-
-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathtest_FinModelCIR.py
More file actions
69 lines (60 loc) · 1.4 KB
/
Copy pathtest_FinModelCIR.py
File metadata and controls
69 lines (60 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright (C) 2018, 2019, 2020 Dominic O'Kane
import numpy as np
from financepy.models.cir_montecarlo import CIRNumericalScheme
from financepy.models.cir_montecarlo import zero_price_mc, zero_price
r0 = 0.05
a = 0.20
b = 0.05
sigma = 0.20
t = 5.0
num_paths = 2000
dt = 0.05
seed = 1968
########################################################################################
def test_model_cir():
p = zero_price(r0, a, b, sigma, t)
p_mc1 = zero_price_mc(
r0, a, b, sigma, t, dt, num_paths, seed, CIRNumericalScheme.EULER.value
)
p_mc2 = zero_price_mc(
r0,
a,
b,
sigma,
t,
dt,
num_paths,
seed,
CIRNumericalScheme.LOGNORMAL.value,
)
p_mc3 = zero_price_mc(
r0,
a,
b,
sigma,
t,
dt,
num_paths,
seed,
CIRNumericalScheme.MILSTEIN.value,
)
p_mc4 = zero_price_mc(
r0,
a,
b,
sigma,
t,
dt,
num_paths,
seed,
CIRNumericalScheme.KAHLJACKEL.value,
)
p_mc5 = zero_price_mc(
r0, a, b, sigma, t, dt, num_paths, seed, CIRNumericalScheme.EXACT.value
)
assert round(p, 4) == 0.7935
assert round(p_mc1, 4) == 0.7868
assert round(p_mc2, 4) == 0.7870
assert round(p_mc3, 4) == 0.7868
assert round(p_mc4, 4) == 0.7863
assert round(p_mc5, 4) == 0.7932