📄 bin_eur_call_ud.cc
字号:
#include <cmath> // standard mathematical library#include <algorithm> // defining the max() operator#include <vector> // STL vector templates#include <iostream>using namespace std;double option_price_call_european_binomial( double S, // spot price double X, // exercice price double r, // interest rate (per period) double u, // up movement double d, // down movement int no_periods){ // no steps in binomial tree double Rinv = exp(-r); // inverse of interest rate double uu = u*u; double p_up = (exp(r)-d)/(u-d); double p_down = 1.0-p_up; vector<double> prices(no_periods+1); // price of underlying prices[0] = S*pow(d, no_periods); // fill in the endnodes. for (int i=1; i<=no_periods; ++i) prices[i] = uu*prices[i-1]; vector<double> call_values(no_periods+1); // value of corresponding call for (int i=0; i<=no_periods; ++i) call_values[i] = max(0.0, (prices[i]-X)); // call payoffs at maturity for (int step=no_periods-1; step>=0; --step) { for (int i=0; i<=step; ++i) { call_values[i] = (p_up*call_values[i+1]+p_down*call_values[i])*Rinv; }; }; return call_values[0];};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -