pathdependentasiangeometric.h

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

H
90
字号
//
//
//                  PathDependentAsian.h
//
//


#define PathDependentAsianG_H

#include <PathDependent.h>
#include <PayOffBridge.h>

class PathDependentAsianG : public PathDependent
{
public:

    PathDependentAsianG(const MJArray& LookAtTimes_, 
                       double DeliveryTime_,
                       const PayOffBridge& ThePayOff_);

    virtual unsigned long MaxNumberOfCashFlows() const;
    virtual MJArray PossibleCashFlowTimes() const;
    virtual unsigned long CashFlows(const MJArray& SpotValues, 
                                    std::vector<CashFlow>& GeneratedFlows) const;
    virtual ~PathDependentAsianG(){}
    virtual PathDependent* clone() const;

private:

    double DeliveryTime;
    PayOffBridge ThePayOff;
    unsigned long NumberOfTimes;
};

//
//
//
//                    PathDependentAsian.cpp
//
//

#include <PathDependentAsian.h>

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

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

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

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

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

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

    return 1UL; 
}

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



⌨️ 快捷键说明

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