Composable financial contracts with Monte Carlo valuation
Project description
Monte Carlo Contracts
Composable financial contracts with Monte Carlo valuation. This module employs ideas from How to Write a Financial Contract by S. L. Peyton Jones and J-M. Eber. However, the implementation is not based on functional programming but rather using an object oriented approach. Also, this implementation is tailored towards Monte Carlo based cashflow generation whereas the paper favours more general methods.
Features
- Composition of financial contracts using elementary contracts
Zero
,One
,Give
,Scale
,And
,When
,Cond
,Anytime
,Until
andDelay
- Boolean and real valued observables (stochastic processes) to be referenced by contracts
- Cashflow generation for composed contracts given simulation models on fixed dategrids
Examples
Install
You can install monte-carlo-contracts
using pip
with
pip3 install monte-carlo-contracts
or you can simply download mcc.py
and then run it using python3
with
python3 mcc.py
History
See HISTORY.md.
Credits
Main developer is luphord luphord@protonmail.com. cookiecutter-pyscript is used as project template.
History
0.10.0 (not yet)
- ToDo: Add new
Exchange(currency, contract)
contract - ToDo: Modify FX options examples to use
Exchange
for cash settlement
0.9.0 (not yet)
- ToDo: Split
mcc.py
into multiple modules forming packagemcc
- ToDo: Split tests into multiple modules
0.8.0 (2023-03-20)
- BREAKING CHANGE:
Contract
now inherits fromResolvableContract
instead of the other way round - BREAKING CHANGE:
And
andOr
contracts now accept more than two contracts to be combined; these have equivalent semantics to nestedAnd
orOr
contracts and allow for flat structures to improve readability - Add
Delay(observableBool, contract)
contract to delay cashflows to a later point in time (main use case is FX payment offset) - First steps towards model requirements (yet incomplete)
- Fix cashflow generation for nested contracts
0.7.0 (2022-03-13)
- BREAKING CHANGE:
ObservableFloat.simulate
andObservableBool.simulate
now accept aDateIndex
first_observation_idx
as first argument,Contract
classes will passacquisition_idx
; this allows observations to depend on the time of entering a contract, e.g. "maximum spot since acquisition" - BREAKING CHANGE:
FixedAfter
fixes composed observable after (including)first_observation_idx
, not from the beginning - Add operator overloading for
Contract
classes, i.e. you can now doOne("USD") - One("EUR") | 1.2 * One("GBP")
instead ofOr(And(One("USD"), Give(One("EUR"))), Scale(1.2, One("GBP")))
Maximum
andMinimum
observables to observe the larger and smaller value of two observables at the same time on the same pathRunningMax
andRunningMin
observables to observe running extreme values fromfirst_observation_idx
onwards- Support Python 3.10
- Make use of type annotations added to numpy
0.6.0 (2022-03-04)
- BREAKING CHANGE: Make
SimpleCashflows
apandas.DataFrame
- Run notebooks in automated tests using nbval
- Migrate from travis-ci to GitHub Actions
- Explicitly support Python 3.8 and 3.9
- Move history to HISTORY.md
0.5.0 (2020-11-08)
- BREAKING CHANGE: Add
simulated_rates
toModel
(included in constructor); pass an empty dict forsimulated_rates
to adapt your code - BREAKING CHANGE:
BrownianMotion
andGeometricBrownianMotion
generalized to dynamic mean/drift; passmu_t = lambda t: mu * t
to adapt your code LinearRate
observable supported byTermStructureModel
- First steps towards term structure models
FixedAfter
observable to keep an observable fixed after a condition is true- Observables support arithmetic operations (binary
+
,-
,*
,/
,**
and unary-
) with other observables as well as constants (also right operators work) - Working with Observables example notebook
0.4.0 (2020-11-04)
- Discounting (
Model.discount
) - Evaluation (
Model.evaluate
) - String representations for contracts and observables
0.3.0 (2020-10-23)
- Simulation of basic contract
Until
- Currency conversion of
IndexedCashflows
Or
contract supports multiple currenciesObservableFloat
supports<
,<=
,>
and>=
operators withfloat
or otherObservableFloat
instancesObservableBool
supports~
,&
and|
operators for combined conditions- Equity Options and FX Options examples
0.2.0 (2020-10-11)
- Simulation of basic contracts
Zero
,One
,Give
,Scale
,And
,When
andCond
- Partial simulation of
Or
contract - Float observables
Stock
andFX
- Boolean observables
At
SimulatedCashflows
and model-boundIndexedCashflows
to represent cashflows- Basic
Model
allowing the generation of cashflows for the contracts above
0.1.0 (2020-09-22)
- Created using cookiecutter-pyscript
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for monte-carlo-contracts-0.8.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a749ed8cfa47930e3d9976f8882c23902060c72bf671efd4a2ba9e7b117e606 |
|
MD5 | 7871e70ad2e073e924c0d1f518bd58f3 |
|
BLAKE2b-256 | 661f873ff96589378aec07b1a66a0ac3a250fa628fb71f82f82a3e5496bb4956 |
Hashes for monte_carlo_contracts-0.8.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4be15f8be860a56563a9a19e57bae4d50bedddd409daacaf5b87f4fecc9b723 |
|
MD5 | 1856b81775d6aaab842e3080dac48f27 |
|
BLAKE2b-256 | 862b82c46bfb459c029a4f8982492833904ccd1e9291196bc22839ad7586d6c0 |