@@ -18,12 +18,17 @@ pub fn npv(bsd_option: &&EquityOption) -> f64 {
18
18
assert ! ( bsd_option. time_to_maturity( ) >= 0.0 ) ;
19
19
assert ! ( bsd_option. underlying_price. value >= 0.0 ) ;
20
20
if bsd_option. option_type == OptionType :: Call {
21
+
21
22
let option_price = bsd_option. underlying_price . value ( )
22
23
* N ( bsd_option. d1 ( ) )
23
24
* exp ( -bsd_option. dividend_yield * bsd_option. time_to_maturity ( ) )
24
25
- bsd_option. strike_price
25
26
* exp ( -bsd_option. risk_free_rate * bsd_option. time_to_maturity ( ) )
26
27
* N ( bsd_option. d2 ( ) ) ;
28
+ let a = N ( bsd_option. d1 ( ) ) ;
29
+ let b = N ( bsd_option. d2 ( ) ) ;
30
+ println ! ( "a = {:?} b = {:?}" , a, b) ;
31
+ println ! ( "{:?}" , bsd_option) ;
27
32
return option_price;
28
33
} else {
29
34
let option_price = -bsd_option. underlying_price . value ( )
@@ -152,6 +157,7 @@ impl EquityOption {
152
157
}
153
158
pub fn option_pricing ( ) {
154
159
println ! ( "Welcome to the Black-Scholes Option pricer." ) ;
160
+ print ! ( ">>" ) ;
155
161
println ! ( " What is the current price of the underlying asset?" ) ;
156
162
print ! ( ">>" ) ;
157
163
let mut curr_price = String :: new ( ) ;
@@ -199,6 +205,7 @@ pub fn option_pricing() {
199
205
println ! ( "{:?}" , expiry. trim( ) ) ;
200
206
let _d = expiry. trim ( ) ;
201
207
let future_date = NaiveDate :: parse_from_str ( & _d, "%Y-%m-%d" ) . expect ( "Invalid date format" ) ;
208
+ //println!("{:?}", future_date);
202
209
println ! ( "Dividend yield on this stock:" ) ;
203
210
print ! ( ">>" ) ;
204
211
let mut div = String :: new ( ) ;
@@ -211,7 +218,7 @@ pub fn option_pricing() {
211
218
// rates: vec![0.01,0.02,0.05,0.07,0.08,0.1,0.11,0.12]
212
219
//};
213
220
let date = vec ! [ 0.01 , 0.02 , 0.05 , 0.1 , 0.5 , 1.0 , 2.0 , 3.0 ] ;
214
- let rates = vec ! [ 0.05 , 0.05 , 0.06 , 0.07 , 0.08 , 0.9 , 0.9 , 0.10 ] ;
221
+ let rates = vec ! [ 0.05 , 0.05 , 0.05 , 0.05 , 0.05 , 0.05 , 0.05 , 0.05 ] ;
215
222
let ts = YieldTermStructure :: new ( date, rates) ;
216
223
let curr_quote = Quote :: new ( curr_price. trim ( ) . parse :: < f64 > ( ) . unwrap ( ) ) ;
217
224
let mut option = EquityOption {
@@ -231,17 +238,18 @@ pub fn option_pricing() {
231
238
style : ContractStyle :: European ,
232
239
valuation_date : Local :: today ( ) . naive_local ( ) ,
233
240
} ;
241
+ println ! ( "{:?}" , option. time_to_maturity( ) ) ;
234
242
option. set_risk_free_rate ( ) ;
235
243
println ! ( "Theoretical Price ${}" , option. npv( ) ) ;
236
244
println ! ( "Premium at risk ${}" , option. get_premium_at_risk( ) ) ;
237
- println ! ( "Delata {}" , option. delta( ) ) ;
245
+ println ! ( "Delta {}" , option. delta( ) ) ;
238
246
println ! ( "Gamma {}" , option. gamma( ) ) ;
239
247
println ! ( "Vega {}" , option. vega( ) * 0.01 ) ;
240
248
println ! ( "Theta {}" , option. theta( ) * ( 1.0 / 365.0 ) ) ;
241
249
println ! ( "Rho {}" , option. rho( ) * 0.01 ) ;
242
- let mut div1 = String :: new ( ) ;
250
+ let mut wait = String :: new ( ) ;
243
251
io:: stdin ( )
244
- . read_line ( & mut div )
252
+ . read_line ( & mut wait )
245
253
. expect ( "Failed to read line" ) ;
246
254
}
247
255
pub fn implied_volatility ( ) {
0 commit comments