📄 currency_opt_bin_call.cc
字号:
#include <cmath>#include <algorithm>#include <vector>using namespace std;double currency_option_price_call_american_binomial(double S, double X, double r, double r_f, double sigma, double time, int no_steps) { vector<double> exchange_rates(no_steps+1); vector<double> call_values(no_steps+1); double t_delta= time/no_steps; double Rinv = exp(-r*(t_delta)); double u = exp(sigma*sqrt(t_delta)); double d = 1.0/u; double uu= u*u; double pUp = (exp((r-r_f)*t_delta)-d)/(u-d); // adjust for foreign int.rate double pDown = 1.0 - pUp; exchange_rates[0] = S*pow(d, no_steps); int i; for (i=1; i<=no_steps; ++i) { exchange_rates[i] = uu*exchange_rates[i-1]; // terminal tree nodes } for (i=0; i<=no_steps; ++i) call_values[i] = max(0.0, (exchange_rates[i]-X)); for (int step=no_steps-1; step>=0; --step) { for (i=0; i<=step; ++i) { exchange_rates[i] = d*exchange_rates[i+1]; call_values[i] = (pDown*call_values[i]+pUp*call_values[i+1])*Rinv; call_values[i] = max(call_values[i], exchange_rates[i]-X); // check for exercise }; }; return call_values[0];};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -