Basket Call Option via C++
来源:互联网 发布:网络预约挂号 编辑:程序博客网 时间:2024/05/18 01:47
Two stocks, with correlation rho, European type, payoff is Max(S1-S2, 0). First, Box-Muller algorithm,
#ifndef BM_GAUSSIAN_HPP_INCLUDED#define BM_GAUSSIAN_HPP_INCLUDED#include <cstdlib>#include <cmath>#include <vector>double uniformRandom(){ return (double)(rand()+1.0)/(double)(RAND_MAX+1.0);}void normalRandom(std::vector<double>& v){ double u1=uniformRandom(); double u2=uniformRandom(); v[0] = cos(8.0*atan(1.0)*u2)*sqrt(-2.0*log(u1)); v[1] = sin(8.0*atan(1.0)*u1)*sqrt(-2.0*log(u2));}#endif // BM_GAUSSIAN_HPP_INCLUDED
main function
#include <iostream>#include <cstdlib>#include <cmath>#include <vector>#include <./BM_Gaussian.hpp>using namespace std;int main(){ // set option contract parameters; double T = 1.0; double r = 0.01; // stock parameters; double S_10 = 100; double sigma_1 = 0.1; double S_20 = 105; double sigma_2 = 0.05; double rho = -0.8; // monte carlo parameters int npaths = 100000; int nsteps = 100; double S1, S2, r1, r2; vector<double> rnorm(2); double sumpayoff = 0.0; double dt = double(T)/double(nsteps); for (int i=0; i<npaths; i++){ S1 = S_10; S2 = S_20; for (int j=0; j<nsteps; j++){ normalRandom(rnorm); r1 = rnorm[0]; r2 = rnorm[0]*rho + rnorm[1]*sqrt(1-rho*rho); S1 *= exp((r-0.5*sigma_1*sigma_1)*dt + sigma_1*sqrt(dt)*r1); S2 *= exp((r-0.5*sigma_2*sigma_2)*dt + sigma_2*sqrt(dt)*r2); } sumpayoff += max(r1-r2, 0.0); } double callprice = double(sumpayoff)/double(npaths); cout << "Call Price: " << callprice << endl; return 0;}Correlation will affect the call price. To the extreme, if rho=1, stocks move together, the gap could be small, call price will be low. Negative rho generates high call price.
0 0
- Basket Call Option via C++
- Vanilla Option Pricing via C++
- 《CLR Via C#》
- windows via c/c++
- Windows via c/c++
- CLR via c#------Introduction
- Windows Via C/C++
- American Option Pricing via Longstaff and Schwartz (2001)
- C/C++ Projcet Option
- 【C#】22. Option类型
- CLR Via C#:Second Edition
- 《windows via C++》之精华
- CLR via C#: 关于equals
- windows via c/c++ 读书笔记
- 框架结构(CLR Via C#)读书笔记
- Windows Via C/C++ 读书笔记
- ETF creation basket VS calculation basket
- VIA
- 百度地图开发之【公交信息检索】
- 数字在排序数组中出现的次数
- 装饰模式(Decorator)
- 系统出错, 发生系统错误 1067, 进程意外终止. 解决方法
- ubunutu 更改grub等待时间
- Basket Call Option via C++
- 浅谈JAVA设计模式之——适配器模式(Adapter)
- 创建自定义 AngularJS 指令:Part 5 link
- 组合模式(Composite)
- 《unix环境高级编程》-09、进程关系-读书笔记
- 面试题53:正则表达式匹配
- ios编译出错,codesign:invaild option --o
- 折腾AMAZON EC2 之(1) —— 安装apache(零初始环境)/ nginx
- 创建自定义 AngularJS 指令:Part 6 使用controllers