Esempio n. 1
0
void LongstaffSchwartzExerciseStrategy::nextStep(
    const CurveState& currentState) {
    principalInNumerairePortfolio_ = newPrincipal_;

    if (isRebateTime_[currentIndex_])
        exercise_->nextStep(currentState);
    if (isControlTime_[currentIndex_])
        control_->nextStep(currentState);
    if (isBasisTime_[currentIndex_])
        basisSystem_->nextStep(currentState);

    if (currentIndex_ < numeraires_.size()-1) {
        Size numeraire = numeraires_[currentIndex_];
        Size nextNumeraire = numeraires_[currentIndex_+1];
        newPrincipal_ *=
            currentState.discountRatio(numeraire, nextNumeraire);
    }

    ++currentIndex_;
}
    bool MultiStepPeriodCapletSwaptions::nextTimeStep(
            const CurveState& currentState,
            std::vector<Size>& numberCashFlowsThisStep,
            std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
                                                               genCashFlows)
    {

     for (Size i=0; i < numberCashFlowsThisStep.size(); ++i)
        numberCashFlowsThisStep[i]=0UL;

    if (currentIndex_ >=offset_ && (currentIndex_ - offset_) % period_ ==0)
    {
        // caplet first
        Real df = currentState.discountRatio(currentIndex_ + period_, currentIndex_);
        Time tau = rateTimes_[currentIndex_+period_]- rateTimes_[currentIndex_];
        Real forward = (1.0/df-1.0)/tau;
        Real value = (*forwardPayOffs_[productIndex_])(forward);
        value *= tau*currentState.discountRatio(currentIndex_+period_,currentIndex_);

        if (value >0)
        {
            numberCashFlowsThisStep[productIndex_]=1UL;
            genCashFlows[productIndex_][0].amount = value;
            genCashFlows[productIndex_][0].timeIndex= productIndex_;
        }

        // now swaption

        unsigned long numberPeriods = numberBigFRAs_ - productIndex_;
        Real B = 0.0;
        double P0 = 1.0; // i.e currentState.discountRatio(currentIndex_,currentIndex_);
        Real Pn = currentState.discountRatio(currentIndex_ + numberPeriods*period_, currentIndex_);
        for (unsigned long i=0; i < numberPeriods; ++i)
        {
            Time tau = rateTimes_[currentIndex_+(i+1)*period_]- rateTimes_[currentIndex_+i*period_];
            B+= tau*currentState.discountRatio(currentIndex_+(i+1)*period_,currentIndex_);
        }


        Real swapRate = (P0-Pn)/B;

        Real swaptionValue=  (*swapPayOffs_[productIndex_])(swapRate);
        swaptionValue *=B;

        if (swaptionValue >0)
        {
            numberCashFlowsThisStep[productIndex_+numberBigFRAs_]=1UL;
            genCashFlows[productIndex_+numberBigFRAs_][0].amount = swaptionValue;
            genCashFlows[productIndex_+numberBigFRAs_][0].timeIndex=productIndex_+numberBigFRAs_;
       }

        ++productIndex_;

    }

    ++currentIndex_;

    bool terminate =(productIndex_ >= numberBigFRAs_);


    return terminate;
    }