//! Annuity at time 0 double LmmVanillaSwapPricer::annuity0(const VanillaSwap& vanillaSwap, const std::vector<double>& liborsInitValue) const { assert(pLMMTenorStructure_->get_horizon()+1 == liborsInitValue.size()); assert(pLMMTenorStructure_->get_horizon() >= vanillaSwap.get_indexEnd()); // if not cannot price this swap; size_t horizon = pLMMTenorStructure_->get_horizon(); const double & fixedLegdelta_T = vanillaSwap.get_fixedLegTenorType().YearFraction(); const double & floatingLegdelta_T = vanillaSwap.get_floatingLegTenorType().YearFraction(); //! ZC[i] = P(T_0,T_i) std::vector<double> ZC(vanillaSwap.get_indexEnd()+1); ZC[0] = 1.0; for(size_t i=1; i<ZC.size(); ++i) { size_t indexLibor = i-1; //double deltaT = vanillaSwap.get_DeltaTFloatLeg(indexLibor); // YY bug double deltaT = floatingLegdelta_T; ZC[i] = ZC[i-1]/(1+deltaT*liborsInitValue[indexLibor]); } double price = 0.0; const std::vector<LMM::Index>& fixedLegPaymentIndexSchedule = vanillaSwap.get_fixedLegPaymentIndexSchedule(); for(size_t itr = 0; itr < fixedLegPaymentIndexSchedule.size(); ++itr) { size_t fixedLegPaymentIndex = fixedLegPaymentIndexSchedule[itr]; double delta_T = vanillaSwap.get_DeltaTFixedLeg(itr); //std::cout << "numeraire[indexValuationDate]/numeraire[fixedLegPaymentIndex] = " << numeraire[indexValuationDate]/numeraire[fixedLegPaymentIndex] << std::endl; price += delta_T*ZC[fixedLegPaymentIndex]; } return price; }
double LmmVanillaSwapPricer::swapNPV_Analytical_1(const VanillaSwap& vanillaSwap, const std::vector<double>& liborsInitValue) const // initLibor[i] = L_i[T_0] { assert(pLMMTenorStructure_->get_horizon()+1 == liborsInitValue.size()); assert(pLMMTenorStructure_->get_horizon() >= vanillaSwap.get_indexEnd()); // if not cannot price this swap; size_t horizon = pLMMTenorStructure_->get_horizon(); const double & floatingLegdelta_T = vanillaSwap.get_floatingLegTenorType().YearFraction(); const double & fixedLegdelta_T = vanillaSwap.get_fixedLegTenorType().YearFraction(); //! ZC[i] = P(T_0,T_i) std::vector<double> ZC(horizon+2); ZC[0] = 1.0; for(size_t i=1; i<ZC.size(); ++i) { ZC[i] = ZC[i-1]/(1+floatingLegdelta_T*liborsInitValue[i-1]); } //! pvFloatingLeg: 1 - 1 const std::vector<LMM::Index>& floatingLegPaymentIndexSchedule = vanillaSwap.get_floatingLegPaymentIndexSchedule(); //size_t floatingLegTenorLmmTenorRatio = vanillaSwap.get_floatingLegTenorLmmTenorRatio(); LMM::Index indexFloatingLegStart = floatingLegPaymentIndexSchedule.front(); LMM::Index indexFloatingLegEnd = floatingLegPaymentIndexSchedule.back(); double pvFloatingLeg = ZC[indexFloatingLegStart-1] - ZC[indexFloatingLegEnd]; ////! pvFloatingLeg: exact //double pvFloatingLeg = 0.0; //const std::vector<LMM::Index>& floatingLegPaymentIndexSchedule = vanillaSwap.get_floatingLegPaymentIndexSchedule(); //for(size_t itr = 0; itr < floatingLegPaymentIndexSchedule.size(); ++itr) //{ // //! At time T_{i+1}, pay: L_i(T_i) // size_t floatingLegPaymentIndex = floatingLegPaymentIndexSchedule[itr]; // = i+1 // size_t indexLibor = floatingLegPaymentIndex-1; // =i, because : floatingTenor = lmmTenor // pvFloatingLeg += floatingLegdelta_T*initLibor[indexLibor]*ZC[floatingLegPaymentIndex]; //} //! pvFixedLeg double pvFixedLeg = 0.0; const std::vector<LMM::Index>& fixedLegPaymentIndexSchedule = vanillaSwap.get_fixedLegPaymentIndexSchedule(); for(size_t itr = 0; itr < fixedLegPaymentIndexSchedule.size(); ++itr) { size_t fixedLegPaymentIndex = fixedLegPaymentIndexSchedule[itr]; // = itr+1 pvFixedLeg += fixedLegdelta_T*ZC[fixedLegPaymentIndex]; } pvFixedLeg *= vanillaSwap.get_strike(); return pvFloatingLeg - pvFixedLeg; }
double LmmVanillaSwapPricer::annuity( const LMM::Index indexValuationDate, const VanillaSwap & vanillaSwap, const std::vector<double> & numeraire) const { assert(indexValuationDate <= vanillaSwap.get_indexStart()); //YY TODO: this test too slow, esp: within MC simulation assert(pLMMTenorStructure_->get_horizon() >= vanillaSwap.get_indexEnd()); // if not cannot price this swap; double price = 0.0; const std::vector<LMM::Index>& fixedLegPaymentIndexSchedule = vanillaSwap.get_fixedLegPaymentIndexSchedule(); for(size_t itr = 0; itr < fixedLegPaymentIndexSchedule.size(); ++itr) { size_t fixedLegPaymentIndex = fixedLegPaymentIndexSchedule[itr]; double delta_T = vanillaSwap.get_DeltaTFixedLeg(itr); //std::cout << "numeraire[indexValuationDate]/numeraire[fixedLegPaymentIndex] = " << numeraire[indexValuationDate]/numeraire[fixedLegPaymentIndex] << std::endl; price += delta_T*numeraire[indexValuationDate]/numeraire[fixedLegPaymentIndex]; } return price; }