forked from jonnathan-romero/Options-Market-Making
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.cpp
More file actions
executable file
·145 lines (114 loc) · 3.61 KB
/
Options.cpp
File metadata and controls
executable file
·145 lines (114 loc) · 3.61 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
#include "Options.hpp"
#include <iostream>
#include <cmath>
Options::Options(double starting_price, double risk_free, double starting_time_left, double v)
{
this->risk_free_rate = risk_free;
this->update_everything(starting_price, starting_time_left, v);
}
double Options::BlackScholes(char CallPutFlag, double S, double X, double T, double r, double v)
{
double d1, d2;
double bs_price;
d1=(log(S/X)+(r+v*v/2)*T)/(v*sqrt(T));
d2=d1-v*sqrt(T);
if(CallPutFlag == 'c')
bs_price = S *CND(d1)-X * exp(-r*T)*CND(d2);
else if(CallPutFlag == 'p')
bs_price = X * exp(-r * T) * CND(-d2) - S * CND(-d1);
else
return 0;
if (bs_price <0.01)
{
return 0.01;
}
else
{
return bs_price;
}
}
double Options::CND( double X )
{
double L, K, w ;
double const a1 = 0.31938153, a2 = -0.356563782, a3 = 1.781477937;
double const a4 = -1.821255978, a5 = 1.330274429;
L = fabs(X);
K = 1.0 / (1.0 + 0.2316419 * L);
w = 1.0 - 1.0 / sqrt(2 * Pi) * exp(-L *L / 2) * (a1 * K + a2 * K *K + a3 * pow(K,3) + a4 * pow(K,4) + a5 * pow(K,5));
if (X < 0 ){
w= 1.0 - w;
}
return w;
}
double Options::get_option_price (char type, double strike_p, double time_left, double stock_price)
{
double interested_stock;
update_everything(stock_price, time_left , this->volatility);
if (type == 'c')
{
if (strike_p == 80)
{
interested_stock = pc80;
}
else if (strike_p ==90)
{
interested_stock = pc90;
}
else if (strike_p ==100)
{
interested_stock = pc100;
}
else if (strike_p ==110)
{
interested_stock = pc110;
}
else if (strike_p ==120)
{
interested_stock = pc120;
}
}else if (type == 'p')
{
if (strike_p == 80)
{
interested_stock = pp80;
}
else if (strike_p ==90)
{
interested_stock = pp90;
}
else if (strike_p ==100)
{
interested_stock = pp100;
}
else if (strike_p ==110)
{
interested_stock = pp110;
}
else if (strike_p ==120)
{
interested_stock = pp120;
}
}else{
}
return interested_stock;
}
void Options::update_volatility(double v)
{
this->volatility = v;
}
void Options::update_everything(double stock_price, double time_left, double v)
{
update_volatility(v);
price_now = stock_price;
time = time_left;
pc80=BlackScholes('c', stock_price, 80, time_left, this->risk_free_rate, this->volatility);
pp80=BlackScholes('p', stock_price, 80, time_left, this->risk_free_rate, this->volatility);
pc90=BlackScholes('c', stock_price, 90, time_left, this->risk_free_rate, this->volatility);
pp90=BlackScholes('p', stock_price, 90, time_left, this->risk_free_rate, this->volatility);
pc100=BlackScholes('c', stock_price, 100, time_left, this->risk_free_rate, this->volatility);
pp100=BlackScholes('p', stock_price, 100, time_left, this->risk_free_rate, this->volatility);
pc110=BlackScholes('c', stock_price, 110, time_left, this->risk_free_rate, this->volatility);
pp110=BlackScholes('p', stock_price, 110, time_left, this->risk_free_rate, this->volatility);
pc120=BlackScholes('c', stock_price, 120, time_left, this->risk_free_rate, this->volatility);
pp120=BlackScholes('p', stock_price, 120, time_left, this->risk_free_rate, this->volatility);
}