This is a project inspired by following books & codes repositories:
-
Modern Computational Finance: AAD and Parallel Simulations by Antoine Savine
-
Modern Computational Finance: Scripting for Derivatives and xVA by Antoine Savine
Some codes are directly copied from above resources.
just download source codes from github and don't forget to get the submodule
git clone [email protected]:wegamekinglc/Derivatives-Algorithms-Lib.git
cd Derivatives-Algorithms-Lib
git submodule init
git submodule update- git
- cmake
- anaconda python distribution (only for python binding)
- swig (only for python)
- Visual studio 2022 community edition
./build_windows.batafter built, you will get:
- ./lib: the static library and xll excel extension.
- ./bin: all the runnable examples
- git
- cmake
- anaconda python distribution (only for python binding)
- swig (only for python)
- zip
- g++
bash build_linux.shafter built, you will get:
- ./lib: the static library.
- ./bin: all the runnable examples.
both for windows and linux user:
cd public/python
python setup.py wrap
python setup.py installNOTE: This part is only in infancy and should evolve quickly.
We will give a public interface to show the functionality of this project.
we have following data table
| x | y |
|---|---|
| 1 | 10 |
| 3 | 8 |
| 5 | 6 |
| 7 | 4 |
| 9 | 2 |
and we will use follow excel function to create a linear interpolator:
=INTERP1.NEW.LINEAR(E1,A2:A6,B2:B6) # return a object string id, e.g. ~Interp1~my.interp~2F18E558
later we can use the interpolator:
=INTERP1.GET("~Interp1~my.interp~2F18E558", 6.5) # will return 4.5
We will price an european option with our script ability and a basic BS model
The product will be described in excel like :
| Date | Event |
|---|---|
| 2022/9/25 | call pays MAX(spot() - 120, 0.0) |
and we can create a product in excel with the above table:
=PRODUCT.NEW("my_product", A2, B2)
then we set a model to price this:
| Field | Value |
|---|---|
| spot | 100 |
| vol | 0.15 |
| rate | 0.0 |
| dividend | 0.0 |
=BSMODELDATA.NEW("model", D2, D3, D4, D5)
finally we price this product with the model:
=MONTECARLO.VALUE(A5, C7, 2^20, "sobol", FALSE)
| value | 4.0389 |
|---|
The above simple european option pricing example can also be replicated in python:
from dal import *
today = Date_(2022, 9, 15)
EvaluationDate_Set(today)
spot = 100.0
vol = 0.15
rate = 0.0
div = 0.0
strike = 120.0
maturity = Date_(2025, 9, 15)
n_paths = 2 ** 20
use_bb = False
rsg = "sobol"
model_name = "bs"
event_dates = [maturity]
events = [f"call pays MAX(spot() - {strike}, 0.0)"]
product = Product_New(event_dates, events)
model = BSModelData_New(spot, vol, rate, div)
res = MonteCarlo_Value(product, model, n_paths, rsg, False, True)
vega = 0.0
for k, v in res.items():
print(f"{k:<8}: {v:>10.4f}")The output should look like:
d_div : -85.2290
d_rate : 73.1011
d_spot : 0.2838
d_vol : 58.7140
value : 4.0389