Skip to content

Commit a40499b

Browse files
slayoopawelmagnu
andauthored
examples: Magnuszewski 2025 table notebook + pre-arXiv submission changes in figures (+adding pandas as dependency for PyMPDATA-examples) (#563)
Co-authored-by: pawel <[email protected]>
1 parent 1c7b7fe commit a40499b

File tree

8 files changed

+1841
-789
lines changed

8 files changed

+1841
-789
lines changed

docs/bibliography.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,12 @@
193193
],
194194
"label": "Capiński and Zastawniak 2012 (Cambridge University Press)",
195195
"title": "Numerical Methods in Finance with C++"
196+
},
197+
"https://doi.org/10.1111/j.1467-9965.1996.tb00111.x": {
198+
"usages": [
199+
"examples/PyMPDATA_examples/Magnuszewski_et_al_2025/barraquand_data.py"
200+
],
201+
"label": "Barraquand & Pudet 1996 (Math. Financ. 6)",
202+
"title": "Pricing of American path‐dependent contingent claims"
196203
}
197204
}

examples/PyMPDATA_examples/Magnuszewski_et_al_2025/asian_option.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def put(x):
3737

3838

3939
class Simulation:
40-
def __init__(self, settings, *, nx, ny, nt, options, variant="call"):
40+
def __init__(self, settings, *, nx, ny, nt, options, variant="call", eps=1e-10):
4141
self.nx = nx
4242
self.nt = nt
43+
self.eps = eps
4344
self.settings = settings
4445
self.ny = ny
4546
self.dt = settings.T / self.nt
@@ -59,7 +60,7 @@ def __init__(self, settings, *, nx, ny, nt, options, variant="call"):
5960
self.l2 > 2
6061
), f"Lambda squared should be more than 2 for stability {self.l2}"
6162
self.payoff = settings.payoff(A=self.A, da=self.dy, variant=variant)
62-
stepper = Stepper(options=options, n_dims=2)
63+
stepper = Stepper(options=options, n_dims=2, n_threads=1) # TODO #570
6364
x_dim_advector = np.full(
6465
(self.nx + 1, self.ny),
6566
courant_number_x,
@@ -96,8 +97,8 @@ def a_dim_advector(self):
9697
@property
9798
def boundary_conditions(self):
9899
return (
99-
Extrapolated(OUTER),
100-
Extrapolated(INNER),
100+
Extrapolated(OUTER, eps=self.eps),
101+
Extrapolated(INNER, eps=self.eps),
101102
)
102103

103104
def step(self, nt=1):
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# table 6 from [Barraquand and Pudet 1994](https://doi.org/10.1111/j.1467-9965.1996.tb00111.x)
2+
headers = ["sigma", "T", "K", "call_price", "put_price"]
3+
4+
# 0.1,0.25,95,6.132,0.013
5+
# 0.1,0.25,100,1.869,0.626
6+
# 0.1,0.25,105,0.151,3.785
7+
# 0.1,0.5,95,7.248,0.046
8+
# 0.1,0.5,100,3.1,0.655
9+
# 0.1,0.5,105,0.727,3.039
10+
# 0.1,1,95,9.313,0.084
11+
# 0.1,1,100,5.279,0.577
12+
# 0.1,1,105,2.313,2.137
13+
# 0.2,0.25,95,6.5,0.379
14+
# 0.2,0.25,100,2.96,1.716
15+
# 0.2,0.25,105,0.966,4.598
16+
# 0.4,0.25,95,8.151,2.025
17+
# 0.4,0.25,100,5.218,3.970
18+
# 0.4,0.25,105,3.106,6.735
19+
# 0.2,0.5,95,7.793,0.731
20+
# 0.2,1,95,10.336,1.099
21+
# 0.4,1,95,13.825,4.550
22+
# 0.4,0.5,95,10.425,3.215
23+
24+
table = """
25+
0.2,0.5,100,4.548,2.102
26+
0.2,0.5,105,2.241,4.552
27+
0.2,1,100,7.079,2.369
28+
0.2,1,105,4.539,4.356
29+
0.4,0.5,100,7.650,5.197
30+
0.4,0.5,105,5.444,7.748
31+
0.4,1,100,11.213,6.465
32+
0.4,1,105,8.989,8.767
33+
"""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from PyMPDATA import Options
2+
3+
OPTIONS = {
4+
"UPWIND": Options(
5+
n_iters=1,
6+
non_zero_mu_coeff=True,
7+
),
8+
"MPDATA (2 it.)": Options(
9+
n_iters=2,
10+
nonoscillatory=True,
11+
non_zero_mu_coeff=True,
12+
),
13+
"MPDATA (4 it.)": Options(
14+
n_iters=4,
15+
nonoscillatory=True,
16+
non_zero_mu_coeff=True,
17+
),
18+
}

examples/PyMPDATA_examples/Magnuszewski_et_al_2025/figs.ipynb

Lines changed: 1244 additions & 782 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)