Exploring Quantlib: Testing Examples for Financial Modeling
QuantLib 1.31.1 / Boost 1.83.0
BasketLosses
1 September 25th, 2023
2 QuantLib version: 1.31.1
3 BasketLosses!
4
5 GLHP Expected 10-Yr Losses:
6 29.6265
7 Gaussian Binomial Expected 10-Yr Losses:
8 25.8297
9 T Binomial Expected 10-Yr Losses:
10 25.6508
11 G Inhomogeneous Expected 10-Yr Losses:
12 26.111
13 Random G Expected 10-Yr Losses:
14 26.1135
15 Random T Expected 10-Yr Losses:
16 28.2459
17 Random Loss G Expected 10-Yr Losses:
18 24.058
19 Random Loss T Expected 10-Yr Losses:
20 23.6476
21 Base Correlation GLHP Expected 10-Yr Losses:
22 29.6265
23
24 QuantLib version: 1.31.1
25 Using Boost 1.83.0
26 Exit quantLib test
Bermudan Swaption ---- HOUSTON, we have a problem!
Bonds
1 September 25th, 2023
2 QuantLib version: 1.31.1
3
4 CallableBonds.cpp
5
6 Pricing a callable fixed rate bond using
7 Hull White model w/ reversion parameter = 0.03
8 BAC4.65 09/15/12 ISIN: US06060WBJ36
9 roughly five year tenor, quarterly coupon and call dates
10 reference date is : October 16th, 2007
11
12 sigma/vol (%) = 0.00
13 QuantLib price/yld (%) 96.51 / 5.47
14 Bloomberg price/yld (%) 96.50 / 5.47
15
16 sigma/vol (%) = 1.00
17 QuantLib price/yld (%) Bloomberg price/yld (%) 95.68 / 5.66
18
19 sigma/vol (%) = 3.00
20 QuantLib price/yld (%) 92.35 / 6.48
21 Bloomberg price/yld (%) 92.34 / 6.49
22
23 sigma/vol (%) = 6.00
24 QuantLib price/yld (%) 87.12 / 7.84
25 Bloomberg price/yld (%) 87.16 / 7.83
26
27 sigma/vol (%) = 12.00
28 QuantLib price/yld (%) 77.37 / 10.63
29 Bloomberg price/yld (%) 77.31 / 10.65
30
31
32 QuantLib version: 1.31.1
33 Using Boost 1.83.0
34 Exit quantLib test
CDS
1
2 |ExSan| C++ |ExSan|EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Nov 8
3 Thu Nov 9 09:46:33 2023
4
5
6 exsan.plusplus@gmail.com https://twitter.com/#!/ExSan_com
7 Begin Time: 2023-Nov-09 09:46:33.234000
8 JOB: qlCDS_4633
9
10 CDS
11 ***** Running example #1 *****
12
13 Calibrated hazard rate values:
14 hazard rate on May 15th, 2007 is 0.0299685
15 hazard rate on September 20th, 2007 is 0.0299685
16 hazard rate on December 20th, 2007 is 0.0299613
17 hazard rate on June 20th, 2008 is 0.0299619
18 hazard rate on June 22nd, 2009 is 0.0299607
19
20 Some survival probability values:
21 1Y survival probability: 97.040077 %
22 expected: 97.040000 %
23 2Y survival probability: 94.175796 %
24 expected: 94.180000 %
25
26
27 Repricing of quoted CDSs employed for calibration:
28 3M fair spread: 1.500000 %
29 NPV: 1.36424e-11
30 default leg: -5177.05
31 coupon leg: 5177.05
32
33 6M fair spread: 1.500000 %
34 NPV: 2.72848e-11
35 default leg: -8841.72
36 coupon leg: 8841.72
37
38 1Y fair spread: 1.500000 %
39 NPV: -2.00271e-09
40 default leg: -16101.8
41 coupon leg: 16101.8
42
43 2Y fair spread: 1.500000 %
44 NPV: -5.27507e-10
45 default leg: -30154.5
46 coupon leg: 30154.5
47
48
49
50 ***** Running example #2 *****
51 September 22nd, 2014
52 December 22nd, 2014
53 March 20th, 2015
54 June 22nd, 2015
55 September 21st, 2015
56 December 21st, 2015
57 March 21st, 2016
58 June 20th, 2016
59 September 20th, 2016
60 December 20th, 2016
61 ISDA rate curve:
62 November 24th, 2014 6.08332e-05 0.999994
63 December 23rd, 2014 0.00044368 0.999923
64 January 23rd, 2015 0.000804988 0.999793
65 April 23rd, 2015 0.00184508 0.99907
66 July 23rd, 2015 0.00257462 0.998062
67 October 23rd, 2015 0.00339272 0.996594
68 October 24th, 2016 0.00221731 0.995551
69 October 23rd, 2017 0.00274915 0.991764
70 October 23rd, 2018 0.00352107 0.985986
71 October 23rd, 2019 0.00451599 0.977637
72 October 23rd, 2020 0.0057249 0.966173
73 October 25th, 2021 0.00707627 0.951562
74 October 24th, 2022 0.00847959 0.934305
75 October 23rd, 2023 0.009823 0.91529
76 October 23rd, 2024 0.0110503 0.895248
77 October 23rd, 2026 0.0131302 0.85407
78 October 23rd, 2029 0.0153845 0.793724
79 October 23rd, 2034 0.0176039 0.702988
80 October 24th, 2044 0.0188487 0.567776
81 first period = September 22nd, 2014 to December 22nd, 2014 accrued amount = 88888.9
82 reference trade NPV = -40991.9
83 ISDA credit curve:
84 June 21st, 2019;0.0516552;0.948345;0.0113607
85 ***** Running example #3 *****
86 ISDA yield curve:
87 date;time;zeroyield
88 July 15th, 2011;0.0876712;0.00451097
89 August 15th, 2011;0.172603;0.00945207
90 September 15th, 2011;0.257534;0.0123219
91 December 15th, 2011;0.506849;0.0177808
92 March 15th, 2012;0.756164;0.0193672
93 June 15th, 2012;1.00822;0.0208196
94 June 17th, 2013;2.0137;0.0162932
95 June 16th, 2014;3.01096;0.0199753
96 June 15th, 2015;4.00822;0.0228632
97 June 15th, 2016;5.01096;0.0251187
98 June 15th, 2017;6.01096;0.0268835
99 June 15th, 2018;7.01096;0.0282243
100 June 17th, 2019;8.01644;0.0293359
101 June 15th, 2020;9.0137;0.0302361
102 June 15th, 2021;10.0137;0.0310384
103 June 15th, 2022;11.0137;0.0317757
104 June 15th, 2023;12.0137;0.032565
105 June 15th, 2026;15.0164;0.0340699
106 June 16th, 2031;20.0219;0.0345057
107 June 16th, 2036;25.0274;0.0342061
108 June 17th, 2041;30.0329;0.0341081
109 ISDA credit curve:
110 date;time;survivalprob
111 December 21st, 2011;0.523288;0.993032
112 June 21st, 2012;1.02466;0.986405
113 June 21st, 2014;3.02466;0.939078
114 June 21st, 2016;5.0274;0.862452
115 June 21st, 2018;7.0274;0.788519
116 June 22nd, 2021;10.0329;0.690297
117
118 End Time: 2023-Nov-09 09:46:33.724000
119 Elapsed Time(seconds): 490 miliseconds
120 QuantLib version: 1.31.1
121
122 ENDS qlCDS_4633 Elapsed Time: 0.492 sec
123 Boost version: 1.83.0 EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Nov 8
124 EXIT FROM EXSAN
+
+
C
E
x
S
a
n
C
+
+
D
o
N
o
t
A
c
c
e
p
t
D
e
f
a
u
l
t
s
T
h
i
n
k
D
i
f
f
e
r
e
n
t
ConvertibleBonds
1
2 |ExSan| C++ |ExSan|EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Nov 8
3 Thu Nov 9 09:02:46 2023
4
5
6 exsan.plusplus@gmail.com https://twitter.com/#!/ExSan_com
7 Begin Time: 2023-Nov-09 09:02:46.647000
8 JOB: qlConBnds_0246
9
10 Convertible Bonds
11
12 option type = Put
13 Time to maturity = 5.00548
14 Underlying price = 36
15 Risk-free interest rate = 6.000000 %
16 Dividend yield = 2.000000 %
17 Volatility = 20.000000 %
18
19
20 ===============================================================
21 Tsiveriotis-Fernandes method
22 ===============================================================
23 Tree type European American
24 ---------------------------------------------------------------
25 Jarrow-Rudd 105.705221 108.162511
26 Cox-Ross-Rubinstein 105.711075 108.185719
27 Additive equiprobabilities 105.641777 108.105906
28 Trigeorgis 105.711569 108.186165
29 Tian 105.728045 108.179950
30 Leisen-Reimer 105.679115 108.158839
31 Joshi 105.679116 108.158840
32 ===============================================================
33
34 End Time: 2023-Nov-09 09:02:50.869000
35 Elapsed Time(seconds): 4
36 QuantLib version: 1.31.1
37
38 ENDS qlConBnds_0246 Elapsed Time: 4.223000 sec
39 Boost version: 1.83.0 EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Nov 8
40 EXIT FROM EXSAN
+
+
C
E
x
S
a
n
C
+
+
D
o
N
o
t
A
c
c
e
p
t
D
e
f
a
u
l
t
s
T
h
i
n
k
D
i
f
f
e
r
e
n
t
CVAIRS
1
2 Begin Time: 2023-Oct-31 07:16:43.180000
3 |ExSan| C++ |ExSan|EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Oct 27
4 Tue Oct 31 07:16:43 2023
5
6
7 exsan.plusplus@gmail.com https://twitter.com/#!/ExSan_com
8 Begin Time: 2023-Oct-31 07:16:43.182000
9 JOB: CVAIRS_1643
10
11 CVAIRS
12 -- Correction in the contract fix rate in bp --
13 5 | 3.249 % | -0.24 | -0.87 | -2.10
14 10 | 4.074 % | -2.15 | -5.62 | -11.65
15 15 | 4.463 % | -4.60 | -10.41 | -19.60
16 20 | 4.675 % | -6.94 | -14.57 | -25.67
17 25 | 4.775 % | -8.79 | -17.63 | -29.62
18 30 | 4.811 % | -10.16 | -19.73 | -32.00
19
20
21 End Time: 2023-Oct-31 07:16:58.818000
22 Elapsed Time(seconds): 15
23 QuantLib version: 1.31.1
26 Boost version: 1.83.0 EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Oct 27
27 EXIT FROM EXSAN
+
+
C
E
x
S
a
n
C
+
+
D
o
N
o
t
A
c
c
e
p
t
D
e
f
a
u
l
t
s
T
h
i
n
k
D
i
f
f
e
r
e
n
t
DiscreteHedging
1
2 *Begin Time: 2023-Oct-27 09:43:40.697000
3 DiscreteHedging
4
5 Option value: 2.51207
6
7 | | P&L | P&L | Derman&Kamal | P&L | P&L
8 samples | trades | mean | std.dev. | formula | skewness | kurtosis
9 ------------------------------------------------------------------------------
10 50000 | 21 | 0.006 | 0.43 | 0.44 | -0.30 | 1.48
11 50000 | 84 | -0.001 | 0.22 | 0.22 | -0.22 | 1.65
12
13 *Begin Time: 2023-Oct-27 09:43:40.697000
14 End Time: 2023-Oct-27 09:44:05.974000
15 Elapsed Time: 25 seconds and 25277 mili seconds 25.25277
16 Elapsed Time(seconds): 50
17 QuantLib version: 1.31.1
18 Boost version: 1.83.0EXSAN_64 MSVSC2022_V17_7.6@-toolSet(v143) Oct 27
+
+
C
E
x
S
a
n
C
+
+
D
o
N
o
t
A
c
c
e
p
t
D
e
f
a
u
l
t
s
T
h
i
n
k
D
i
f
f
e
r
e
n
t
EquityOption
1
2 z_QuantLib.cpp/testQuantLib(void) * QuantLib version: 10.40 1.31.1
3 *Begin Time: 2023-Oct-21 08:30:38.633000
4 Equity Option
5
6 Option type = Put
7 Maturity = May 17th, 1999
8 Underlying price = 36
9 Strike = 40
10 Risk-free interest rate = 6.000000 %
11 Dividend yield = 0.000000 %
12 Volatility = 20.000000 %
13
14
15 Method European Bermudan American
16 Black-Scholes 3.844308 N/A N/A
17 Black Vasicek Model 3.818577 N/A N/A
18 Heston semi-analytic 3.844306 N/A N/A
19 Bates semi-analytic 3.844306 N/A N/A
20 Barone-Adesi/Whaley N/A N/A 4.459628
21 Bjerksund/Stensland N/A N/A 4.453064
22 QD+ fixed-point (fast) N/A N/A 4.486617
23 QD+ fixed-point (accurate) N/A N/A 4.486669
24 QD+ fixed-point (high precision) N/A N/A 4.486674
25 Integral 3.844309 N/A N/A
26 Finite differences 3.844330 4.360765 4.486113
27 Binomial Jarrow-Rudd 3.844132 4.361174 4.486552
28 Binomial Cox-Ross-Rubinstein 3.843504 4.360861 4.486415
29 Additive equiprobabilities 3.836911 4.354455 4.480097
30 Binomial Trigeorgis 3.843557 4.360909 4.486461
31 Binomial Tian 3.844171 4.361176 4.486413
32 Binomial Leisen-Reimer 3.844308 4.360713 4.486076
33 Binomial Joshi 3.844308 4.360713 4.486076
34 MC (crude) 3.834522 N/A N/A
35 QMC (Sobol) 3.844613 N/A N/A
36 MC (Longstaff Schwartz) N/A N/A 4.456935
37
38 *Begin Time: 2023-Oct-21 08:30:38.633000
39 End Time: 2023-Oct-21 08:31:00.258000
40 Elapsed Time: 21 seconds and 21625 mili seconds 21.21625
41 Elapsed Time(seconds): 42
42 QuantLib version: 1.31.1
43 Boost version: 1.83.0
44 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.5 -
FittedBondCurve
1
2 z_QuantLib.cpp/testQuantLib(void) * QuantLib version: 10.40 1.31.1
3 *Begin Time: 2023-Oct-21 08:19:44.021000
4 Fitted Bond Curve
5
6 Today's date: October 23rd, 2023
7 Bonds' settlement date: October 23rd, 2023
8 Calculating fit for 15 bonds.....
9
10 (a) exponential splines
11 reference date : October 23rd, 2023
12 number of iterations : 6237
13
14 (b) simple polynomial
15 reference date : October 23rd, 2023
16 number of iterations : 280
17
18 (c) Nelson-Siegel
19 reference date : October 23rd, 2023
20 number of iterations : 1235
21
22 (d) cubic B-splines
23 reference date : October 23rd, 2023
24 number of iterations : 696
25
26 (e) Svensson
27 reference date : October 23rd, 2023
28 number of iterations : 3952
29
30 (f) Nelson-Siegel spread
31 reference date : October 23rd, 2023
32 number of iterations : 1622
33
34 (g) exponential splines, fixed kappa
35 reference date : October 23rd, 2023
36 number of iterations : 1740
37
38 Output par rates for each curve. In this case,
39 par rates should equal coupons for these par bonds.
40
41 tenor | coupon | bstrap | (a) | (b) | (c) | (d) | (e) | (f) | (g)
42 2.000 | 2.000 | 2.000 | 2.000 | 2.010 | 2.060 | 1.770 | 2.008 | 2.060 | 2.000
43 4.006 | 2.250 | 2.250 | 2.250 | 2.257 | 2.266 | 2.398 | 2.225 | 2.266 | 2.251
44 6.000 | 2.500 | 2.500 | 2.499 | 2.501 | 2.484 | 2.657 | 2.511 | 2.484 | 2.500
45 8.000 | 2.750 | 2.750 | 2.750 | 2.746 | 2.716 | 2.748 | 2.771 | 2.716 | 2.750
46 10.003 | 3.000 | 3.000 | 3.000 | 2.993 | 2.960 | 2.905 | 3.013 | 2.960 | 3.000
47 12.000 | 3.250 | 3.250 | 3.250 | 3.241 | 3.214 | 3.195 | 3.248 | 3.214 | 3.250
48 14.000 | 3.500 | 3.500 | 3.500 | 3.490 | 3.477 | 3.521 | 3.486 | 3.477 | 3.500
49 16.003 | 3.750 | 3.750 | 3.750 | 3.743 | 3.746 | 3.796 | 3.731 | 3.746 | 3.750
50 18.000 | 4.000 | 4.000 | 4.000 | 3.996 | 4.017 | 4.016 | 3.984 | 4.017 | 4.000
51 20.000 | 4.250 | 4.250 | 4.250 | 4.251 | 4.286 | 4.232 | 4.245 | 4.286 | 4.250
52 22.000 | 4.500 | 4.500 | 4.500 | 4.507 | 4.548 | 4.478 | 4.510 | 4.548 | 4.500
53 24.000 | 4.750 | 4.750 | 4.750 | 4.761 | 4.797 | 4.745 | 4.772 | 4.797 | 4.750
54 26.006 | 5.000 | 5.000 | 5.001 | 5.012 | 5.029 | 5.015 | 5.025 | 5.029 | 5.000
55 28.000 | 5.250 | 5.250 | 5.250 | 5.254 | 5.236 | 5.267 | 5.258 | 5.236 | 5.250
56 30.000 | 5.500 | 5.500 | 5.500 | 5.485 | 5.416 | 5.485 | 5.464 | 5.416 | 5.500
57
58
59
60 Now add 23 months to today. Par rates should be
61 automatically recalculated because today's date
62 changes. Par rates will NOT equal coupons (YTM
63 will, with the correct compounding), but the
64 piecewise yield curve par rates can be used as
65 a benchmark for correct par rates.
66
67 (a) exponential splines
68 reference date : September 23rd, 2025
69 number of iterations : 1189
70
71 (b) simple polynomial
72 reference date : September 23rd, 2025
73 number of iterations : 264
74
75 (c) Nelson-Siegel
76 reference date : September 23rd, 2025
77 number of iterations : 1003
78
79 (d) cubic B-splines
80 reference date : September 23rd, 2025
81 number of iterations : 685
82
83 (e) Svensson
84 reference date : September 23rd, 2025
85 number of iterations : 2664
86
87 (f) Nelson-Siegel spread
88 reference date : September 23rd, 2025
89 number of iterations : 1010
90
91 (g) exponential spline, fixed kappa
92 reference date : September 23rd, 2025
93 number of iterations : 962
94
95
96
97 tenor | coupon | bstrap | (a) | (b) | (c) | (d) | (e) | (f) | (g)
98 0.083 | 2.000 | 1.964 | 1.969 | 1.983 | 2.025 | 1.310 | 1.964 | 2.025 | 1.966
99 2.089 | 2.250 | 2.248 | 2.242 | 2.249 | 2.256 | 2.335 | 2.235 | 2.256 | 2.244
100 4.083 | 2.500 | 2.499 | 2.496 | 2.496 | 2.481 | 2.908 | 2.529 | 2.481 | 2.498
101 6.083 | 2.750 | 2.749 | 2.749 | 2.743 | 2.716 | 3.013 | 2.765 | 2.716 | 2.750
102 8.086 | 3.000 | 2.999 | 3.001 | 2.991 | 2.963 | 2.949 | 2.996 | 2.963 | 3.001
103 10.083 | 3.250 | 3.249 | 3.251 | 3.239 | 3.217 | 3.053 | 3.232 | 3.217 | 3.250
104 12.083 | 3.500 | 3.499 | 3.501 | 3.490 | 3.479 | 3.403 | 3.477 | 3.479 | 3.500
105 14.086 | 3.750 | 3.749 | 3.751 | 3.743 | 3.746 | 3.804 | 3.731 | 3.746 | 3.750
106 16.083 | 4.000 | 4.000 | 4.000 | 3.997 | 4.014 | 4.089 | 3.990 | 4.014 | 3.999
107 18.083 | 4.250 | 4.250 | 4.249 | 4.252 | 4.280 | 4.268 | 4.254 | 4.280 | 4.249
108 20.083 | 4.500 | 4.500 | 4.498 | 4.507 | 4.541 | 4.454 | 4.517 | 4.541 | 4.499
109 22.083 | 4.750 | 4.750 | 4.748 | 4.761 | 4.790 | 4.718 | 4.776 | 4.790 | 4.749
110 24.089 | 5.000 | 4.999 | 4.999 | 5.012 | 5.025 | 5.014 | 5.024 | 5.025 | 4.999
111 26.083 | 5.250 | 5.249 | 5.249 | 5.254 | 5.239 | 5.277 | 5.253 | 5.239 | 5.249
112 28.083 | 5.500 | 5.499 | 5.500 | 5.484 | 5.430 | 5.485 | 5.460 | 5.430 | 5.500
113
114
115
116 Now add one more month, for a total of two years
117 from the original date. The first instrument is
118 now expired and par rates should again equal
119 coupon values, since clean prices did not change.
120
121 (a) exponential splines
122 reference date : October 23rd, 2025
123 number of iterations : 6999
124
125 (b) simple polynomial
126 reference date : October 23rd, 2025
127 number of iterations : 269
128
129 (c) Nelson-Siegel
130 reference date : October 23rd, 2025
131 number of iterations : 1057
132
133 (d) cubic B-splines
134 reference date : October 23rd, 2025
135 number of iterations : 717
136
137 (e) Svensson
138 reference date : October 23rd, 2025
139 number of iterations : 3035
140
141 (f) Nelson-Siegel spread
142 reference date : October 23rd, 2025
143 number of iterations : 1655
144
145 (g) exponential, fixed kappa
146 reference date : October 23rd, 2025
147 number of iterations : 1605
148
149 tenor | coupon | bstrap | (a) | (b) | (c) | (d) | (e) | (f) | (g)
150 2.006 | 2.250 | 2.250 | 2.246 | 2.260 | 2.294 | 2.014 | 2.253 | 2.294 | 2.250
151 4.000 | 2.500 | 2.500 | 2.501 | 2.504 | 2.508 | 2.659 | 2.487 | 2.508 | 2.500
152 6.000 | 2.750 | 2.750 | 2.753 | 2.749 | 2.734 | 2.918 | 2.761 | 2.734 | 2.750
153 8.003 | 3.000 | 3.000 | 3.003 | 2.995 | 2.972 | 2.998 | 3.012 | 2.972 | 3.000
154 10.000 | 3.250 | 3.250 | 3.251 | 3.242 | 3.219 | 3.148 | 3.250 | 3.219 | 3.250
155 12.000 | 3.500 | 3.500 | 3.499 | 3.491 | 3.476 | 3.442 | 3.490 | 3.476 | 3.500
156 14.003 | 3.750 | 3.750 | 3.748 | 3.743 | 3.739 | 3.775 | 3.736 | 3.739 | 3.750
157 16.000 | 4.000 | 4.000 | 3.997 | 3.996 | 4.005 | 4.048 | 3.989 | 4.005 | 4.000
158 18.000 | 4.250 | 4.250 | 4.248 | 4.250 | 4.271 | 4.262 | 4.248 | 4.271 | 4.250
159 20.000 | 4.500 | 4.500 | 4.499 | 4.505 | 4.533 | 4.476 | 4.510 | 4.533 | 4.500
160 22.000 | 4.750 | 4.750 | 4.751 | 4.759 | 4.786 | 4.732 | 4.770 | 4.786 | 4.750
161 24.006 | 5.000 | 5.000 | 5.003 | 5.011 | 5.025 | 5.006 | 5.021 | 5.025 | 5.000
162 26.000 | 5.250 | 5.250 | 5.252 | 5.254 | 5.244 | 5.265 | 5.255 | 5.244 | 5.250
163 28.000 | 5.500 | 5.500 | 5.497 | 5.487 | 5.440 | 5.492 | 5.466 | 5.440 | 5.500
164
165
166
167 Now decrease prices by a small amount, corresponding
168 to a theoretical five basis point parallel + shift of
169 the yield curve. Because bond quotes change, the new
170 par rates should be recalculated automatically.
171
172 tenor | coupon | bstrap | (a) | (b) | (c) | (d) | (e) | (f) | (g)
173 2.006 | 2.250 | 2.299 | 2.297 | 2.311 | 2.344 | 2.061 | 2.303 | 2.344 | 2.299
174 4.000 | 2.500 | 2.550 | 2.551 | 2.554 | 2.557 | 2.709 | 2.533 | 2.557 | 2.549
175 6.000 | 2.750 | 2.800 | 2.802 | 2.798 | 2.783 | 2.969 | 2.809 | 2.783 | 2.799
176 8.003 | 3.000 | 3.048 | 3.051 | 3.044 | 3.021 | 3.047 | 3.064 | 3.021 | 3.049
177 10.000 | 3.250 | 3.299 | 3.299 | 3.290 | 3.268 | 3.196 | 3.304 | 3.268 | 3.299
178 12.000 | 3.500 | 3.549 | 3.547 | 3.539 | 3.524 | 3.490 | 3.543 | 3.524 | 3.548
179 14.003 | 3.750 | 3.797 | 3.796 | 3.790 | 3.787 | 3.823 | 3.786 | 3.787 | 3.798
180 16.000 | 4.000 | 4.048 | 4.045 | 4.043 | 4.053 | 4.096 | 4.035 | 4.053 | 4.047
181 18.000 | 4.250 | 4.298 | 4.295 | 4.297 | 4.319 | 4.309 | 4.290 | 4.319 | 4.297
182 20.000 | 4.500 | 4.547 | 4.546 | 4.552 | 4.580 | 4.523 | 4.550 | 4.580 | 4.546
183 22.000 | 4.750 | 4.797 | 4.798 | 4.806 | 4.832 | 4.777 | 4.809 | 4.832 | 4.796
184 24.006 | 5.000 | 5.044 | 5.049 | 5.057 | 5.071 | 5.051 | 5.063 | 5.071 | 5.046
185 26.000 | 5.250 | 5.296 | 5.297 | 5.299 | 5.289 | 5.310 | 5.303 | 5.289 | 5.295
186 28.000 | 5.500 | 5.545 | 5.541 | 5.531 | 5.485 | 5.537 | 5.521 | 5.485 | 5.545
187
188 *Begin Time: 2023-Oct-21 08:19:44.021000
189 End Time: 2023-Oct-21 08:20:51.006000
190 Elapsed Time: 66 seconds and 66985 mili seconds 66.66985
191 Elapsed Time(seconds): 132
192 QuantLib version: 1.31.1
193 Boost version: 1.83.0
194 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
FRA
1
2 z_QuantLib.cpp/testQuantLib(void) * QuantLib version: 10.40 1.31.1
3 *Begin Time: 2023-Oct-07 08:01:08.708000
4 FRA
5
6 Today: Tuesday, May 23rd, 2006
7 Settlement date: Thursday, May 25th, 2006
8
9 Test FRA construction, NPV calculation, and FRA purchase
10
11 3m Term FRA, Months to Start: 1
12 strike FRA rate: 3.000000 %
13 FRA 3m forward rate: 3.000000 % Actual/360 simple compounding
14 FRA market quote: 3.000000 %
15 FRA amount [should be zero]: -1.2776e-13
16 FRA NPV [should be zero]: -1.27421e-13
17
18 3m Term FRA, Months to Start: 2
19 strike FRA rate: 3.100000 %
20 FRA 3m forward rate: 3.100000 % Actual/360 simple compounding
21 FRA market quote: 3.100000 %
22 FRA amount [should be zero]: -6.66612e-13
23 FRA NPV [should be zero]: -6.63245e-13
24
25 3m Term FRA, Months to Start: 3
26 strike FRA rate: 3.200000 %
27 FRA 3m forward rate: 3.200000 % Actual/360 simple compounding
28 FRA market quote: 3.200000 %
29 FRA amount [should be zero]: -5.39043e-13
30 FRA NPV [should be zero]: -5.34941e-13
31
32 3m Term FRA, Months to Start: 6
33 strike FRA rate: 3.300000 %
34 FRA 3m forward rate: 3.300000 % Actual/360 simple compounding
35 FRA market quote: 3.300000 %
36 FRA amount [should be zero]: 1.79361e-14
37 FRA NPV [should be zero]: 1.76522e-14
38
39 3m Term FRA, Months to Start: 9
40 strike FRA rate: 3.400000 %
41 FRA 3m forward rate: 3.400000 % Actual/360 simple compounding
42 FRA market quote: 3.400000 %
43 FRA amount [should be zero]: 1.25212e-14
44 FRA NPV [should be zero]: 1.2221e-14
45
46
47
48 Now take a 100 basis-point upward shift in FRA quotes and examine NPV
49
50 3m Term FRA, 100 notional, Months to Start = 1
51 strike FRA rate: 3.000000 %
52 FRA 3m forward rate: 4.000000 % Actual/360 simple compounding
53 FRA market quote: 4.000000 %
54 FRA amount [should be positive]: 0.25297
55 FRA NPV [should be positive]: 0.252076
56
57 3m Term FRA, 100 notional, Months to Start = 2
58 strike FRA rate: 3.100000 %
59 FRA 3m forward rate: 4.100000 % Actual/360 simple compounding
60 FRA market quote: 4.100000 %
61 FRA amount [should be positive]: 0.252906
62 FRA NPV [should be positive]: 0.251206
63
64 3m Term FRA, 100 notional, Months to Start = 3
65 strike FRA rate: 3.200000 %
66 FRA 3m forward rate: 4.200000 % Actual/360 simple compounding
67 FRA market quote: 4.200000 %
68 FRA amount [should be positive]: 0.258279
69 FRA NPV [should be positive]: 0.255665
70
71 3m Term FRA, 100 notional, Months to Start = 6
72 strike FRA rate: 3.300000 %
73 FRA 3m forward rate: 4.300000 % Actual/360 simple compounding
74 FRA market quote: 4.300000 %
75 FRA amount [should be positive]: 0.252778
76 FRA NPV [should be positive]: 0.247506
77
78 3m Term FRA, 100 notional, Months to Start = 9
79 strike FRA rate: 3.400000 %
80 FRA 3m forward rate: 4.400000 % Actual/360 simple compounding
81 FRA market quote: 4.400000 %
82 FRA amount [should be positive]: 0.249997
83 FRA NPV [should be positive]: 0.242151
84
85
86 *Begin Time: 2023-Oct-07 08:01:08.708000
87 Begin Time: 2023-Oct-07 08:01:08.708000
88 End Time: 2023-Oct-07 08:01:08.722000
89 Elapsed Time: 0 seconds and 14 mili seconds 0.14
90 Elapsed Time(seconds): 0
91 QuantLib version: 1.31.1
92 Exit quantLib test ---- martes 10.20
93 Boost version: 1.83.0
94 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
Gaussian1dModels
34 using namespace QuantLib;
35 // helper function that prints a basket of calibrating swaptions to cout
36
37 void printBasket(
38 const std::vector >& basket) {
39 cout << "\n" << std::left << std::setw(20) << "Expiry" << std::setw(20)
40 << "Maturity" << std::setw(20) << "Nominal" << std::setw(14)
41 << "Rate" << std::setw(12) << "Pay/Rec" << std::setw(14)
42 << "Market ivol" << std::fixed << std::setprecision(6)
43 << std::endl;
44 cout << "===================="
45 "===================="
46 "===================="
47 "===================="
48 "==================" << std::endl;
49 for (const auto& j : basket) {
50 ext::shared_ptr helper = ext::dynamic_pointer_cast(j);
51 Date endDate = helper->underlyingSwap()->fixedSchedule().dates().back();
52 Real nominal = helper->underlyingSwap()->nominal();
53 Real vol = helper->volatility()->value();
54 Real rate = helper->underlyingSwap()->fixedRate();
55 Date expiry = helper->swaption()->exercise()->date(0);
56 Swap::Type type = helper->swaption()->type();
57 std::ostringstream expiryString, endDateString;
58 expiryString << expiry;
59 endDateString << endDate;
60 cout << std::setw(20) << expiryString.str() << std::setw(20)
61 << endDateString.str() << std::setw(20) << nominal
62 << std::setw(14) << rate << std::setw(12)
63 << (type == Swap::Payer ? "Payer" : "Receiver")
64 << std::setw(14) << vol << std::endl;
65 }
66 }
67
68 // helper function that prints the result of a model calibration to cout
69
70 void printModelCalibration(
71 const std::vector >& basket,
72 const Array& volatility) {
73
74 cout << "\n" << std::left << std::setw(20) << "Expiry" << std::setw(14)
75 << "Model sigma" << std::setw(20) << "Model price"
76 << std::setw(20) << "market price" << std::setw(14)
77 << "Model ivol" << std::setw(14) << "Market ivol" << std::fixed
78 << std::setprecision(6) << std::endl;
79 cout << "===================="
80 "===================="
81 "===================="
82 "===================="
83 "====================" << std::endl;
84
85 for (Size j = 0; j < basket.size(); ++j) {
86 ext::shared_ptr helper =
87 ext::dynamic_pointer_cast(basket[j]);
88 Date expiry = helper->swaption()->exercise()->date(0);
89 std::ostringstream expiryString;
90 expiryString << expiry;
91 cout << std::setw(20) << expiryString.str() << std::setw(14)
92 << volatility[j] << std::setw(20) << basket[j]->modelValue()
93 << std::setw(20) << basket[j]->marketValue() << std::setw(14)
94 << basket[j]->impliedVolatility(basket[j]->modelValue(), 1E-6,
95 1000, 0.0, 2.0)
96 << std::setw(14) << basket[j]->volatility()->value()
97 << std::endl;
98 }
99 if (volatility.size() > basket.size()) // only for markov model
100 cout << std::setw(20) << " " << volatility.back() << std::endl;
101 }
102
103 // here the main part of the code starts
104 //
105 int QuantlibGaussian1dModels() {
106 cout << "\n\tQuantlibGaussian1dModels\n";
107
108 try {
109 cout << "\nGaussian1dModel Examples" << std::endl;
110 cout << "\nThis is some example code showing how to use the GSR "
111 "\n(Gaussian short rate) and Markov Functional model." << std::endl;
112
113 Date refDate(30, April, 2014);
114 Settings::instance().evaluationDate() = refDate;
115
116 cout << "\nThe evaluation date for this example is set to "
117 << Settings::instance().evaluationDate() << std::endl;
118
119 Real forward6mLevel = 0.025;
120 Real oisLevel = 0.02;
121
122 Handle forward6mQuote(
123 ext::make_shared(forward6mLevel));
124 Handle oisQuote(ext::make_shared(oisLevel));
125
126 Handle yts6m(ext::make_shared(
127 0, TARGET(), forward6mQuote, Actual365Fixed()));
128 Handle ytsOis(ext::make_shared(
129 0, TARGET(), oisQuote, Actual365Fixed()));
130
131 ext::shared_ptr euribor6m =
132 ext::make_shared(6 * Months, yts6m);
133
134 cout << "\nWe assume a multicurve setup, for simplicity with flat yield "
135 "\nterm structures. The discounting curve is an Eonia curve at"
136 "\na level of " << oisLevel
137 << " and the forwarding curve is an Euribior 6m curve"
138 << "\nat a level of " << forward6mLevel << std::endl;
139
140 Real volLevel = 0.20;
141 Handle volQuote(ext::make_shared(volLevel));
142 Handle swaptionVol(
143 ext::make_shared(
144 0, TARGET(), ModifiedFollowing, volQuote, Actual365Fixed()));
145
146 cout << "\nFor the volatility we assume a flat swaption volatility at "
147 << volLevel << std::endl;
148
149 Real strike = 0.04;
150 cout << "\nWe consider a standard 10y bermudan payer swaption "
151 "\nwith yearly exercises at a strike of " << strike
152 << std::endl;
153
154 Date effectiveDate = TARGET().advance(refDate, 2 * Days);
155 Date maturityDate = TARGET().advance(effectiveDate, 10 * Years);
156
157 Schedule fixedSchedule(effectiveDate, maturityDate, 1 * Years, TARGET(),
158 ModifiedFollowing, ModifiedFollowing,
159 DateGeneration::Forward, false);
160 Schedule floatingSchedule(effectiveDate, maturityDate, 6 * Months,
161 TARGET(), ModifiedFollowing,
162 ModifiedFollowing, DateGeneration::Forward,
163 false);
164
165 ext::shared_ptr underlying =
166 ext::make_shared(VanillaSwap(
167 Swap::Payer, 1.0, fixedSchedule, strike, Thirty360(Thirty360::BondBasis),
168 floatingSchedule, euribor6m, 0.00, Actual360()));
169
170 std::vector exerciseDates;
171 for (Size i = 1; i < 10; ++i)
172 exerciseDates.push_back(
173 TARGET().advance(fixedSchedule[i], -2 * Days));
174
175 ext::shared_ptr exercise =
176 ext::make_shared(exerciseDates, false);
177 ext::shared_ptr swaption =
178 ext::make_shared(underlying, exercise);
179
180 cout << "\nThe model is a one factor Hull White model with piecewise "
181 "\nvolatility adapted to our exercise dates." << std::endl;
182
183 std::vector stepDates(exerciseDates.begin(),
184 exerciseDates.end() - 1);
185 std::vector sigmas(stepDates.size() + 1, 0.01);
186 Real reversion = 0.01;
187
188 cout << "\nThe reversion is just kept constant at a level of "
189 << reversion << std::endl;
190
191 cout << "\nThe model's curve is set to the 6m forward curve. Note that "
192 "\nthe model adapts automatically to other curves where "
193 "appropriate "
194 "\n(e.g. if an index requires a different forwarding curve) or "
195 "\nwhere explicitly specified (e.g. in a swaption pricing "
196 "engine)." << std::endl;
197
198 ext::shared_ptr gsr = ext::make_shared(
199 yts6m, stepDates, sigmas, reversion);
200
201 ext::shared_ptr swaptionEngine =
202 ext::make_shared(gsr, 64, 7.0, true,
203 false, ytsOis);
204 ext::shared_ptr nonstandardSwaptionEngine =
205 ext::make_shared(
206 gsr, 64, 7.0, true, false, Handle(), ytsOis);
207
208 swaption->setPricingEngine(nonstandardSwaptionEngine);
209
210 cout << "\nThe engine can generate a calibration basket in two modes."
211 "\nThe first one is called Naive and generates ATM swaptions "
212 "adapted to"
213 "\nthe exercise dates of the swaption and its maturity date"
214 << std::endl;
215
216 cout << "\nThe resulting basket looks as follows:" << std::endl;
217
218 ext::shared_ptr swapBase =
219 ext::make_shared(10 * Years, yts6m, ytsOis);
220
221
222 std::vector > basket =
223 swaption->calibrationBasket(swapBase, *swaptionVol,
224 BasketGeneratingEngine::Naive);
225 printBasket(basket);
226
227 cout << "\nLet's calibrate our model to this basket. We use a "
228 "specialized"
229 "\ncalibration method calibrating the sigma function one by one "
230 "to"
231 "\nthe calibrating vanilla swaptions. The result of this is as "
232 "follows:" << std::endl;
233
234 for (auto& i : basket)
235 i->setPricingEngine(swaptionEngine);
236
237 LevenbergMarquardt method;
238 EndCriteria ec(1000, 10, 1E-8, 1E-8,
239 1E-8); // only max iterations use actually used by LM
240
241 gsr->calibrateVolatilitiesIterative(basket, method, ec);
242
243 printModelCalibration(basket, gsr->volatility());
244
245 cout << "\nFinally we price our bermudan swaption in the "
246 "calibrated model:" << std::endl;
247
248 Real npv = swaption->NPV();
249
250 cout << "\nBermudan swaption NPV (ATM calibrated GSR) = "
251 << std::fixed << std::setprecision(6) << npv << std::endl;
252
253 cout << "\nThere is another mode to generate a calibration basket called"
254 "\nMaturityStrikeByDeltaGamma. This means that the maturity,"
255 "\nthe strike and the nominal of the calibrating swaptions are"
256 "\nobtained matching the NPV, first derivative and second derivative"
257 "\nof the swap you will exercise into at at each bermudan call date."
258 "\nThe derivatives are taken with respect to the model's state variable."
259 "\nLet's try this in our case." << std::endl;
260
261
262 basket = swaption->calibrationBasket(
263 swapBase, *swaptionVol,
264 BasketGeneratingEngine::MaturityStrikeByDeltaGamma);
265
266 printBasket(basket);
267
268 cout << "\nThe calibrated nominal is close to the exotics nominal."
269 "\nThe expiries and maturity dates of the vanillas are the same"
270 "\nas in the case above. The difference is the strike which"
271 "\nis now equal to the exotics strike." << std::endl;
272
273 cout << "\nLet's see how this affects the exotics npv. The "
274 "\nrecalibrated model is:" << std::endl;
275
276 for (auto& i : basket)
277 i->setPricingEngine(swaptionEngine);
278
279 gsr->calibrateVolatilitiesIterative(basket, method, ec);
280
281 printModelCalibration(basket, gsr->volatility());
282
283 cout << "\nAnd the bermudan's price becomes:" << std::endl;
284
285 npv = swaption->NPV();
286
287 cout << "\nBermudan swaption NPV (deal strike calibrated GSR) = "
288 << std::setprecision(6) << npv << std::endl;
289
290 cout << "\nWe can do more complicated things, let's e.g. modify the"
291 "\nnominal schedule to be linear amortizing and see what"
292 "\nthe effect on the generated calibration basket is:"
293 << std::endl;
294
295 std::vector nominalFixed, nominalFloating;
296 for (Size i = 0; i < fixedSchedule.size() - 1; ++i) {
297 Real tmpNom = 1.0 - (Real)i / (fixedSchedule.size() - 1);
298 nominalFixed.push_back(tmpNom);
299 nominalFloating.push_back(tmpNom);
300 nominalFloating.push_back(
301 tmpNom); // we use that the swap is 6m vs. 1y here
302 }
303 std::vector strikes(nominalFixed.size(), strike);
304
305 ext::shared_ptr underlying2(new NonstandardSwap(
306 Swap::Payer, nominalFixed, nominalFloating, fixedSchedule,
307 strikes, Thirty360(Thirty360::BondBasis), floatingSchedule, euribor6m, 1.0, 0.0,
308 Actual360()));
309 ext::shared_ptr swaption2 =
310 ext::make_shared(underlying2, exercise);
311
312 swaption2->setPricingEngine(nonstandardSwaptionEngine);
313
314 basket = swaption2->calibrationBasket(
315 swapBase, *swaptionVol,
316 BasketGeneratingEngine::MaturityStrikeByDeltaGamma);
317
318 printBasket(basket);
319
320 cout << "\nThe notional is weighted over the underlying exercised "
321 "\ninto and the maturity is adjusted downwards. The rate"
322 "\non the other hand is not affected." << std::endl;
323
324 cout << "\nYou can also price exotic bond's features. If you have e.g. a"
325 "\nbermudan callable fixed bond you can set up the call right "
326 "\nas a swaption to enter into a one leg swap with notional"
327 "\nreimbursement at maturity."
328 "\nThe exercise should then be written as a rebated exercise"
329 "\npaying the notional in case of exercise." << std::endl;
330
331 cout << "\nThe calibration basket looks like this:" << std::endl;
332
333 std::vector nominalFixed2(nominalFixed.size(), 1.0);
334 std::vector nominalFloating2(nominalFloating.size(), 0.0); // null the second leg
335
336 ext::shared_ptr underlying3(new NonstandardSwap(
337 Swap::Receiver, nominalFixed2, nominalFloating2,
338 fixedSchedule, strikes, Thirty360(Thirty360::BondBasis), floatingSchedule, euribor6m,
339 1.0, 0.0, Actual360(), false,
340 true)); // final capital exchange
341
342 ext::shared_ptr exercise2 =
343 ext::make_shared(*exercise, -1.0, 2, TARGET());
344
345 ext::shared_ptr swaption3 =
346 ext::make_shared(underlying3, exercise2);
347
348 ext::shared_ptr oas0 =
349 ext::make_shared(0.0);
350 ext::shared_ptr oas100 =
351 ext::make_shared(0.01);
352 RelinkableHandle oas(oas0);
353
354 ext::shared_ptr nonstandardSwaptionEngine2 =
355 ext::make_shared(
356 gsr, 64, 7.0, true, false, oas); // change discounting to 6m
357
358 swaption3->setPricingEngine(nonstandardSwaptionEngine2);
359
360 basket = swaption3->calibrationBasket(
361 swapBase, *swaptionVol,
362 BasketGeneratingEngine::MaturityStrikeByDeltaGamma);
363
364 printBasket(basket);
365
366 cout << "\nNote that nominals are not exactly 1.0 here. This is"
367 << "\nbecause we do our bond discounting on 6m level while"
368 << "\nthe swaptions are still discounted on OIS level."
369 << "\n(You can try this by changing the OIS level to the "
370 << "\n6m level, which will produce nominals near 1.0)."
371 << "\nThe npv of the call right is (after recalibrating the model)"
372 << std::endl;
373
374 for (auto& i : basket)
375 i->setPricingEngine(swaptionEngine);
376
377 gsr->calibrateVolatilitiesIterative(basket, method, ec);
378 Real npv3 = swaption3->NPV();
379
380 cout << "\nBond's bermudan call right npv = "
381 << std::setprecision(6) << npv3 << std::endl;
382
383 cout << "\nUp to now, no credit spread is included in the pricing."
384 "\nWe can do so by specifying an oas in the pricing engine."
385 "\nLet's set the spread level to 100bp and regenerate"
386 "\nthe calibration basket." << std::endl;
387
388 oas.linkTo(oas100);
389
390 basket = swaption3->calibrationBasket(
391 swapBase, *swaptionVol,
392 BasketGeneratingEngine::MaturityStrikeByDeltaGamma);
393
394 printBasket(basket);
395
396 cout << "\nThe adjusted basket takes the credit spread into account."
397 "\nThis is consistent to a hedge where you would have a"
398 "\nmargin on the float leg around 100bp,too." << std::endl;
399
400 cout << "\nThe npv becomes:" << std::endl;
401
402 for (auto& i : basket)
403 i->setPricingEngine(swaptionEngine);
404
405 gsr->calibrateVolatilitiesIterative(basket, method, ec);
406 Real npv4 = swaption3->NPV();
407
408 cout << "\nBond's bermudan call right npv (oas = 100bp) = "
409 << std::setprecision(6) << npv4 << std::endl;
410
411 cout << "\nThe next instrument we look at is a CMS 10Y vs Euribor "
412 "\n6M swaption. The maturity is again 10 years and the option"
413 "\nis exercisable on a yearly basis" << std::endl;
414
415 ext::shared_ptr underlying4(new FloatFloatSwap(
416 Swap::Payer, 1.0, 1.0, fixedSchedule, swapBase,
417 Thirty360(Thirty360::BondBasis), floatingSchedule, euribor6m, Actual360(), false,
418 false, 1.0, 0.0, Null(), Null(), 1.0, 0.0010));
419
420 ext::shared_ptr swaption4 =
421 ext::make_shared(underlying4, exercise);
422
423 ext::shared_ptr
424 floatSwaptionEngine(new Gaussian1dFloatFloatSwaptionEngine(
425 gsr, 64, 7.0, true, false, Handle(), ytsOis, true));
426
427 swaption4->setPricingEngine(floatSwaptionEngine);
428
429 cout << "\nSince the underlying is quite exotic already, we start with"
430 "\npricing this using the LinearTsrPricer for CMS coupon "
431 "estimation" << std::endl;
432
433 Handle reversionQuote(
434 ext::make_shared(reversion));
435
436 const Leg& leg0 = underlying4->leg(0);
437 const Leg& leg1 = underlying4->leg(1);
438 ext::shared_ptr cmsPricer =
439 ext::make_shared(swaptionVol, reversionQuote);
440 ext::shared_ptr iborPricer(new BlackIborCouponPricer);
441
442 setCouponPricer(leg0, cmsPricer);
443 setCouponPricer(leg1, iborPricer);
444
445 ext::shared_ptr swapPricer =
446 ext::make_shared(ytsOis);
447
448 underlying4->setPricingEngine(swapPricer);
449
450 Real npv5 = underlying4->NPV();
451
452 cout << "Underlying CMS Swap NPV = " << std::setprecision(6) << npv5 << std::endl;
453 cout << " CMS Leg NPV = " << underlying4->legNPV(0) << std::endl;
454 cout << " Euribor Leg NPV = " << underlying4->legNPV(1) << std::endl;
455
456 cout << "\nWe generate a naive calibration basket and calibrate "
457 "\nthe GSR model to it:" << std::endl;
458
459 basket = swaption4->calibrationBasket(swapBase, *swaptionVol, BasketGeneratingEngine::Naive);
460 for (auto& i : basket)
461 i->setPricingEngine(swaptionEngine);
462 gsr->calibrateVolatilitiesIterative(basket, method, ec);
463
464 printBasket(basket);
465 printModelCalibration(basket, gsr->volatility());
466
467 cout << "\nThe npv of the bermudan swaption is" << std::endl;
468
469 Real npv6 = swaption4->NPV();
470
471 cout << "\nFloat swaption NPV (GSR) = " << std::setprecision(6) << npv6 << std::endl;
472
473 cout << "\nIn this case it is also interesting to look at the "
474 "\nunderlying swap npv in the GSR model." << std::endl;
475
476 cout << "\nFloat swap NPV (GSR) = " << std::setprecision(6)
477 << swaption4->result("underlyingValue") << std::endl;
478
479 cout << "\nNot surprisingly, the underlying is priced differently"
480 "\ncompared to the LinearTsrPricer, since a different"
481 "\nsmile is implied by the GSR model." << std::endl;
482
483 cout << "\nThis is exactly where the Markov functional model"
484 << "\ncomes into play, because it can calibrate to any"
485 << "\ngiven underlying smile (as long as it is arbitrage"
486 << "\nfree). We try this now. Of course the usual use case"
487 << "\nis not to calibrate to a flat smile as in our simple"
488 << "\nexample, still it should be possible, of course..."
489 << std::endl;
490
491 std::vector markovStepDates(exerciseDates.begin(),
492 exerciseDates.end());
493 const std::vector& cmsFixingDates(markovStepDates);
494 std::vector markovSigmas(markovStepDates.size() + 1, 0.01);
495 std::vector tenors(cmsFixingDates.size(), 10 * Years);
496 ext::shared_ptr markov =
497 ext::make_shared(
498 yts6m, reversion, markovStepDates, markovSigmas, swaptionVol,
499 cmsFixingDates, tenors, swapBase,
500 MarkovFunctional::ModelSettings().withYGridPoints(16));
501
502 ext::shared_ptr swaptionEngineMarkov =
503 ext::make_shared(markov, 8, 5.0, true,
504 false, ytsOis);
505 ext::shared_ptr
506 floatEngineMarkov =
507 ext::make_shared(
508 markov, 16, 7.0, true, false, Handle(), ytsOis, true);
509
510 swaption4->setPricingEngine(floatEngineMarkov);
511
512 Real npv7 = swaption4->NPV();
513
514 cout << "\nThe option npv is the markov model is:" << std::endl;
515
516 cout << "\nFloat swaption NPV (Markov) = " << std::setprecision(6) << npv7 << std::endl;
517
518 cout << "\nThis is not too far from the GSR price." << std::endl;
519
520 cout << "\nMore interesting is the question how well the Markov"
521 << "\nmodel did its job to match our input smile. For this"
522 << "\nwe look at the underlying npv under the Markov model" << std::endl;
523
524 cout << "\nFloat swap NPV (Markov) = " << std::setprecision(6)
525 << swaption4->result("underlyingValue") << std::endl;
526
527 cout << "\nThis is closer to our terminal swap rate model price."
528 "\nA perfect match is not expected anyway, because the"
529 "\ndynamics of the underlying rate in the linear"
530 "\nmodel is different from the Markov model, of"
531 "\ncourse." << std::endl;
532
533 cout << "\nThe Markov model can not only calibrate to the"
534 "\nunderlying smile, but has at the same time a"
535 "\nsigma function (similar to the GSR model) which"
536 "\ncan be used to calibrate to a second instrument"
537 "\nset. We do this here to calibrate to our coterminal"
538 "\nATM swaptions from above." << std::endl;
539
540 cout << "\nThis is a computationally demanding task, so"
541 "\ndepending on your machine, this may take a"
542 "\nwhile now..." << std::endl;
543
544 for (auto& i : basket)
545 i->setPricingEngine(swaptionEngineMarkov);
546
547 markov->calibrate(basket, method, ec);
548
549 printModelCalibration(basket, markov->volatility());
550
551 cout << "\nNow let's have a look again at the underlying pricing."
552 "\nIt shouldn't have changed much, because the underlying"
553 "\nsmile is still matched." << std::endl;
554
555 Real npv8 = swaption4->result("underlyingValue");
556
557 cout << "\nFloat swap NPV (Markov) = " << std::setprecision(6) << npv8 << std::endl;
558
559 cout << "\nThis is close to the previous value as expected." << std::endl;
560
561 cout << "\nAs a final remark we note that the calibration to"
562 << "\ncoterminal swaptions is not particularly reasonable"
563 << "\nhere, because the european call rights are not"
564 << "\nwell represented by these swaptions."
565 << "\nSecondly, our CMS swaption is sensitive to the"
566 << "\ncorrelation between the 10y swap rate and the"
567 << "\nEuribor 6M rate. Since the Markov model is one factor"
568 << "\nit will most probably underestimate the market value"
569 << "\nby construction." << std::endl;
570
571 cout << "\nThat was it. Thank you for running this demo. Bye." << std::endl;
572 }
573
574 catch (const QuantLib::Error& e) {
575 cout << "terminated with a ql exception: " << e.what()
576 << std::endl;
577 return 1;
578 }
579 catch (const std::exception& e) {
580 cout << "terminated with a general exception: " << e.what()
581 << std::endl;
582 return 1;
583 }
584 }
File: output
585
586 z_QuantLib.cpp/testQuantLib(void) * QuantLib version: 10.40 1.31.1
587 *Begin Time: 2023-Oct-15 05:41:28.859000
588 latent Model
589
590 Gaussian versus T prob of extreme event (random and integrable)-
591 -Prob of 0 events... 1 ** 0.99999 ** 1 ** 1
592 -Prob of 1 events... 0.252189 ** 0.249196 ** 0.2524 ** 0.24917
593 -Prob of 2 events... 0.0328963 ** 0.0336561 ** 0.03279 ** 0.03368
594 -Prob of 3 events... 0.00199248 ** 0.00421316 ** 0.00201 ** 0.0041
595
596 -- Default correlations G,T,GRand,TRand--
597 -----------------------------------------
598 1 , 0.00935891 , 0.00935891 ,
599 0.00935891 , 1 , 0.00935891 ,
600 0.00935891 , 0.00935891 , 1 ,
601
602 1 , 0.031698 , 0.031698 ,
603 0.031698 , 1 , 0.031698 ,
604 0.031698 , 0.031698 , 1 ,
605
606 1.00001 , 0.00827934 , 0.00517704 ,
607 0.00827934 , 1.00001 , 0.0103137 ,
608 0.00517704 , 0.0103137 , 1.00001 ,
609
610 1.00001 , 0.0305301 , 0.0283078 ,
611 0.0305301 , 1.00001 , 0.0323241 ,
612 0.0283078 , 0.0323241 , 1.00001 ,
613
614 *Begin Time: 2023-Oct-15 05:41:28.859000
615 Begin Time: 2023-Oct-15 05:41:28.859000
616 End Time: 2023-Oct-15 05:41:50.728000
617 Elapsed Time: 21 seconds and 21869 mili seconds 21.21869
618 Elapsed Time(seconds): 42
619 QuantLib version: 1.31.1
620 Boost version: 1.83.0
621 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
GlobalOptimizer
1 Begin Time: 2023-Sep-27 08:19:27.704000
2 QuantLib version: 1.31.1
3
4 GlobalOptimizer.cpp
5
6 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 Firefly Algorithm Test
8 ----------------------------------------------------------------
9 Function eggholder, Agents: 150, Vola: 1.5, Intensity: 1
10 Starting point: f(0, 0) = -25.4603
11 End point: f(512, 404.233) = -959.641
12 Global optimum: f(512, 404.232) = -959.641
13 ================================================================
14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 Hybrid Simulated Annealing Test
16 ----------------------------------------------------------------
17 Function: ackley, Dimensions: 3, Initial temp:100, Final temp:0.1, Reset scheme:1, Reset steps:150
18 Starting point: f(1.5, 1.5, 1.5) = 8.64483
19 End point: f(-3.9612e-10, -7.59216e-10, -5.20854e-10) = -1.76341
20 Global optimum: f(0, 0, 0) = -1.76341
21 ================================================================
22 Function: ackley, Dimensions: 10, Initial temp:100, Final temp:0.1, Reset scheme:1, Reset steps:150
23 Starting point: f(1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5) = 12.4858
24 End point: f(-12, -7.99998, 7.00012, -2.00008, 16, -65.9999, 27, 14, -33.0001, -13) = -125.695
25 Global optimum: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = -145.695
26 ================================================================
27 Function: ackley, Dimensions: 30, Initial temp:100, Final temp:0.1, Reset scheme:1, Reset steps:150
28 Starting point: f(1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5,
29 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5) = 16.4604
30 End point: f(-12.0762, 32.9876, -20.0425, 44.0148, -11.9894, -69.189, 57.9683, 38.9634, -0.91182,
31 6.01559, -23.0271, 7.98989, 53.0801, 57.962, -18.1016, -24.0706, -2.98203, 1.90956, -11.0558,
32 -10.5171, 31.9222, -4.98168, -68.9358, -14.1033, -39.7814, -23.0863, 21.7602, -18.1119,
33 53.9189, -57.0111) = -138480
34 Global optimum: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = -3.26901e+06
36 ================================================================
37 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 Particle Swarm Optimization Test
39 ----------------------------------------------------------------
40 Function: rosenbrock, Dimensions: 3, Agents: 100, K-neighbors: 25, Threshold: 500
41 Starting point: f(0, 0, 0) = 2
42 End point: f(1, 1, 1) = 8.87469e-30
43 Global optimum: f(1, 1, 1) = 0
44 ================================================================
45 Function: rosenbrock, Dimensions: 10, Agents: 100, K-neighbors: 25, Threshold: 500
46 Starting point: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = 9
47 End point: f(1, 1, 1, 1, 1, 1, 1, 1, 1, 0.999999) = 1.13266e-13
48 Global optimum: f(1, 1, 1, 1, 1, 1, 1, 1, 1, 1) = 0
49 ================================================================
50 Function: rosenbrock, Dimensions: 30, Agents: 100, K-neighbors: 25, Threshold: 500
51 Starting point: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = 29
53 End point: f(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
54 1, 1, 1, 1, 1, 1, 1, 1, 1.00001, 1.00002, 1.00004, 1.00007) = 2.13593e-09
55 Global optimum: f(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
56 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) = 0
57 ================================================================
58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59 Simulated Annealing Test
60 ----------------------------------------------------------------
61 Function ackley, Lambda: 0.1, Temperature: 350, Epsilon: 0.99, Iterations: 1000
62 Starting point: f(1.5, 1.5, 1.5) = 8.64483
63 End point: f(-0.0105481, 0.217139, 0.0154376) = 0.323981
64 Global optimum: f(0, 0, 0) = -1.76341
65 ================================================================
66 Function ackley, Lambda: 0.1, Temperature: 350, Epsilon: 0.99, Iterations: 1000
67 Starting point: f(1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5) = 12.4858
68 End point: f(3.92748, -0.159356, 2.93683, 0.961311, 2.99826,
69 0.945902, -0.0364158, 1.92264, -2.05194, 2.91581) = -71.9656
70 Global optimum: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = -145.695
71 ================================================================
72 Function ackley, Lambda: 0.1, Temperature: 350, Epsilon: 0.99, Iterations: 1000
73 Starting point: f(1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5,
74 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5,
75 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5) = 16.4604
76 End point: f(1.94186, 2.01441, 1.22074, 1.95719, 1.96516,
77 1.97919, 1.0248, 2.08729, -0.00165529, -0.030517, 3.00412,
78 1.1271, 1.96798, 1.98459, 1.942, -0.0290291, 0.977605, 2.02131,
79 0.92106, 0.876527, -0.0128266, 2.00096, 2.78297, 1.98555,
80 -0.051758, 0.945374, 2.97153, 2.01402, 0.967426, 3.01027) = -757934
81 Global optimum: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = -3.26901e+06
83 ================================================================
84
85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86 Differential Evolution Test
87 ----------------------------------------------------------------
88 Function: rosenbrock, Dimensions: 3, Agents: 50, Probability: 0.3,
89 StepsizeWeight: 0.6, Strategy: BestMemberWithJitter
90 Starting point: f(0, 0, 0) = 2
91 End point: f(1, 1, 1) = 1.01752e-15
92 Global optimum: f(1, 1, 1) = 0
93 ================================================================
94 Function: rosenbrock, Dimensions: 10, Agents: 150, Probability: 0.3,
95 StepsizeWeight: 0.6, Strategy: BestMemberWithJitter
96 Starting point: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = 9
97 End point: f(1, 1, 1, 1, 1, 0.999999, 0.999998, 0.999997, 0.999994, 0.999988) = 5.55643e-11
98 Global optimum: f(1, 1, 1, 1, 1, 1, 1, 1, 1, 1) = 0
99 ================================================================
100 Function: rosenbrock, Dimensions: 30, Agents: 450, Probability: 0.3,
101 StepsizeWeight: 0.6, Strategy: BestMemberWithJitter
102 Starting point: f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) = 29
104 End point: f(0.999998, 0.999996, 0.999999, 1, 0.999997, 0.999999,
105 0.999999, 1, 1, 0.999999, 0.999999, 0.999998, 0.999999, 1, 0.999998,
106 1, 0.999998, 1, 0.999999, 0.999999, 0.999995, 0.99999, 0.999982,
107 0.999966, 0.999938, 0.999904, 0.999819, 0.99965,
108 0.999308, 0.998614) = 7.99492e-07
109 Global optimum: f(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
110 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) = 0
111 ================================================================
112 Name: UK settlement
113 New Year is Holiday: 0
114 New Year is Business Day: 1
115 --------------- Date Counter --------------------
116 First Date: December 28th, 2008
117 Second Date: January 4th, 2009
118 Business Days Betweeen: 4
119 End of Month 1. Date: December 31st, 2008
120 End of Month 2. Date: January 30th, 2009
121
122 Begin Time: 2023-Sep-27 08:19:27.704000
123 End Time: 2023-Sep-27 08:22:01.550000
124 Elapsed Time(seconds): 153
125 Elapsed Time(mili seconds): 153846
126 QuantLib version: 1.31.1
127 Boost version: 1.83.0
128 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
129 Exit quantLib test
130
131
132 Build started...
133 1>------ Build started: Project: QL, Configuration: Debug x64 ------
134 1>ExSan.cpp
135 1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\
136 MSVC\14.37.32822\include\stdfloat(13): warning STL4038:
137 The contents of are available only with C++23 or later.
138 1>QL.vcxproj -> C:\Users\User\Documents\Visual Community 2022\Cpp\QL\x64\Debug\QL.exe
139 1>Done building project "QL.vcxproj".
140 ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
141 ========== Build started at 8:18 and took 30,055 seconds ==========
LatentModel
34
35 using namespace std;
36 using namespace QuantLib;
37
38 /* This sample code shows basic usage of a Latent variable model.
39 The data and correlation problem presented is the same as in:
40 'Modelling Dependent Defaults: Asset Correlations Are Not Enough!'
41 Frey R., A. J. McNeil and M. A. Nyfeler RiskLab publications March 2001
42 */
43 //int main(int, char* []) {
44 int latentQL() {
45 cout << "\n\tlatent Model\n";
46 try {
47 cout << std::endl;
48 Calendar calendar = TARGET();
49 Date todaysDate(19, March, 2014);
50 // must be a business day
51 todaysDate = calendar.adjust(todaysDate);
52
53 Settings::instance().evaluationDate() = todaysDate;
54
55 /* --------------------------------------------------------------
56 SET UP BASKET PORTFOLIO
57 -------------------------------------------------------------- */
58 // build curves and issuers into a basket of three names
59 std::vector hazardRates(3, -std::log(1. - 0.01));
60 std::vector names;
61 for (Size i = 0; i < hazardRates.size(); i++)
62 names.push_back(std::string("Acme") + std::to_string(i));
63 std::vector > defTS;
64 defTS.reserve(hazardRates.size());
65 for (Real& hazardRate : hazardRates)
66 defTS.emplace_back(
67 ext::make_shared(0, TARGET(), hazardRate, Actual365Fixed()));
68 std::vector issuers;
69 for (Size i = 0; i < hazardRates.size(); i++) {
70 std::vector curves(1,
71 std::make_pair(NorthAmericaCorpDefaultKey(
72 EURCurrency(), QuantLib::SeniorSec,
73 Period(), 1. // amount threshold
74 ), defTS[i]));
75 issuers.emplace_back(curves);
76 }
77
78 ext::shared_ptr thePool = ext::make_shared();
79 for (Size i = 0; i < hazardRates.size(); i++)
80 thePool->add(names[i], issuers[i], NorthAmericaCorpDefaultKey(
81 EURCurrency(), QuantLib::SeniorSec, Period(), 1.));
82
83 std::vector defaultKeys(hazardRates.size(),
84 NorthAmericaCorpDefaultKey(EURCurrency(), SeniorSec, Period(), 1.));
85 // Recoveries are irrelevant in this example but must be given as the
86 // lib stands.
87 std::vector > rrModels(
88 hazardRates.size(), ext::make_shared(
89 ConstantRecoveryModel(0.5, SeniorSec)));
90 ext::shared_ptr theBskt = ext::make_shared(
91 todaysDate, names, std::vector(hazardRates.size(), 100.),
92 thePool);
93 /* --------------------------------------------------------------
94 SET UP JOINT DEFAULT EVENT LATENT MODELS
95 -------------------------------------------------------------- */
96 // Latent model factors, corresponds to the first entry in Table1 of the
97 // publication mentioned. It is a single factor model
98 std::vector > fctrsWeights(hazardRates.size(),
99 std::vector(1, std::sqrt(0.1)));
100 // --- Default Latent models -------------------------------------
101 #ifndef QL_PATCH_SOLARIS
102 // Gaussian integrable joint default model:
103 ext::shared_ptr lmG(new
104 GaussianDefProbLM(fctrsWeights,
105 LatentModelIntegrationType::GaussianQuadrature,
106 GaussianCopulaPolicy::initTraits() // otherwise gcc screams
107 ));
108 #endif
109 // Define StudentT copula
110 // this is as far as we can be from the Gaussian, 2 T_3 factors:
111 std::vector ordersT(2, 3);
112 TCopulaPolicy::initTraits iniT;
113 iniT.tOrders = ordersT;
114 // StudentT integrable joint default model:
115 ext::shared_ptr lmT(new TDefProbLM(fctrsWeights,
116 // LatentModelIntegrationType::GaussianQuadrature,
117 LatentModelIntegrationType::Trapezoid,
118 iniT));
119
120 // --- Default Loss models ----------------------------------------
121 // Gaussian random joint default model:
122 Size numSimulations = 100000;
123 // Size numCoresUsed = 4;
124 #ifndef QL_PATCH_SOLARIS
125 // Sobol, many cores
126 ext::shared_ptr rdlmG(
127 ext::make_shared >(lmG,
128 std::vector(), numSimulations, 1.e-6, 2863311530UL));
129 #endif
130 // StudentT random joint default model:
131 ext::shared_ptr rdlmT(
132 ext::make_shared >(lmT,
133 std::vector(), numSimulations, 1.e-6, 2863311530UL));
134
135 /* --------------------------------------------------------------
136 DUMP SOME RESULTS
137 -------------------------------------------------------------- */
138 /* Default correlations in a T copula should be below those of the
139 gaussian for the same factors.
140 The calculations on the MC show dispersion on both copulas (thats
141 ok) and too large values with very large dispersions on the T case.
142 Computations are ok, within the dispersion, for the gaussian; compare
143 with the direct integration in both cases.
144 However the T does converge to the gaussian value for large value of
145 the parameters.
146 */
147 Date calcDate(TARGET().advance(Settings::instance().evaluationDate(),
148 Period(120, Months)));
149 std::vector probEventsTLatent, probEventsTRandLoss;
150 #ifndef QL_PATCH_SOLARIS
151 std::vector probEventsGLatent, probEventsGRandLoss;
152 #endif
153 //
154 lmT->resetBasket(theBskt);
155 for (Size numEvts = 0; numEvts <= theBskt->size(); numEvts++) {
156 probEventsTLatent.push_back(lmT->probAtLeastNEvents(numEvts,
157 calcDate));
158 }
159 //
160 theBskt->setLossModel(rdlmT);
161 for (Size numEvts = 0; numEvts <= theBskt->size(); numEvts++) {
162 probEventsTRandLoss.push_back(theBskt->probAtLeastNEvents(numEvts,
163 calcDate));
164 }
165 //
166 #ifndef QL_PATCH_SOLARIS
167 lmG->resetBasket(theBskt);
168 for (Size numEvts = 0; numEvts <= theBskt->size(); numEvts++) {
169 probEventsGLatent.push_back(lmG->probAtLeastNEvents(numEvts,
170 calcDate));
171 }
172 //
173 theBskt->setLossModel(rdlmG);
174 for (Size numEvts = 0; numEvts <= theBskt->size(); numEvts++) {
175 probEventsGRandLoss.push_back(theBskt->probAtLeastNEvents(numEvts,
176 calcDate));
177 }
178 #endif
179
180 Date correlDate = TARGET().advance(
181 Settings::instance().evaluationDate(), Period(12, Months));
182 std::vector > correlsGlm, correlsTlm, correlsGrand,
183 correlsTrand;
184 //
185 lmT->resetBasket(theBskt);
186 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
187 std::vector tmp;
188 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
189 tmp.push_back(lmT->defaultCorrelation(correlDate,
190 iName1, iName2));
191 correlsTlm.push_back(tmp);
192 }
193 //
194 theBskt->setLossModel(rdlmT);
195 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
196 std::vector tmp;
197 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
198 tmp.push_back(theBskt->defaultCorrelation(correlDate,
199 iName1, iName2));
200 correlsTrand.push_back(tmp);
201 }
202 #ifndef QL_PATCH_SOLARIS
203 //
204 lmG->resetBasket(theBskt);
205 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
206 std::vector tmp;
207 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
208 tmp.push_back(lmG->defaultCorrelation(correlDate,
209 iName1, iName2));
210 correlsGlm.push_back(tmp);
211 }
212 //
213 theBskt->setLossModel(rdlmG);
214 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
215 std::vector tmp;
216 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
217 tmp.push_back(theBskt->defaultCorrelation(correlDate,
218 iName1, iName2));
219 correlsGrand.push_back(tmp);
220 }
221 #endif
222
223
224 cout << " Gaussian versus T prob of extreme event (random and integrable)-" << std::endl;
225 for (Size numEvts = 0; numEvts <= theBskt->size(); numEvts++) {
226 cout << "-Prob of " << numEvts << " events... " <<
227 #ifndef QL_PATCH_SOLARIS
228 probEventsGLatent[numEvts] << " ** " <<
229 #else
230 "n/a" << " ** " <<
231 #endif
232 probEventsTLatent[numEvts] << " ** " <<
233 #ifndef QL_PATCH_SOLARIS
234 probEventsGRandLoss[numEvts] << " ** " <<
235 #else
236 "n/a" << " ** " <<
237 #endif
238 probEventsTRandLoss[numEvts]
239 << std::endl;
240 }
241
242 cout << endl;
243 cout << "-- Default correlations G,T,GRand,TRand--" << endl;
244 cout << "-----------------------------------------" << endl;
245 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
246 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
247 cout <<
248 #ifndef QL_PATCH_SOLARIS
249 correlsGlm[iName1][iName2] << " , ";
250 #else
251 "n/a" << " , ";
252 #endif
253 cout << endl;
254 }
255 cout << endl;
256 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
257 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
258 cout <<
259 correlsTlm[iName1][iName2] << " , ";
260 ;
261 cout << endl;
262 }
263 cout << endl;
264 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
265 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
266 cout <<
267 #ifndef QL_PATCH_SOLARIS
268 correlsGrand[iName1][iName2] << " , ";
269 #else
270 "n/a" << " , ";
271 #endif
272 cout << endl;
273 }
274 cout << endl;
275 for (Size iName1 = 0; iName1 < theBskt->size(); iName1++) {
276 for (Size iName2 = 0; iName2 < theBskt->size(); iName2++)
277 cout << correlsTrand[iName1][iName2] << " , ";
278 ;
279 cout << endl;
280 }
281
282 return 0;
283 }
284 catch (exception& e) {
285 cerr << e.what() << endl;
286 return 1;
287 }
288 catch (...) {
289 cerr << "unknown error" << endl;
290 return 1;
291 }
292 }
293
294
output
295
296 z_QuantLib.cpp/testQuantLib(void) * QuantLib version: 10.40 1.31.1
297 *Begin Time: 2023-Oct-14 10:46:03.395000
298 latent Model
299
300 Gaussian versus T prob of extreme event (random and integrable)-
301 -Prob of 0 events... 1 ** 0.99999 ** 1 ** 1
302 -Prob of 1 events... 0.252189 ** 0.249196 ** 0.2524 ** 0.24917
303 -Prob of 2 events... 0.0328963 ** 0.0336561 ** 0.03279 ** 0.03368
304 -Prob of 3 events... 0.00199248 ** 0.00421316 ** 0.00201 ** 0.0041
305
306 -- Default correlations G,T,GRand,TRand--
307 -----------------------------------------
308 1 , 0.00935891 , 0.00935891 ,
309 0.00935891 , 1 , 0.00935891 ,
310 0.00935891 , 0.00935891 , 1 ,
311
312 1 , 0.031698 , 0.031698 ,
313 0.031698 , 1 , 0.031698 ,
314 0.031698 , 0.031698 , 1 ,
315
316 1.00001 , 0.00827934 , 0.00517704 ,
317 0.00827934 , 1.00001 , 0.0103137 ,
318 0.00517704 , 0.0103137 , 1.00001 ,
319
320 1.00001 , 0.0305301 , 0.0283078 ,
321 0.0305301 , 1.00001 , 0.0323241 ,
322 0.0283078 , 0.0323241 , 1.00001 ,
323
324 *Begin Time: 2023-Oct-14 10:46:03.395000
325 Begin Time: 2023-Oct-14 10:46:03.395000
326 End Time: 2023-Oct-14 10:46:23.917000
327 Elapsed Time: 20 seconds and 20522 mili seconds 20.20522
328 Elapsed Time(seconds): 40
329 QuantLib version: 1.31.1
330 Boost version: 1.83.0
331 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
MarketModels
1 Begin Time: 2023-Sep-26 09:54:32.243000 QuantLib version: 1.31.1
2
3 MarketModels.cpp
4 inverse floater
5 fixed strikes : 0.15
6 number rates : 20
7 training paths, 8192
8 paths, 8192
9 vega Paths, 1024
10 rate level 0.05
11 -0.0163102
12 0.0868556
13 time to build strategy, 8.819, seconds.
14 time to price, 13.483, seconds.
15 vega output
16 factorwise bumping 0
17 doCaps 0
18 price estimate, 0.0867505
19 Delta, 0, 1.32586, 0.00697765
20 Delta, 1, 1.2217, 0.012492
21 Delta, 2, 1.11844, 0.0154305
22 Delta, 3, 1.00695, 0.0175338
º º º
36 Delta, 17, 0.267288, 0.0127586
37 Delta, 18, 0.241634, 0.0121926
38 Delta, 19, 0.211169, 0.0115879
39 vega, 0, 0.000238311 ,0
40 vega, 1, -0.000540559 ,0
41 vega, 2, 0.00144704 ,0
42 vega, 3, 0.00124777 ,0
º º º
57 vega, 18, -4.46314e-05 ,0
58 vega, 19, 5.26027e-05 ,0
59 total Vega, 0.00529884
60 vega output
61 factorwise bumping 1
62 doCaps 0
63 price estimate, 0.0867505
64 Delta, 0, 1.32586, 0.00697765
65 Delta, 1, 1.2217, 0.012492
66 Delta, 2, 1.11844, 0.0154305
67 Delta, 3, 1.00695, 0.0175338
º º º
81 Delta, 17, 0.267288, 0.0127586
82 Delta, 18, 0.241634, 0.0121926
83 Delta, 19, 0.211169, 0.0115879
84 vega, 0, 1.37095e-05 ,0
85 vega, 1, 0.000346951 ,0
86 vega, 2, 0.000755235 ,0
º º º
102 vega, 18, 3.76146e-05 ,0
103 vega, 19, 2.57313e-05 ,0
104 total Vega, 0.00487331
105 vega output
106 factorwise bumping 0
107 doCaps 1
108 price estimate, 0.0867505
109 Delta, 0, 1.32586, 0.00697765
110 Delta, 1, 1.2217, 0.012492
111 Delta, 2, 1.11844, 0.0154305
º º º
126 Delta, 17, 0.267288, 0.0127586
127 Delta, 18, 0.241634, 0.0121926
128 Delta, 19, 0.211169, 0.0115879
129 vega, 0, -4.22408e-05 ,0
130 vega, 1, -0.000792249 ,0
131 vega, 2, 0.00149812 ,0
132 vega, 3, 0.0012451 ,0
133 vega, 4, -0.000850462 ,0
134 vega, 5, 0.00300618 ,0
º º º
162 vega, 33, -4.65385e-05 ,0
163 vega, 34, -5.21661e-05 ,0
164 total Vega, 0.00756555
165 vega output
166 factorwise bumping 1
167 doCaps 1
168 price estimate, 0.0867505
169 Delta, 0, 1.32586, 0.00697765
170 Delta, 1, 1.2217, 0.012492
171 Delta, 2, 1.11844, 0.0154305
º º º
186 Delta, 17, 0.267288, 0.0127586
187 Delta, 18, 0.241634, 0.0121926
188 Delta, 19, 0.211169, 0.0115879
189 vega, 0, -2.49179e-05 ,0
190 vega, 1, 0.000162094 ,0
191 vega, 2, 0.000594682 ,0
192 vega, 3, 0.00118513 ,0
193 vega, 4, 0.000556093 ,0
º º º
222 vega, 33, -6.6534e-05 ,0
223 vega, 34, -6.98233e-05 ,0
224 vega, 35, -0.000114118 ,0
225 vega, 36, -9.73229e-05 ,0
226 vega, 37, -3.68239e-05 ,0
227 vega, 38, -3.89956e-05 ,0
228 total Vega, 0.00521601
229 Upper - lower is, 0.00567566, with standard error 0.000567726
230 time to compute upper bound is, 342.247, seconds.
231 inverse floater
232 fixed strikes : 0.15
233 number rates : 20
234 training paths, 8192
235 paths, 8192
236 vega Paths, 1024
237 rate level 0.06
238 0.172554
239 0.21675
240 time to build strategy, 9.387, seconds.
241 time to price, 13.942, seconds.
242 vega output
243 factorwise bumping 0
244 doCaps 0
245 price estimate, 0.217573
246 Delta, 0, 1.25707, 0.00505225
247 Delta, 1, 1.17624, 0.00790033
248 Delta, 2, 1.09578, 0.0098834
º º º
264 Delta, 18, 0.318489, 0.0104608
265 Delta, 19, 0.271991, 0.00997292
266 vega, 0, -0.000452958 ,0
267 vega, 1, -0.000300466 ,0
268 vega, 2, 0.000652116 ,0
º º º
284 vega, 18, -3.9356e-05 ,0
285 vega, 19, 5.70183e-05 ,0
286 total Vega, 0.00127483
287 vega output
288 factorwise bumping 1
289 doCaps 0
290 price estimate, 0.217573
291 Delta, 0, 1.25707, 0.00505225
292 Delta, 1, 1.17624, 0.00790033
293 Delta, 2, 1.09578, 0.0098834
294 Delta, 3, 1.0096, 0.0111099
º º º
306 Delta, 15, 0.412406, 0.01168
307 Delta, 16, 0.387111, 0.0113693
308 Delta, 17, 0.348954, 0.010846
309 Delta, 18, 0.318489, 0.0104608
310 Delta, 19, 0.271991, 0.00997292
311 vega, 0, -9.03707e-05 ,0
312 vega, 1, -0.000129169 ,0
313 vega, 2, 0.000123926 ,0
314 vega, 3, -5.43411e-05 ,0
º º º
329 vega, 18, 6.70467e-06 ,0
330 vega, 19, 6.41868e-05 ,0
331 total Vega, 0.00138851
332 vega output
333 factorwise bumping 0
334 doCaps 1
335 price estimate, 0.217573
336 Delta, 0, 1.25707, 0.00505225
337 Delta, 1, 1.17624, 0.00790033
338 Delta, 2, 1.09578, 0.0098834
339 Delta, 3, 1.0096, 0.0111099
º º º
354 Delta, 18, 0.318489, 0.0104608
355 Delta, 19, 0.271991, 0.00997292
356 vega, 0, -7.7746e-05 ,0
357 vega, 1, -0.000222112 ,0
358 vega, 2, 0.000789888 ,0
359 vega, 3, 4.86573e-05 ,0
360 vega, 4, -3.40801e-05 ,0
361 vega, 5, 0.00165109 ,0
362 vega, 6, -0.00229894 ,0
363 vega, 7, 0.00182743 ,0
º º º
389 vega, 33, -0.000122365 ,0
390 vega, 34, -0.000105843 ,0
391 total Vega, 0.00136272
392 vega output
393 factorwise bumping 1
394 doCaps 1
395 price estimate, 0.217573
396 Delta, 0, 1.25707, 0.00505225
397 Delta, 1, 1.17624, 0.00790033
398 Delta, 2, 1.09578, 0.0098834
º º º
413 Delta, 17, 0.348954, 0.010846
414 Delta, 18, 0.318489, 0.0104608
415 Delta, 19, 0.271991, 0.00997292
416 vega, 0, -2.69803e-05 ,0
417 vega, 1, 2.21854e-05 ,0
418 vega, 2, 0.000342796 ,0
419 vega, 3, 0.000188348 ,0
420 vega, 4, 7.50689e-05 ,0
421 vega, 5, 0.000958102 ,0
422 vega, 6, -0.000706874 ,0
423 vega, 7, 0.000556081 ,0
424 vega, 8, 0.000345365 ,0
425 vega, 9, 8.20215e-06 ,0
º º º
451 vega, 35, -0.000220035 ,0
452 vega, 36, -0.000206515 ,0
453 vega, 37, -0.00016524 ,0
454 vega, 38, -1.54774e-05 ,0
455 total Vega, 0.00077847
456 Upper - lower is, 0.00279201, with standard error 0.00042531
457 time to compute upper bound is, 418.172, seconds.
458 inverse floater
459 fixed strikes : 0.15
460 number rates : 20
461 training paths, 8192
462 paths, 8192
463 vega Paths, 1024
464 rate level 0.07
465 0.323515
466 0.342549
467 time to build strategy, 9.452, seconds.
468 time to price, 14.776, seconds.
469 vega output
470 factorwise bumping 0
471 doCaps 0
472 price estimate, 0.342737
473 Delta, 0, 0.974753, 0.0119069
474 Delta, 1, 0.886859, 0.0119163
* * *
487 Delta, 14, 0.424369, 0.0087738
488 Delta, 15, 0.395253, 0.00854362
489 Delta, 16, 0.380985, 0.00845121
490 Delta, 17, 0.357063, 0.00824797
491 Delta, 18, 0.340226, 0.00806955
492 Delta, 19, 0.295172, 0.00793197
493 vega, 0, -0.00156808 ,0
494 vega, 1, 6.52581e-05 ,0
495 vega, 2, 0.000644331 ,0
496 vega, 3, 8.57844e-06 ,0
* * *
508 vega, 15, 7.22987e-05 ,0
509 vega, 16, -5.41747e-05 ,0
510 vega, 17, -4.414e-05 ,0
511 vega, 18, -0.000131302 ,0
512 vega, 19, 5.04762e-05 ,0
513 total Vega, -0.00167947
514 vega output
515 factorwise bumping 1
516 doCaps 0
517 price estimate, 0.342737
518 Delta, 0, 0.974753, 0.0119069
519 Delta, 1, 0.886859, 0.0119163
520 Delta, 2, 0.799723, 0.0119849
521 Delta, 3, 0.766886, 0.0114094
* * *
535 Delta, 17, 0.357063, 0.00824797
536 Delta, 18, 0.340226, 0.00806955
537 Delta, 19, 0.295172, 0.00793197
538 vega, 0, -0.000410461 ,0
539 vega, 1, -0.000327282 ,0
540 vega, 2, -0.000306096 ,0
541 vega, 3, -0.000258822 ,0
* * *
553 vega, 15, 0.000195981 ,0
554 vega, 16, -1.93034e-05 ,0
555 vega, 17, -2.4007e-05 ,0
556 vega, 18, -4.28699e-05 ,0
557 vega, 19, 8.0729e-05 ,0
558 total Vega, -0.00203148
559 vega output
560 factorwise bumping 0
561 doCaps 1
562 price estimate, 0.342737
563 Delta, 0, 0.974753, 0.0119069
564 Delta, 1, 0.886859, 0.0119163
565 Delta, 2, 0.799723, 0.0119849
566 Delta, 3, 0.766886, 0.0114094
* * *
579 Delta, 16, 0.380985, 0.00845121
580 Delta, 17, 0.357063, 0.00824797
581 Delta, 18, 0.340226, 0.00806955
582 Delta, 19, 0.295172, 0.00793197
583 vega, 0, -0.000186785 ,0
584 vega, 1, -4.61459e-05 ,0
585 vega, 2, 0.000602706 ,0
586 vega, 3, -2.0546e-05 ,0
587 vega, 4, -0.000329798 ,0
* * *
616 vega, 33, -0.000187908 ,0
617 vega, 34, -0.0001909 ,0
618 total Vega, -0.00389955
619 vega output
620 factorwise bumping 1
621 doCaps 1
622 price estimate, 0.342737
623 Delta, 0, 0.974753, 0.0119069
624 Delta, 1, 0.886859, 0.0119163
625 Delta, 2, 0.799723, 0.0119849
626 Delta, 3, 0.766886, 0.0114094
627 Delta, 4, 0.723408, 0.0110285
628 Delta, 5, 0.694783, 0.0108878
. . .
642 Delta, 19, 0.295172, 0.00793197
643 vega, 0, -5.44257e-05 ,0
644 vega, 1, 0.000107786 ,0
645 vega, 2, 0.000118882 ,0
646 vega, 3, 0.000132511 ,0
* * *
676 vega, 33, -0.000334439 ,0
677 vega, 34, -0.000303679 ,0
678 vega, 35, -0.000355093 ,0
679 vega, 36, -0.000321851 ,0
680 vega, 37, -0.000283163 ,0
681 vega, 38, -0.000133919 ,0
682 total Vega, -0.00359569
683 Upper - lower is, 0.000630429, with standard error 0.000162214
684 time to compute upper bound is, 500.622, seconds.
685 inverse floater
686 fixed strikes : 0.15
687 number rates : 20
688 training paths, 8192
689 paths, 8192
690 vega Paths, 1024
691 rate level 0.08
692 0.433923
693 0.442164
694 time to build strategy, 8.965, seconds.
695 time to price, 14.236, seconds.
696 vega output
697 factorwise bumping 0
698 doCaps 0
699 price estimate, 0.442292
700 Delta, 0, 0.45604, 0.0112208
701 Delta, 1, 0.501177, 0.0113876
º º º
717 Delta, 17, 0.328997, 0.00615947
718 Delta, 18, 0.307421, 0.00590508
719 Delta, 19, 0.282435, 0.00586653
720 vega, 0, -0.00156644 ,0
721 vega, 1, 0.000196311 ,0
722 vega, 2, 0.000387412 ,0
. . .
737 vega, 17, -0.000209636 ,0
738 vega, 18, -0.000103926 ,0
739 vega, 19, 3.50955e-05 ,0
740 total Vega, -0.00291991
741 vega output
742 factorwise bumping 1
743 doCaps 0
744 price estimate, 0.442292
745 Delta, 0, 0.45604, 0.0112208
746 Delta, 1, 0.501177, 0.0113876
747 Delta, 2, 0.505817, 0.0108376
. . .
762 Delta, 17, 0.328997, 0.00615947
763 Delta, 18, 0.307421, 0.00590508
764 Delta, 19, 0.282435, 0.00586653
765 vega, 0, -0.000389764 ,0
766 vega, 1, -0.000486551 ,0
767 vega, 2, -0.00033777 ,0
. . .
783 vega, 18, -6.41297e-06 ,0
784 vega, 19, 4.3125e-05 ,0
785 total Vega, -0.00371629
786 vega output
787 factorwise bumping 0
788 doCaps 1
789 price estimate, 0.442292
790 Delta, 0, 0.45604, 0.0112208
791 Delta, 1, 0.501177, 0.0113876
792 Delta, 2, 0.505817, 0.0108376
793 Delta, 3, 0.486482, 0.0101469
794 Delta, 4, 0.489724, 0.00984302
. . .
808 Delta, 18, 0.307421, 0.00590508
809 Delta, 19, 0.282435, 0.00586653
810 vega, 0, -0.000136359 ,0
811 vega, 1, -2.26742e-06 ,0
812 vega, 2, 0.000423245 ,0
813 vega, 3, 6.51835e-05 ,0
. . .
906 vega, 36, -0.000368676 ,0
907 vega, 37, -0.000358751 ,0
908 vega, 38, -0.000295147 ,0
909 total Vega, -0.00550073
910 Upper - lower is, 0.000319638, with standard error 0.00011468
911 time to compute upper bound is, 463.534, seconds.
912 inverse floater
913 fixed strikes : 0.15
914 number rates : 20
915 training paths, 8192
916 paths, 8192
917 vega Paths, 1024
918 rate level 0.09
919 0.511051
920 0.514768
921 time to build strategy, 8.733, seconds.
922 time to price, 13.125, seconds.
923 vega output
924 factorwise bumping 0
925 doCaps 0
926 price estimate, 0.513999
927 Delta, 0, 0.225733, 0.00389604
928 Delta, 1, 0.272344, 0.00641587
...
943 Delta, 16, 0.279605, 0.00472991
944 Delta, 17, 0.269411, 0.00451021
945 Delta, 18, 0.266124, 0.00436554
946 Delta, 19, 0.250533, 0.00429609
947 vega, 0, -0.000353236 ,0
948 vega, 1, -0.000454379 ,0
949 vega, 2, 4.25786e-05 ,0
950 vega, 3, 0.000253304 ,0
951 vega, 4, -0.000593775 ,0
......
963 vega, 16, 0.000144084 ,0
964 vega, 17, -0.000300143 ,0
965 vega, 18, -0.000165131 ,0
966 vega, 19, 2.59897e-05 ,0
967 total Vega, -0.00318385
968 vega output
969 factorwise bumping 1
970 doCaps 0
971 price estimate, 0.513999
972 Delta, 0, 0.225733, 0.00389604
973 Delta, 1, 0.272344, 0.00641587
974 Delta, 2, 0.297184, 0.00706936
. . .
985 Delta, 13, 0.302714, 0.00521743
986 Delta, 14, 0.297283, 0.00503659
987 Delta, 15, 0.291272, 0.00486343
988 Delta, 16, 0.279605, 0.00472991
989 Delta, 17, 0.269411, 0.00451021
990 Delta, 18, 0.266124, 0.00436554
991 Delta, 19, 0.250533, 0.00429609
992 vega, 0, 7.43209e-06 ,0
993 vega, 1, -0.000408263 ,0
......
1010 vega, 18, -8.95679e-05 ,0
1011 vega, 19, 1.95846e-05 ,0
1012 total Vega, -0.00393333
1013 vega output
1014 factorwise bumping 0
1015 doCaps 1
1016 price estimate, 0.513999
1017 Delta, 0, 0.225733, 0.00389604
1018 Delta, 1, 0.272344, 0.00641587
1019 Delta, 2, 0.297184, 0.00706936
.......
1070 vega, 33, -0.000386055 ,0
1071 vega, 34, -0.000352769 ,0
1072 total Vega, -0.00513803
1073 vega output
1074 factorwise bumping 1
1075 doCaps 1
1076 price estimate, 0.513999
1077 Delta, 0, 0.225733, 0.00389604
1078 Delta, 1, 0.272344, 0.00641587
1079 Delta, 2, 0.297184, 0.00706936
1080 Delta, 3, 0.316197, 0.00729195
1081 Delta, 4, 0.33118, 0.007482
.......
1094 Delta, 17, 0.269411, 0.00451021
1095 Delta, 18, 0.266124, 0.00436554
1096 Delta, 19, 0.250533, 0.00429609
1097 vega, 0, 0.00010051 ,0
1098 vega, 1, -8.30964e-05 ,0
1099 vega, 2, -9.97606e-06 ,0
1100 vega, 3, -5.65519e-05 ,0
.......
1133 vega, 36, -0.000393401 ,0
1134 vega, 37, -0.000345943 ,0
1135 vega, 38, -0.00034315 ,0
1136 total Vega, -0.00526595
1137 Upper - lower is, 0.000174615, with standard error 7.04341e-05
1138 time to compute upper bound is, 498.8, seconds.
1139
1140 Begin Time: 2023-Sep-26 09:54:32.243000
1141 End Time: 2023-Sep-26 10:38:15.094000
1142 Elapsed Time(seconds): 2622
1143 Elapsed Time(mili seconds): 2622851
1144 QuantLib version: 1.31.1
1145 Boost version: 1.83.0
1146 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
1147 Exit quantLib test
MulticurveBootstrapping
1 Begin Time: 2023-Sep-26 07:50:00.027000 QuantLib version: 1.31.1
2
3 MulticurveBootstrapping.cpp
4
5 Today: Tuesday, December 11th, 2012
6 Settlement date: Thursday, December 13th, 2012
7 ===============================================================================================
8 With 5-year market swap-rate = 0.76 %
9 -----------------------------------------------------------------------------------------------
10 | net present value | fair spread | fair fixed rate
11 -----------------------------------------------------------------------------------------------
12 5-years swap paying 0.70 % | 3076.03 | -0.06 % | 0.76 %
13 -----------------------------------------------------------------------------------------------
14 5-years, 1-year forward swap paying 0.70 % | 19202.89 | -0.38 % | 1.09 %
15 ===============================================================================================
16 With 5-year market swap-rate = 0.90 %
17 -----------------------------------------------------------------------------------------------
18 | net present value | fair spread | fair fixed rate
19 -----------------------------------------------------------------------------------------------
20 5-years swap paying 0.70 % | 9922.67 | -0.20 % | 0.90 %
21 -----------------------------------------------------------------------------------------------
22 5-years, 1-year forward swap paying 0.70 % | 19202.89 | -0.38 % | 1.09 %
23 ===============================================================================================
24
25 Begin Time: 2023-Sep-26 07:50:00.027000
26 End Time: 2023-Sep-26 07:50:15.781000
27 Elapsed Time(seconds): 15
28 Elapsed Time(mili seconds): 15754
29 QuantLib version: 1.31.1
30 Boost version: 1.83.0
31 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
32 Exit quantLib test
33
34
35 ///-----------
36 Build started...
37 1>------ Build started: Project: ExSan, Configuration: Debug x64 ------
38 1>ExSan.cpp
39 1>C:...\Tools\MSVC\14.37.32822\include\stdfloat(13): warning STL4038:
40 The contents of are available only with C++23 or later.
44 1>.. ExSan\x64\Debug\ExSan.exe
45 1>Done building project "ExSan.vcxproj".
46 ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
47 ========== Build started at 7:49 and took 32,884 seconds ==========
MultidimIntegral
1 Begin Time: 2023-Sep-26 06:53:58.554000 QuantLib version: 1.31.1
2
3 MultidimIntegral.cpp
4
5
6 --------------
7 Exact: 2.6303
8 Quad: 2.6303
9 Grid: 2.6303
10
11
12 Begin Time: 2023-Sep-26 06:53:58.554000
13 End Time: 2023-Sep-26 06:53:58.608000
14 Elapsed Time(seconds): 0
15 Elapsed Time(mili seconds): 54
16 QuantLib version: 1.31.1
17 Using Boost 1.83.0
18 Microsoft Visual Studio Community 2022 (64 - bit) - Version 17.7.4 -
19 Exit quantLib test
Replication
1
2 Begin Time: 2023-Sep-26 06:40:21.889000
3 QuantLib version: 1.31.1
4
5 Replication.cpp
6
7 ===========================================================================
8 Initial market conditions
9 ===========================================================================
10 Option NPV Error
11 ---------------------------------------------------------------------------
12 Original barrier option 4.260726 N/A
13 Replicating portfolio (12 dates) 4.322358 0.061632
14 Replicating portfolio (26 dates) 4.295464 0.034738
15 Replicating portfolio (52 dates) 4.280909 0.020183
16 ===========================================================================
17 Modified market conditions: out of the money
18 ===========================================================================
19 Option NPV Error
20 ---------------------------------------------------------------------------
21 Original barrier option 2.513058 N/A
22 Replicating portfolio (12 dates) 2.539365 0.026307
23 Replicating portfolio (26 dates) 2.528362 0.015304
24 Replicating portfolio (52 dates) 2.522105 0.009047
25 ===========================================================================
26 Modified market conditions: in the money
27 ===========================================================================
28 Option NPV Error
29 ---------------------------------------------------------------------------
30 Original barrier option 5.739125 N/A
31 Replicating portfolio (12 dates) 5.851239 0.112114
32 Replicating portfolio (26 dates) 5.799867 0.060742
33 Replicating portfolio (52 dates) 5.773678 0.034553
34 ===========================================================================
35
36 The replication seems to be less robust when volatility and
37 risk-free rate are changed. Feel free to experiment with
38 the example and contribute a patch if you spot any errors.
39
40 Begin Time: 2023-Sep-26 06:40:21.889000
41 End Time: 2023-Sep-26 06:40:22.138000
42 Elapsed Time(seconds): 0
43 Elapsed Time(mili seconds): 249
44 QuantLib version: 1.31.1
45 Using Boost 1.83.0
46 Microsoft Visual Studio Community 2022 (64 - bit) - Current Version 17.7.4
47 Exit quantLib test
Repo
1 September 26th, 2023
2
3 Begin Time: 2023-Sep-26 06:12:00.159000
4 QuantLib version: 1.31.1
5
6 Repo.cpp
7
8 Underlying bond clean price: 89.9769
9 Underlying bond dirty price: 93.288
10 Underlying bond accrued at settlement: 3.31111
11 Underlying bond accrued at delivery: 3.33333
12 Underlying bond spot income: 3.9834
13 Underlying bond fwd income: 4.08465
14 Repo strike: 91.5745
15 Repo NPV: -2.8066e-05
16 Repo clean forward price: 88.2411
17 Repo dirty forward price: 91.5745
18 Repo implied yield: 5.000063 % Actual/360 simple compounding
19 Market repo rate: 5.000000 % Actual/360 simple compounding
20
21 Compare with example given at
22 http://www.fincad.com/support/developerFunc/mathref/BFWD.htm
23 Clean forward price = 88.2408
24
25 In that example, it is unknown what bond calendar they are
26 using, as well as settlement Days. For that reason, I have
27 made the simplest possible assumptions here: NullCalendar
28 and 0 settlement days.
29
30 Begin Time: 2023-Sep-26 06:12:00.159000
31 End Time: 2023-Sep-26 06:12:00.165000
32 Elapsed Time(seconds): 0
33 Elapsed Time(mili seconds): 6
34 QuantLib version: 1.31.1
35 Using Boost 1.83.0
36 Exit quantLib test
Polulating ExSan with Market Data Tick by Tick
Previous
Back Testing Algorithmic Trading Modern Portfolio Simulator - Some Code
Next
+
+
C
E
x
S
a
n
C
+
+
D
o
N
o
t
A
c
c
e
p
t
D
e
f
a
u
l
t
s
T
h
i
n
k
D
i
f
f
e
r
e
n
t

Comments
Post a Comment