pathdependentasiangeometric.cpp

来自「蒙特卡罗期权定价 布朗桥方法 分层样本方法」· C++ 代码 · 共 46 行

CPP
46
字号
#include "PathDependentAsianGeometric.h"

PathDependentAsianGeometric::PathDependentAsianGeometric(const MJArray& LookAtTimes_, 
                                       double DeliveryTime_,
                                       const PayOffBridge& ThePayOff_)
                                       :
                                        PathDependent(LookAtTimes_),
                                        DeliveryTime(DeliveryTime_),
                                        ThePayOff(ThePayOff_),
                                        NumberOfTimes(LookAtTimes_.size())
{
}

unsigned long PathDependentAsianGeometric::MaxNumberOfCashFlows() const
{
     return 1UL;
}

MJArray PathDependentAsianGeometric::PossibleCashFlowTimes() const
{
    MJArray tmp(1UL);
    tmp[0] = DeliveryTime;
    return tmp;
}

unsigned long PathDependentAsianGeometric::CashFlows(const MJArray& SpotValues, 
                                    std::vector<CashFlow>& GeneratedFlows) const
{
   long double sum =1;
for (size_t i=0; i<SpotValues.size();i++)
sum=sum*SpotValues[i];

long double M=1.0/NumberOfTimes;
    long double mean = pow(sum,M);

    GeneratedFlows[0].TimeIndex = 0UL;
    GeneratedFlows[0].Amount = ThePayOff(mean);

    return 1UL; 
}

PathDependent* PathDependentAsianGeometric::clone() const
{
    return new PathDependentAsianGeometric(*this);
}

⌨️ 快捷键说明

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