📄 tst_black_scholes_extensions.cc
字号:
#include <vector>/*void test_european_dividends(){ cout << "Testing european BS with dividends" << endl; double S = 100.0; double X = 100.0; double r = 0.1; double sigma = 0.25; double time=1.0; vector<double> dividend_times; dividend_times.push_back(0.5); vector<double> dividend_amounts; dividend_amounts.push_back(5.0); cout << " call prices: " << endl; cout << " european " << " call = " << calc_black_scholes_call_price_with_dividend( S,X,r,sigma,time, dividend_times, dividend_amounts) << " put= " << calc_black_scholes_put_price_with_dividend( S,X,r,sigma,time, dividend_times, dividend_amounts) << endl; dividend_times[0]=0.25; dividend_times.push_back(0.75); dividend_amounts[0]=2.5; dividend_amounts.push_back(2.5); cout << " call prices: " << endl; cout << " european " << " call = " << calc_black_scholes_call_price_with_dividend( S,X,r,sigma,time, dividend_times, dividend_amounts) << " put= " << calc_black_scholes_put_price_with_dividend( S,X,r,sigma,time, dividend_times, dividend_amounts) << endl;}void test_analytical_american_call() { cout << " testing roll-geske-whaley " << endl; double S = 100.0; double X = 100.0; double r = 0.1; double sigma = 0.25; double tau = 1.0; double tau1 = 0.5; double D1 = 10.0; cout << " call price " << calc_american_call_w_div_roll_geske_whaley( S,X,r,sigma,tau,D1, tau1) << endl; cout << " testing roll-geske-whaley " << endl; S = 50.0; X = 45.0; r = 0.06; sigma = sqrt(0.2); tau = 3.0/12.0; tau1 = 1.0/12.0; D1 = 1.0; vector<double> dividend_times; dividend_times.push_back(tau1); vector<double> dividend_amounts; dividend_amounts.push_back(D1); cout << " BS " << calc_black_scholes_call_price(S,X,r,sigma,tau) << endl; cout << " BS div " << calc_black_scholes_call_price((S-exp(-r*tau1)),X,r,sigma,tau) << endl; cout << " BS div at tau1 " << calc_black_scholes_call_price(S,X,r,sigma,tau1) << endl; cout << " bin div " << calc_binomial_american_call_price_with_dividends( S,X,r,sigma,tau,200,dividend_times,dividend_amounts) << endl; cout << " call price " << calc_american_call_w_div_roll_geske_whaley( S,X,r,sigma,tau,D1, tau1) << endl;};*/void test_black_scholes_price_payout(){ cout << "Testing Black Scholes price with payouts " << endl; double spot = 100.0; double exercise = 100.0; double r = 0.1; double sigma = 0.25; double time_to_maturity=1.0; double b=0.05; cout << "continous payout 5% " << endl; cout << " call price: " << option_price_european_call_payout(spot,exercise,r,b,sigma, time_to_maturity) << endl; cout << " put price: " << option_price_european_put_payout(spot,exercise,r,b,sigma, time_to_maturity) << endl; cout << "discrete dividends, european options" << endl; vector<double> dividend_times; dividend_times.push_back(0.5); vector<double> dividend_amounts; dividend_amounts.push_back(2.0); cout << " call price: " << option_price_european_call_dividends(spot,exercise,r,sigma, time_to_maturity, dividend_times, dividend_amounts) << endl; cout << " put price: " << option_price_european_put_dividends(spot,exercise,r,sigma, time_to_maturity, dividend_times, dividend_amounts) << endl; cout << " American call, one dividend, exact solution " << endl; double D=2; double time_to_dividend=0.5; cout << " call price (D=2): " << option_price_american_call_dividend(spot,exercise,r,sigma, time_to_maturity, D,time_to_dividend) << endl; D=10; cout << " call price (D=10): " << option_price_american_call_dividend(spot,exercise,r,sigma, time_to_maturity, D,time_to_dividend) << endl;};void test_black_scholes_extensions(){ test_black_scholes_price_payout();};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -