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

📄 pathdependentasiangeometric.h

📁 蒙特卡罗期权定价 布朗桥方法 分层样本方法
💻 H
字号:
//
//
//                  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -