<<C++ design patterns and Derivatives Pricing>> 学习系列 CH1-对蒙特卡洛基本理解

4 篇文章 0 订阅


前面的推导省略,该公式为期权定价公式


参数解释:

r:riskless 利率 ==r

T:期限 ==Expire

S0:起始spot price ==Spot

:Vol ==Vol

K:strike price即成交价 ==Strike


算法核心在于求期望,解决方法为多次计算f(S)并求其平均值来得到期望。 用变量x来表示每一次实验N(0,1)的取值,这里用到Box Muller算法(该算法根据标准正态分布产生随机数)。



附核心算法代码:

*******************************************主过程*****************************************

double SimpleMonteCarlo1(double Expiry,
double Strike,
double Spot,
double Vol,
double r,
unsigned long NumberOfPaths)
{
double variance = Vol*Vol*Expiry;
double rootVariance = sqrt(variance);
double itoCorrection = -0.5*variance;
double movedSpot = Spot*exp(r*Expiry +itoCorrection);
double thisSpot;
double runningSum=0;
for (unsigned long i=0; i < NumberOfPaths; i++)
{
double thisGaussian = GetOneGaussianByBoxMuller();
thisSpot = movedSpot*exp( rootVariance*thisGaussian);
double thisPayoff = thisSpot - Strike;
thisPayoff = thisPayoff >0 ? thisPayoff : 0;
runningSum += thisPayoff;
}
double mean = runningSum / NumberOfPaths;
mean *= exp(-r*Expiry);
return mean;
}


*******************************************Box Muller*********************************************

double GetOneGaussianByBoxMuller()
{
double result;
double x;
double y;
double sizeSquared;
do
{
x = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
y = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
sizeSquared = x*x + y*y;
}
while
( sizeSquared >= 1.0);
result = x*sqrt(-2*log(sizeSquared)/sizeSquared);
return result;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Design patterns are the cutting-edge paradigm for programming in object-oriented languages. Here they are discussed, for the first time in a book, in the context of implementing financial models in C++. Assuming only a basic knowledge of C++ and mathematical finance, the reader is taught how to produce well-designed, structured, re-usable code via concrete examples. Each example is treated in depth, with the whys and wherefores of the chosen method of solution critically examined. Part of the book is devoted to designing re-usable components that are then put together to build a Monte Carlo pricer for path-dependent exotic options. Advanced topics treated include the factory pattern, the singleton pattern and the decorator pattern. Complete ANSI/ISO-compatible C++ source code is included on a CD for the reader to study and re-use and so develop the skills needed to implement financial models with object-oriented programs and become a working financial engineer. Please note the CD supplied with this book is platform-dependent and PC users will not be able to use the files without manual intervention in order to remove extraneous characters. Cambridge University Press apologises for this error. Machine readable files for all users can be obtained from www.markjoshi.com/design. ? First book on implementing financial models using object-oriented C++, with plenty of examples taken from finance ? Contains complete C++ source code which is ANSI/ISO compatible ? Comes with CD containing all the code

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值