-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.cpp
More file actions
180 lines (174 loc) · 12.1 KB
/
Copy pathplot.cpp
File metadata and controls
180 lines (174 loc) · 12.1 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "plot.h"
void Plot_GBM::set_values(SolvingType RES, Method MTD, double &S, double &K, double &r, double &sigma, double &T, int &M, double &d_S){
switch (RES){
case MC:
switch (MTD) {
case Direct:
switch(m_X_type){
case Spot:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::MC::Direct::call_price(X, K, r, sigma, T, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::MC::Direct::call_delta(X, K, r, sigma, T, M, d_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::MC::Direct::call_gamma(X, K, r, sigma, T, M, d_S)[0]));
m_pts_vega.push_back(std::make_pair(X, GBM::MC::Direct::call_vega(X, K, r, sigma, T, M, d_S)[0]));
}
break;
case Volatility:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::MC::Direct::call_price(S, K, r, X, T, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::MC::Direct::call_delta(S, K, r, X, T, M, d_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::MC::Direct::call_gamma(S, K, r, X, T, M, d_S)[0]));
m_pts_vega.push_back(std::make_pair(X, GBM::MC::Direct::call_vega(S, K, r, X, T, M, d_S)[0]));
}
break;
case Maturity:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::MC::Direct::call_price(S, K, r, sigma, X, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::MC::Direct::call_delta(S, K, r, sigma, X, M, d_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::MC::Direct::call_gamma(S, K, r, sigma, X, M, d_S)[0]));
m_pts_vega.push_back(std::make_pair(X, GBM::MC::Direct::call_vega(S, K, r, sigma, X, M, d_S)[0]));
}
break;
default:
std::cout<< "X_axis not implemented" << std::endl;
}
break;
case Antithetic:
switch(m_X_type){
case Spot:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::MC::Antithetic::call_price(X, K, r, sigma, T, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::MC::Antithetic::call_delta(X, K, r, sigma, T, M, d_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::MC::Antithetic::call_gamma(X, K, r, sigma, T, M, d_S)[0]));
m_pts_vega.push_back(std::make_pair(X, GBM::MC::Antithetic::call_vega(X, K, r, sigma, T, M, d_S)[0]));
}
break;
case Volatility:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::MC::Antithetic::call_price(S, K, r, X, T, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::MC::Antithetic::call_delta(S, K, r, X, T, M, d_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::MC::Antithetic::call_gamma(S, K, r, X, T, M, d_S)[0]));
m_pts_vega.push_back(std::make_pair(X, GBM::MC::Antithetic::call_vega(S, K, r, X, T, M, d_S)[0]));
}
break;
case Maturity:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::MC::Antithetic::call_price(S, K, r, sigma, X, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::MC::Antithetic::call_delta(S, K, r, sigma, X, M, d_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::MC::Antithetic::call_gamma(S, K, r, sigma, X, M, d_S)[0]));
m_pts_vega.push_back(std::make_pair(X, GBM::MC::Antithetic::call_vega(S, K, r, sigma, X, M, d_S)[0]));
}
break;
default:
std::cout<< "X_axis not implemented" << std::endl;
}
break;
default:
std::cout<< "Monte-Carlo Reduction Variance Method not defined for plotting" << std::endl;
}
case Analytic:
switch(m_X_type){
case Spot:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::Analytic::call_price(X, K, r, sigma, T)));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::Analytic::call_delta(X, K, r, sigma, T)));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::Analytic::call_gamma(X, K, r, sigma, T)));
m_pts_vega.push_back(std::make_pair(X, GBM::Analytic::call_vega(X, K, r, sigma, T)));
}
break;
case Volatility:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::Analytic::call_price(S, K, r, X, T)));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::Analytic::call_delta(S, K, r, X, T)));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::Analytic::call_gamma(S, K, r, X, T)));
m_pts_vega.push_back(std::make_pair(X, GBM::Analytic::call_vega(S, K, r, X, T)));
}
break;
case Maturity:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, GBM::Analytic::call_price(S, K, r, sigma, X)));
m_pts_delta.push_back(std::make_pair(X, 100*GBM::Analytic::call_delta(S, K, r, sigma, X)));
m_pts_gamma.push_back(std::make_pair(X, 5000*GBM::Analytic::call_gamma(S, K, r, sigma, X)));
m_pts_vega.push_back(std::make_pair(X, GBM::Analytic::call_vega(S, K, r, sigma, X)));
}
break;
default:
std::cout<< "X_axis not implemented" << std::endl;
}
break;
default:
std::cout<< "SolvingType not defined for plotting" << std::endl;
}
}
void Plot_GBM::show(){
Gnuplot gp;
gp << boost::format("set xrange [%1%:%2%]\nset yrange [0:100]\n") % m_X_min % m_X_max;
gp << "plot" << gp.file1d(m_pts_price) << "with points title 'GBM-Price'," <<
gp.file1d(m_pts_delta) << "with points title 'GBM-Delta'," <<
gp.file1d(m_pts_gamma) << "with points title 'GBM-Gamma'," <<
gp.file1d(m_pts_vega) << "with points title 'GBM-Vega'," << std::endl;
}
void Plot_Heston::set_values(SolvingType RES, Method MTD, double &S, double &K, double &r, double &kappa,
double &theta, double &sigma, double &rho, double &T, int &M, double &delta_S, double &delta_sigma){
switch (RES){
case MC:
switch (MTD) {
case Direct:
switch(m_X_type){
case Spot:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, Heston::MC::Direct::call_price(X, K, r, kappa, theta, sigma, rho, T, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*Heston::MC::Direct::call_delta(X, K, r, kappa, theta, sigma, rho, T, M, delta_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*Heston::MC::Direct::call_gamma(X, K, r, kappa, theta, sigma, rho, T, M, delta_S)[0]));
m_pts_vega.push_back(std::make_pair(X, Heston::MC::Direct::call_vega(X, K, r, kappa, theta, sigma, rho, T, M, delta_sigma)[0]));
}
break;
case Maturity:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, Heston::MC::Direct::call_price(S, K, r, kappa, theta, sigma, rho, X, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*Heston::MC::Direct::call_delta(S, K, r, kappa, theta, sigma, rho, X, M, delta_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*Heston::MC::Direct::call_gamma(S, K, r, kappa, theta, sigma, rho, X, M, delta_S)[0]));
m_pts_vega.push_back(std::make_pair(X, Heston::MC::Direct::call_vega(S, K, r, kappa, theta, sigma, rho, X, M, delta_sigma)[0]));
}
break;
default:
std::cout<< "X_axis not implemented" << std::endl;
}
break;
case Antithetic:
switch(m_X_type){
case Spot:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, Heston::MC::Antithetic::call_price(X, K, r, kappa, theta, sigma, rho, T, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*Heston::MC::Antithetic::call_delta(X, K, r, kappa, theta, sigma, rho, T, M, delta_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*Heston::MC::Antithetic::call_gamma(X, K, r, kappa, theta, sigma, rho, T, M, delta_S)[0]));
m_pts_vega.push_back(std::make_pair(X, Heston::MC::Antithetic::call_vega(X, K, r, kappa, theta, sigma, rho, T, M, delta_sigma)[0]));
}
break;
case Maturity:
for (double X = m_X_min; X < m_X_max; X += (m_X_max - m_X_min) / m_N) {
m_pts_price.push_back(std::make_pair(X, Heston::MC::Direct::call_price(S, K, r, kappa, theta, sigma, rho, X, M)[0]));
m_pts_delta.push_back(std::make_pair(X, 100*Heston::MC::Direct::call_delta(S, K, r, kappa, theta, sigma, rho, X, M, delta_S)[0]));
m_pts_gamma.push_back(std::make_pair(X, 5000*Heston::MC::Direct::call_gamma(S, K, r, kappa, theta, sigma, rho, X, M, delta_S)[0]));
m_pts_vega.push_back(std::make_pair(X, Heston::MC::Direct::call_vega(S, K, r, kappa, theta, sigma, rho, X, M, delta_sigma)[0]));
}
break;
default:
std::cout<< "X_axis not implemented" << std::endl;
}
break;
default:
std::cout<< "Monte-Carlo Reduction Variance Method not defined for plotting" << std::endl;
}
default:
std::cout<< "SolvingType not defined for plotting" << std::endl;
}
}
void Plot_Heston::show(){
Gnuplot gp;
gp << boost::format("set xrange [%1%:%2%]\nset yrange [0:100]\n") % m_X_min % m_X_max;
gp << "plot" << gp.file1d(m_pts_price) << "with points title 'Heston-Price'," <<
gp.file1d(m_pts_delta) << "with points title 'Heston-Delta'," <<
gp.file1d(m_pts_gamma) << "with points title 'Heston-Gamma'," <<
gp.file1d(m_pts_vega) << "with points title 'Heston-Vega'," << std::endl;
}