-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.cpp
More file actions
28 lines (22 loc) · 912 Bytes
/
option.cpp
File metadata and controls
28 lines (22 loc) · 912 Bytes
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
#include "option.h"
#include "include.h"
#include "util.h"
void Option::calc_d1() {
d1 = log(current_asset_price / strike_price) + (risk_free_intrest + std::pow(volatility, 2) / 2) * time_to_maturity;
d1 = d1 / volatility * std::sqrt(time_to_maturity);
}
void Option::calc_d2() {
d2 = d1 - volatility * std::sqrt(time_to_maturity);
}
void Option::calc_call_price() {
call_price = current_asset_price * util::normalCDF(d1) - strike_price * std::exp(-risk_free_intrest * time_to_maturity) * util::normalCDF(d2);
if (call_price < 0) call_price = 0;
}
void Option::calc_put_price() {
put_price = strike_price * std::exp(-risk_free_intrest * time_to_maturity) * util::normalCDF(-d2) - current_asset_price * util::normalCDF(-d1);
if (put_price < 0) put_price = 0;
}
void Option::normalize_prices() {
call_price = std::ceil(call_price * 100.0) / 100.0;
put_price = std::ceil(put_price * 100.0) / 100.0;
}