Ejemplo n.º 1
0
    bool MultiStepSwaption::nextTimeStep(
        const CurveState &currentState,
        std::vector<Size> &numberCashFlowsThisStep,
        std::vector<std::vector<MarketModelMultiProduct::CashFlow> > &
            genCashFlows) {
        if (currentIndex_ == startIndex_) {
            genCashFlows[0][0].timeIndex = 0;
            // Rate swapRate =
            // currentState.cmSwapRate(startIndex_,endIndex_-startIndex_);
            // Real annuity =
            // currentState.cmSwapAnnuity(startIndex_,startIndex_,endIndex_-startIndex_);
            Rate swapRate =
                currentState.swapRate(startIndex_, endIndex_, step_);
            Real annuity = currentState.swapAnnuity(startIndex_, startIndex_,
                                                    endIndex_, step_);

            genCashFlows[0][0].amount = (*payoff_)(swapRate) * annuity;
            // std::max(swapRate-payoff_->strike(),0.0) * annuity; // test

            numberCashFlowsThisStep[0] =
                genCashFlows[0][0].amount != 0.0 ? 1 : 0;
        } else {
            numberCashFlowsThisStep[0] = 0;
        }

        ++currentIndex_;
        return currentIndex_ > startIndex_;
    }
Ejemplo n.º 2
0
 void CustomBasisSystem::values(const CurveState& currentState,
                              std::vector<Real>& results) const {
     results.reserve(startByCurrentIndex_.size()+1);
     results.resize(1);
     results[0] = 1.0;
     //        std::cout << "Custom basis system:" << std::endl;
     for(Size i=0;i<startByCurrentIndex_.size();i++) {
         results.push_back(currentState.swapRate(startByCurrentIndex_[i](currentIndex_),
                                                 endByCurrentIndex_[i](currentIndex_),
                                                 step_));
         //            std::cout << "rate (" << startByCurrentIndex_[i](currentIndex_) << ";" <<
         //    endByCurrentIndex_[i](currentIndex_) << ";" << step_ << ") " << results.back() << std::endl;
     }
     
 }
Ejemplo n.º 3
0
    bool MultiStepVolSwap::nextTimeStep(
            const CurveState& currentState,
            std::vector<Size>& numberCashFlowsThisStep,
            std::vector<std::vector<MarketModelMultiProduct::CashFlow> >& genCashFlows)
    {

		//std::cout << "currentIndex=" << currentIndex_ << std::endl;

		Rate referenceRate = currentState.swapRate(referenceRateIndices_.first, referenceRateIndices_.second, referenceRateStep_ );
		
		for(Size i=8; i>=1; i--) referenceRateFixings_[i] = referenceRateFixings_[i-1];
		referenceRateFixings_[0] = referenceRate;

		Size noCf=0;

		if(currentIndex_ == floatingFixingIndices_[currentFloatingIndex_]) {
	        Rate liborRate = currentState.forwardRate(currentFloatingIndex_);
			//std::cout << "generate float payment @" << floatingPaymentIndices_[currentFloatingIndex_] << std::endl;
			genCashFlows[0][noCf].timeIndex = floatingPaymentIndices_[currentFloatingIndex_];
			genCashFlows[0][noCf].amount = (payer_ ? 1.0 : -1.0)*liborRate*floatingAccruals_[currentFloatingIndex_];
			noCf++;
			currentFloatingIndex_++;
		}

		if(currentIndex_ == structuredFixingIndices_[currentStructuredIndex_]) {
			//std::cout << "generate structured payment @" << paymentTimes_[structuredPaymentIndices_[currentStructuredIndex_]] << std::endl;
			Real volIdx = (fabs(referenceRateFixings_[1]-referenceRateFixings_[5])+
				          fabs(referenceRateFixings_[2]-referenceRateFixings_[6])+
						  fabs(referenceRateFixings_[3]-referenceRateFixings_[7])+
						  fabs(referenceRateFixings_[4]-referenceRateFixings_[8])) / 4.0;
			genCashFlows[0][noCf].timeIndex = structuredPaymentIndices_[currentStructuredIndex_];
			genCashFlows[0][noCf].amount = ( (currentStructuredIndex_== (Size)filterStructuredIndex_ || filterStructuredIndex_== -1) ? 1.0 : 0.0)*(payer_ ? -1.0 : 1.0)*structuredAccruals_[currentStructuredIndex_]*std::max(floor_,fixedRate_+multiplier_*volIdx);
			//genCashFlows[0][noCf].amount = (currentIndex_==structuredFixingIndices_[0] ? 1.0 : 0.0)*std::max(referenceRate-fixedRate_,0.0)*currentState.swapAnnuity(12,12,52,2); // TEST (plain vanilla swaption payoff)
			noCf++;
			currentStructuredIndex_++;
		}

        numberCashFlowsThisStep[0] = noCf;

        ++currentIndex_;

		bool done = (floatingFixingIndices_[currentFloatingIndex_] == QL_MAX_INTEGER && structuredFixingIndices_[currentStructuredIndex_] == QL_MAX_INTEGER );

		//std::cout << "ok, finished = " << done << std::endl;

        return done; 
    }