コード例 #1
0
void PricingConfig::resetAllLmmComponent()
{
	shifts.resize(pLMMTenorStructure->get_horizon()+1) ; std::fill(shifts.begin(), shifts.end(), shifted_value);

	liborsInitValue.resize(pLMMTenorStructure->get_horizon()+1) ; std::fill(liborsInitValue.begin(), liborsInitValue.end(), fwdRate);
	
	pVanillaSwap.reset( new VanillaSwap(strike, indexStart, indexEnd, floatLegTenorType, fixedLegTenorType, pLMMTenorStructure) );
	pVanillaSwaption.reset(new VanillaSwaption(*pVanillaSwap,OptionType::CALL) );

	size_t correlFullRank = pLMMTenorStructure->get_horizon()+1;
	size_t correlReducedRank = corr_nbFactor;

	CorrelationReductionType::CorrelationReductionType non_reduction=CorrelationReductionType::NON;
	//pCorrelation.reset(new Const_Correlation(correlFullRank,correlReducedRank, non_reduction , 0. ) );
	pCorrelation.reset(new XY_beta_Correlation(correlFullRank,correlReducedRank, corr_ReductionType,XY_corr_alpha,XY_corr_beta) );
	pCorrelation->calculate();
	//pCorrelation->print("simuTest_MCvsApprox_SwaptionPricer_Correlation.csv");


	pHGVolatilityFunction.reset( new ConstShifted_HGVolatilityFunction(pLMMTenorStructure, pCorrelation, abcd_params_ptr) );
	

	pDispersion.reset(new Dispersion(pHGVolatilityFunction) );

	pRNGenerator.reset( new McGenerator(seed) );

	pLmm.reset(new Lmm(*pDispersion));

	if(useTerminalProba)
	{
		pMCLmm.reset(new McTerminalLmm(pLmm, liborsInitValue, pRNGenerator, mcSchemeType) ) ;
	}
	else
	{
		pMCLmm.reset(new McSpotLmm(pLmm, liborsInitValue, pRNGenerator, mcSchemeType) ) ;
	}

	pMCLmmVanillaSwapPricer.reset(     new McLmmVanillaSwapPricer(pMCLmm)     ) ;
	pMCLmmVanillaSwaptionPricer.reset( new McLmmVanillaSwaptionPricer(pMCLmm) ) ;
	pLmmApproxVanillaSwaptionPricer.reset( new LmmVanillaSwaptionApproxPricer_Rebonato(pLmm) ); //YY: wrong!
}
コード例 #2
0
ファイル: Test_GMatrixMapping.cpp プロジェクト: JBLMM/LMM
UpperTriangleVanillaSwaptionQuotes_ConstPTR create_UpperTriangleVanillaSwaptionQuotes(LMMTenorStructure_PTR pLMMTenorStructure, const Tenor& tenorfixedleg, const Tenor& tenorfloatleg)
{
	/// Creation of Rebonato Approx ==================================

	size_t nbFactor       = 3; // need to test nbFactor  = 3, and nbFactor = 
	size_t correlFullRank = pLMMTenorStructure->get_horizon()+1;
	size_t correlReducedRank = nbFactor;
	CorrelationReductionType::CorrelationReductionType correlReductionType = CorrelationReductionType::PCA;
	double correlAlpha = 0.0;
	double correlBeta  = 0.1;
	Correlation_PTR correlation(new XY_beta_Correlation(correlFullRank,correlReducedRank, correlReductionType,correlAlpha,correlBeta));
	correlation->calculate(); // for print.

	double a=0.22,b=0.4,c=0.6,d=0.15;
	double g_constParam = 1.;
	double shift_constParam = 0.0;

	Shifted_HGVolatilityParam::ABCDParameter abcdParam(a,b,c,d);
	ConstShifted_HGVolatilityParam_PTR pConstShifted_HGVolatilityParam( new ConstShifted_HGVolatilityParam(pLMMTenorStructure, abcdParam, g_constParam, shift_constParam));


	Shifted_HGVolatilityFunction_PTR pVolatilityFunction (new ConstShifted_HGVolatilityFunction(pLMMTenorStructure, correlation, pConstShifted_HGVolatilityParam)); 

	//! Dispersion
	Dispersion dispersion(pVolatilityFunction);

	Lmm_PTR lmm_ptr(new Lmm(dispersion) );

	LmmVanillaSwaptionApproxPricer_Rebonato_PTR pLmmApproxVanillaSwaptionPricer(new LmmVanillaSwaptionApproxPricer_Rebonato(lmm_ptr));	
	/// End of creation of Rebonato Approx ==================================


	LiborQuotes_ConstPTR libor_quote_ptr = LiborQuotes::create_LiborInit(pLMMTenorStructure, 0.02);

	UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = UpperTriangleVanillaSwaptionQuotes::create_ATMSwaptionImpliedVol(
		libor_quote_ptr,
		tenorfixedleg,
		tenorfloatleg,
		pLmmApproxVanillaSwaptionPricer
		);

	//assert( atm_swaption_implied_vol_ptr->check_swaprate_consistency(libor_quote_ptr) );

	return atm_swaption_implied_vol_ptr;
}
UpperTriangleVanillaSwaptionQuotes::UpperTriangleVanillaSwaptionQuotes(
	LMMTenorStructure_PTR lmmTenorStructure,
	int   lastYear, 	
	const Tenor& fixedTenor,
	const Tenor& floatingTenor,
	const UpperTriangularDoubleMatrix& strikes, // 1st row and column not used like g!
	const UpperTriangularDoubleMatrix& quotes)  // 1st row and column not used like g!
	: lmmTenorStructure_(lmmTenorStructure)
	, lastYear_(lastYear)
	, fixedTenor_(fixedTenor)
	, floatingTenor_(floatingTenor)
	, indexRatio_(fixedTenor.NbOfMonth()/floatingTenor.NbOfMonth())
	, upperTriangleVanillaSwaptionQuotes_(lastYear+1, lastYear+1)
	, indexMapping_gDelegate_gTransformed_(lastYear+1, lastYear+1)
{
	assert(lmmTenorStructure_->get_horizon() == lastYear*indexRatio_); 
	assert(lastYear>1);
	assert(strikes.size1() == strikes.size2() && strikes.size1() == lastYear_+1); 
	assert(quotes.size1()  == quotes.size2()  && quotes.size1()  == lastYear_+1);
	assert(fixedTenor.NbOfMonth() == 12 && fixedTenor.NbOfMonth()%floatingTenor.NbOfMonth() ==0);
	assert(lmmTenorStructure->get_tenorType() == floatingTenor);

	//! upperTriangle:
	for(size_t iExpirity = 1; iExpirity<quotes.size1(); ++iExpirity) // row
	{
		for(size_t jTenor = 1; jTenor<quotes.size2()-iExpirity; ++jTenor) // col
		{
			double strike = strikes(iExpirity,jTenor);
			//size_t indexStart = computeStartIndex(iExpirity);
			//size_t indexEnd   = computeIndexEnd(iExpirity,jTenor);
			size_t indexStart = iExpirity*indexRatio_;
			size_t indexEnd   = indexStart + jTenor*indexRatio_;
			VanillaSwap     vanillaSwap(strike, indexStart, indexEnd, floatingTenor_, fixedTenor_, lmmTenorStructure);
			VanillaSwaption vanillaSwaption(vanillaSwap, OptionType::OptionType::CALL);

			double quote = quotes(iExpirity,jTenor);

			std::pair<VanillaSwaption, double> p(vanillaSwaption, quote);

			upperTriangleVanillaSwaptionQuotes_(iExpirity,jTenor) = p;
		}
	}

	initialize_gDelegate_IndexIngTransformed();
}
コード例 #4
0
void BetaShifted_HGVolatilityParam::initializeShiftMatrix(
	LMMTenorStructure_PTR        pLMMTenorStructure, 
	const LowerTriangularMatrix& betas, 
	const std::vector<double>&   liborsInitValues)
{
	assert(betas.size1() == betas.size2() && betas.size2() == liborsInitValues.size() && pLMMTenorStructure->get_nbLIBOR());

	//unused first column, first row is automatically null since it is lower triangular matrix
	LowerTriangularMatrix m(betas.size1(), betas.size2());

	for(size_t k=0; k<m.size1();++k)
	{
		shift_matrix_(k,0) = 1.0e100;	
	}

	for(size_t liborIndex=1; liborIndex<m.size1();++liborIndex)
	{
		for(size_t timeIndex=1;timeIndex<=liborIndex;++timeIndex)
		{
			double beta = betas(liborIndex,timeIndex);
			double liborInitValue = liborsInitValues[liborIndex];
			shift_matrix_(liborIndex,timeIndex) = 1+ (1-beta)/beta*liborInitValue;
		}	
	} 
}
コード例 #5
0
//! for MC
double McGeneticTargetSwapLmmPricer::evaluateCouponLeg(	LMM::Index indexValuationDate,
														const CouponLeg_CONSTPTR couponLeg,
														const std::vector<double>& numeraire, 
														const matrix& liborMatrix,
														LMMTenorStructure_PTR lmmTenorStructure)const 
{
	std::vector<Coupon_CONSTPTR> couponList=couponLeg->getLeg();
	
	Coupon_CONSTPTR firstCoupon = couponList[0];
	TargetCoupon_CONSTPTR firstTargetCoupon = boost::dynamic_pointer_cast<const TargetCoupon>(firstCoupon);
	if(!firstTargetCoupon)
		throw("fail to cast targetCoupon");
	double	target	=	firstTargetCoupon->getTarget();
	Rate_CONSTPTR firstRate = firstTargetCoupon->getRate();   
	LiborRate_CONSTPTR	firstLiborRate		=	boost::dynamic_pointer_cast<const LiborRate>(firstRate);
	ConstRate_CONSTPTR	firstConstRate		=	boost::dynamic_pointer_cast<const ConstRate>(firstRate);
	if(!firstLiborRate&&!firstConstRate)
	{
		throw("fail to cast LiborRate or ConstRate");
	}

	double price = 0.0;
	if(firstLiborRate)
	{
		if(firstLiborRate->getDuration()!=lmmTenorStructure->get_tenorType())
			throw("the tenor of the libor demanded is not the same than that in the model");
		for(size_t i=0; i<couponList.size(); i++)
		{
			Coupon_CONSTPTR coupon=couponList[i];		
			LMM::Index paymentIndex = coupon->getPaymentIndex();

			if(paymentIndex<=indexValuationDate)continue;

			CappedFlooredCoupon_CONSTPTR cappedFlooredCoupon = boost::dynamic_pointer_cast<const CappedFlooredCoupon>(coupon);
			TargetCoupon_CONSTPTR targetCoupon = boost::dynamic_pointer_cast<const TargetCoupon>(coupon);
			Rate_CONSTPTR rate = targetCoupon->getRate();   
			LiborRate_CONSTPTR	liborRate		=	boost::dynamic_pointer_cast<const LiborRate>(rate);
			LMM::Index	indexLibor				=	liborRate->getFixingTime();

			assert(indexLibor<=paymentIndex);

			if(price<target)
			{	
				double numeraire1		=	numeraire[indexValuationDate];
				double numeraire2		=	numeraire[paymentIndex];
				double numeraireLocal	=	numeraire1/numeraire2;
				double liborValue		=	liborMatrix(indexLibor, indexLibor);
				double result_calculate	=	evaluateCappedFlooredCoupon(cappedFlooredCoupon, liborValue);			
				price				   +=	numeraireLocal*result_calculate;
			}
		}
	}
	else
	{
		for(size_t i=0; i<couponList.size(); i++)
		{
			Coupon_CONSTPTR coupon=couponList[i];		
			LMM::Index paymentIndex = coupon->getPaymentIndex();

			if(paymentIndex<=indexValuationDate)continue;

			CappedFlooredCoupon_CONSTPTR cappedFlooredCoupon = boost::dynamic_pointer_cast<const CappedFlooredCoupon>(coupon);
			Rate_CONSTPTR rate = cappedFlooredCoupon->getRate();   
			ConstRate_CONSTPTR	constRate		=	boost::dynamic_pointer_cast<const ConstRate>(rate);
			double	constRateValue				=	constRate->getConstRateValue();

			price+=numeraire[indexValuationDate]/numeraire[paymentIndex]*evaluateCappedFlooredCoupon(cappedFlooredCoupon, constRateValue);
		}
	}

	return price;
}
UpperTriangleVanillaSwaptionQuotes_ConstPTR UpperTriangleVanillaSwaptionQuotes::create_ATMSwaptionImpliedVol
	(
	LiborQuotes_ConstPTR libor_quotes_ptr,
	const Tenor&  fixedTenor,
	const Tenor&  floatingTenor,
	LmmVanillaSwaptionApproxPricer_Rebonato_PTR black_vol_approx_ptr,
	const double&  strike_bump
	)
{
	LMMTenorStructure_PTR pLMMTenorStructure = libor_quotes_ptr->get_LMMTenorStructure_PTR() ;
	size_t fix_float_ratio = fixedTenor.ratioTo(floatingTenor);
	size_t lastLiborIndex  = pLMMTenorStructure->get_nbLIBOR()-1;
	assert(lastLiborIndex%fix_float_ratio == 0);
	size_t last_year = lastLiborIndex / fix_float_ratio ;

	size_t matrix_size = last_year + 1 ;
	UpperTriangularDoubleMatrix swap_rate_matrix(matrix_size,matrix_size);
	UpperTriangularDoubleMatrix black_vol_matrix(matrix_size,matrix_size);

	//first row and first column never used
	for(size_t k=0;k<matrix_size;++k)
	{
		swap_rate_matrix(k,0) = -1000000; swap_rate_matrix(0,k) = -1000000;
		black_vol_matrix(k,0) = -1000000; black_vol_matrix(0,k) = -1000000;
	}


	const std::vector<double> & init_libor = libor_quotes_ptr->get_InitLibor();
	LmmVanillaSwapPricer swap_pricer(pLMMTenorStructure);
	for(size_t iMaturity=1;iMaturity<matrix_size;++iMaturity)
	{
		for(size_t jTenor=1;jTenor<matrix_size - iMaturity ;++jTenor)
		{
			size_t start_swap_index = iMaturity * fix_float_ratio;
			size_t end_swap_index   = (iMaturity+jTenor) * fix_float_ratio;	

			double empty_strike = -100000000;
			VanillaSwap swap_ij(empty_strike,start_swap_index,end_swap_index,floatingTenor,fixedTenor,pLMMTenorStructure);
			double swap_rate_ij = strike_bump+swap_pricer.swapRate_Analytical(swap_ij,init_libor);

			swap_ij.set_strike(swap_rate_ij);
			swap_rate_matrix(iMaturity,jTenor) = swap_rate_ij;

			VanillaSwaption swaption_ij(swap_ij, OptionType::OptionType::CALL);
			double black_vol_ij = black_vol_approx_ptr->volBlack(swaption_ij,init_libor);

			black_vol_matrix(iMaturity,jTenor)=black_vol_ij;
		}
	}

	UpperTriangleVanillaSwaptionQuotes_PTR atm_swaption_implied_vol 
		(new UpperTriangleVanillaSwaptionQuotes(
		pLMMTenorStructure,
		last_year,
		fixedTenor,
		floatingTenor,
		swap_rate_matrix,
		black_vol_matrix
		) 
		);

	atm_swaption_implied_vol->set_Data_FileName("VirtuallyCreatedData");

	return atm_swaption_implied_vol;
}