Esempio n. 1
0
//! 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;
}
Esempio n. 2
0
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;
}