Skip to content

Commit 571c0c3

Browse files
committed
fixed a bug on gamma
1 parent 703383a commit 571c0c3

File tree

3 files changed

+114
-30
lines changed

3 files changed

+114
-30
lines changed

Cargo.lock

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/equity/blackscholes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl BlackScholesPricer {
6161
}
6262
}
6363
fn npv_vanilla(&self, bsd_option: &EquityOption) -> f64 {
64+
6465
let n_d1 = N(bsd_option.base.d1());
6566
let n_d2 = N(bsd_option.base.d2());
6667
let df_d = exp(-bsd_option.base.dividend_yield * bsd_option.time_to_maturity());
@@ -94,13 +95,13 @@ impl BlackScholesPricer {
9495
let df_r = exp(-bsd_option.base.risk_free_rate * bsd_option.time_to_maturity());
9596
let num = dn_d1*(df_r/df_d);
9697
let var_sqrt = bsd_option.base.volatility * (bsd_option.time_to_maturity().sqrt());
97-
return num/ (bsd_option.base.current_price.value() * var_sqrt);
98+
return num/ (bsd_option.base.underlying_price.value() * var_sqrt);
9899
}
99100
fn vega_vanilla(&self, bsd_option: &EquityOption) -> f64 {
100101
let dn_d1 = dN(bsd_option.base.d1());
101102
let df_d = exp(-bsd_option.base.dividend_yield * bsd_option.time_to_maturity());
102103
let df_r = exp(-bsd_option.base.risk_free_rate * bsd_option.time_to_maturity());
103-
let df_S = bsd_option.base.current_price.value()*df_r/df_d;
104+
let df_S = bsd_option.base.underlying_price.value()*df_r/df_d;
104105
let vega = df_S * dn_d1 * bsd_option.time_to_maturity().sqrt();
105106
return vega;
106107
}
@@ -112,7 +113,7 @@ impl BlackScholesPricer {
112113
let n_d2 = N(bsd_option.base.d2());
113114
let df_d = exp(-bsd_option.base.dividend_yield * bsd_option.time_to_maturity());
114115
let df_r = exp(-bsd_option.base.risk_free_rate * bsd_option.time_to_maturity());
115-
let df_S = bsd_option.base.current_price.value()*df_r/df_d;
116+
let df_S = bsd_option.base.underlying_price.value()*df_r/df_d;
116117
let t1 = -df_S*dn_d1 * bsd_option.base.volatility
117118
/ (2.0 * bsd_option.time_to_maturity().sqrt());
118119

src/examples/EQ/equity_option.json

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
{"contracts" : [
22
{
3-
"action":"PV",
4-
"pricer":"Analytical",
5-
"asset":"EQ",
6-
"payoff_type": "Vanilla",
7-
"market_data":{
8-
"underlying_price":100,
9-
"option_type":"C",
10-
"strike_price":100,
11-
"volatility":0.4,
12-
"risk_free_rate":0.06,
13-
"maturity":"2023-12-31",
14-
"dividend": 0.01
15-
}
3+
"action":"PV",
4+
"pricer":"Analytical",
5+
"asset":"EQ",
6+
"payoff_type": "Vanilla",
7+
"market_data":{
8+
"underlying_price":100,
9+
"option_type":"C",
10+
"strike_price":100,
11+
"volatility":0.4,
12+
"risk_free_rate":0.06,
13+
"maturity":"2025-03-31",
14+
"dividend": 0.01
15+
}
1616
},
17-
{
18-
"action":"PV",
19-
"pricer":"MonteCarlo",
20-
"asset":"EQ",
21-
"market_data":{
22-
"underlying_price":100,
23-
"option_type":"C",
24-
"strike_price":105,
25-
"volatility":0.45,
26-
"risk_free_rate":0.06,
27-
"maturity":"2023-12-31",
28-
"dividend": 0.01,
29-
"simulation":100000
30-
}}
17+
{
18+
"action":"PV",
19+
"pricer":"Analytical",
20+
"asset":"EQ",
21+
"payoff_type": "Vanilla",
22+
"market_data":{
23+
"underlying_price":100,
24+
"option_type":"P",
25+
"strike_price":100,
26+
"volatility":0.4,
27+
"risk_free_rate":0.06,
28+
"maturity":"2025-03-31",
29+
"dividend": 0.01
30+
}
31+
}
3132
]
3233
}

0 commit comments

Comments
 (0)