⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcsimple.h

📁 蒙特卡罗期权定价 布朗桥方法 分层样本方法
💻 H
字号:
//
//
//
//                mcsimple.h/.cpp
//
//

#define mcsimple_H

#include <Vanilla3.h>
#include <Parameters.h>
#include <Random2.h>
#include <MCStatistics.h>
#include <cmath>
#include <Arrays.h>

void SimpleMonteCarlo6(const VanillaOption& TheOption, 
						 double Spot,
						 const Parameters& Vol, 
						 double r,
						 double d,
                         unsigned long NumberOfPaths,
						 StatisticsMC& gatherer,
                         RandomBase& generator);



//
//
//                  
//                         
//



// the basic math functions should be in namespace std but aren't in VCPP6
#if !defined(_MSC_VER)
using namespace std;
#endif

void SimpleMonteCarlo(const VanillaOption& TheOption, 
						 double Spot, 
						 const Parameters& Vol, 
						 double r, 
						 double d,
                         unsigned long NumberOfPaths,
						 StatisticsMC& gatherer,
                         RandomBase& generator)
{
    generator.ResetDimensionality(1);

    double Expiry = TheOption.GetExpiry();
	double variance = Vol.IntegralSquare(0,Expiry);
	double rootVariance = sqrt(variance);
	double itoCorrection = -0.5*variance;
	double movedSpot = Spot*(exp((r-d)*Expiry) +itoCorrection);

	double thisSpot;
    double discounting = exp(-r*Expiry);

    MJArray VariateArray(1);

	for (unsigned long i=0; i < NumberOfPaths; i++)
	{
        generator.GetGaussians(VariateArray);
		thisSpot = movedSpot*exp( rootVariance*VariateArray[0]);
		double thisPayOff = TheOption.OptionPayOff(thisSpot);
        gatherer.DumpOneResult(thisPayOff*discounting);
	}

    return;
}

⌨️ 快捷键说明

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