simulated_delta_call.cc

来自「Financial Recipes」· CC 代码 · 共 28 行

CC
28
字号
#include <cmath>     // standard mathematical functions#include <algorithm>   // define the max() functionusing namespace std;#include "normdist.h"   // definition of random number generatordouble option_price_delta_call_european_simulated(const double& S, 						  const double& X, 						  const double& r,						  const double& sigma, 						  const double& time,						  const int& no_sims){    double R = (r - 0.5 * pow(sigma,2))*time;    double SD = sigma * sqrt(time);    double sum_payoffs = 0.0;    double sum_payoffs_q = 0.0;    double q = S*0.01;     for (int n=1; n<=no_sims; n++) {	double Z = random_normal();	double S_T  = S* exp(R + SD * Z);	sum_payoffs += max(0.0, S_T-X);	double S_T_q = (S+q)* exp(R + SD * Z);	sum_payoffs_q += max(0.0, S_T_q-X);    };    double c = exp(-r*time) * ( sum_payoffs/no_sims);     double c_q = exp(-r*time) * ( sum_payoffs_q/no_sims);     return (c_q-c)/q;};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?