当前位置: 首页>>代码示例>>C++>>正文


C++ Tenor类代码示例

本文整理汇总了C++中Tenor的典型用法代码示例。如果您正苦于以下问题:C++ Tenor类的具体用法?C++ Tenor怎么用?C++ Tenor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tenor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_TruncatedLocalResetGMatrixMapping

void test_TruncatedLocalResetGMatrixMapping()
{
	{
		size_t nbYear = 6;
		Tenor tenorfixedleg = Tenor::_1YR;
		Tenor tenorfloatleg = Tenor::_6M;
		const double increment_matrix = 10;

		LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

		size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
		size_t horizon = pLmmTenorStructure->get_horizon() ;

		size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
		size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

		UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

		Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

		UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

		GMatrixMapping gMatrixMapping(
			g_matrix_size
			, empty_delegate_matrix
			, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

		std::vector<size_t> truncated_cols;
		truncated_cols.push_back(2);
		truncated_cols.push_back(3);

		std::vector<size_t> truncated_rows;
		truncated_rows.push_back(2);
		truncated_rows.push_back(3);

		gMatrixMapping.reset_Truncated_gDelegate_Rows(truncated_rows);
		gMatrixMapping.reset_Truncated_gDelegate_Cols(truncated_cols);
		std::vector<size_t> non_truncated_row = get_NonTruncatedIndices(truncated_rows,nbYear);

		size_t value_counter=1;
		for(size_t iRow=0;iRow<non_truncated_row.size();++iRow)
		{
			const size_t iDelegate = non_truncated_row[iRow];

			QuantLib::Array x = gMatrixMapping.get_DelegateArray(iDelegate);
			for(size_t jX=0;jX<x.size();++jX)
			{
				x[jX]=value_counter*0.1;
				++value_counter;
			}
			gMatrixMapping.reset_gDelegate(x,iDelegate);
			std::cout<<" Delegate Row["<<iDelegate<<"]   "<<x<<std::endl;
			std::ostringstream local_gDelegate_file; 
			local_gDelegate_file<< "test_TruncatedLocalResetGMatrixMapping_"<<iDelegate<<"thRow.csv";

			gMatrixMapping.print(local_gDelegate_file.str() );
		}
	}

}
开发者ID:JBLMM,项目名称:LMM,代码行数:60,代码来源:Test_GMatrixMapping.cpp

示例2: test_LocalResetGMatrixMapping

void test_LocalResetGMatrixMapping()
{
	std::cout<<"hello test_LocalResetGMatrixMapping() "<<std::endl;

	size_t nbYear = 5;
	Tenor tenorfixedleg = Tenor::_1YR;
	Tenor tenorfloatleg = Tenor::_6M;
	const double increment_matrix = 10;

	LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
	size_t horizon = pLmmTenorStructure->get_horizon() ;

	size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
	size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

	UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

	UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

	GMatrixMapping gMatrixMapping(
		g_matrix_size
		, empty_delegate_matrix
		, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

	gMatrixMapping.print("test_LocalResetGMatrixMapping_init.csv");

	Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

	// loop reset delegate rows
	size_t max_DelegateRowIndex =	gMatrixMapping.get_MaxDelegateRowIndex();

	for(size_t iRowDelegate=1;iRowDelegate<=max_DelegateRowIndex;++iRowDelegate)
	{
		QuantLib::Array row_values = gMatrixMapping.get_DelegateArray(iRowDelegate);
		for(size_t jarray=0;jarray<row_values.size();++jarray)
		{
			size_t jColDelegate = jarray+1;
			row_values[jarray] = empty_delegate_matrix(iRowDelegate,jColDelegate);
			gMatrixMapping.reset_gDelegate(row_values,iRowDelegate);

			std::ostringstream local_gDelegate_file; 
			local_gDelegate_file<< "test_LocalResetGMatrixMapping_reset_"<<iRowDelegate<<"th-Col.csv";
			gMatrixMapping.print( local_gDelegate_file.str() );
		}	
	}

	check_gMatrix(gMatrixMapping.get_g_Ref(), increment_matrix);
}
开发者ID:JBLMM,项目名称:LMM,代码行数:50,代码来源:Test_GMatrixMapping.cpp

示例3: vanillaSwapComparaisonExemple

void vanillaSwapComparaisonExemple()
{

	double strike		=	0.02;
	size_t indexStart	=	3;
	size_t indexEnd		=	19;
	Tenor tenorStruture	=	Tenor::_6M;
	Tenor floatingTenor	=	Tenor::_6M;
	Tenor fixedTenor	=	Tenor::_12M;
	LMMTenorStructure_PTR lmmTenorStructure(new LMMTenorStructure(tenorStruture, 10));
	size_t liborIndex	=	lmmTenorStructure->get_horizon()+1;
	std::vector<double> myInitialLibor(liborIndex);

	for (size_t i = 0; i <myInitialLibor.size(); i++)
	{
		myInitialLibor[i]=0.02;							//+((double)i)*0.01;
	}

	cout	<<	"strike:                        "	<<	strike												<<	endl;
	cout	<<	"indexStart:                    "	<<	indexStart											<<	endl;
	cout	<<	"indexEnd:                      "	<<	indexEnd											<<	endl;
	cout	<<	"tenorStrutureYearFraction:     "	<<	lmmTenorStructure->get_tenorType().YearFraction()	<<	endl;
	cout	<<	"floatingVStenorStrutureRatio:  "	<<	floatingTenor.ratioTo(tenorStruture)				<<	endl;
	cout	<<	"fixedVStenorStrutureRatio:     "	<<	fixedTenor.ratioTo(tenorStruture)					<<	endl;
	cout	<<	"myInitialLibor:  ";
	for (size_t i = 0; i <myInitialLibor.size(); i++)
	{
		cout	<<	myInitialLibor[i]	<<	" ";
	}
	cout	<<	 endl;
	cout	<<	 endl;

	//VanillaSwap_Chi_Trang
	VanillaSwap myVS(strike, indexStart , indexEnd, floatingTenor, fixedTenor, lmmTenorStructure);
	LmmVanillaSwapPricer myVSP(lmmTenorStructure);
	double prix_swap=myVSP.swapNPV_Analytical_1(myVS, myInitialLibor);


	//GeneticSwap test
	//build geneticVanillaSwap
	GenericSwap_CONSTPTR vanillaSwap_Genetic=InstrumentFactory::createVanillaSwap(
		strike,indexStart,indexEnd,floatingTenor,fixedTenor,lmmTenorStructure,1.0);

	GenericVanillaSwapPricer_PTR geneticVanillaSwapPricer(new GenericVanillaSwapPricer());
	double geneticPrice=geneticVanillaSwapPricer->genericVanillaSwap_Analytical(vanillaSwap_Genetic, myInitialLibor);

	cout << "FirstVersionSwapPrice: "	<<	prix_swap				<< endl;
	cout << "GeneticSwapTest:       "	<<	geneticPrice			<< endl;
	cout << "Difference:            "	<<	geneticPrice-prix_swap	<< endl;
}
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:50,代码来源:Test_Comparaison_VanillaSwap.cpp

示例4: test_CascadeResetGMatrixMapping

void test_CascadeResetGMatrixMapping()
{
	{
		size_t nbYear = 5;
		Tenor tenorfixedleg = Tenor::_1YR;
		Tenor tenorfloatleg = Tenor::_6M;
		const double increment_matrix = 10;

		LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

		size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
		size_t horizon = pLmmTenorStructure->get_horizon() ;

		size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
		size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

		UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

		UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

		GMatrixMapping gMatrixMapping(
			g_matrix_size
			, empty_delegate_matrix
			, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

		gMatrixMapping.print("test_CascadeResetGMatrixMapping_init.csv");

		Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

		// loop reset delegate rows
		size_t max_DelegateRowIndex =	gMatrixMapping.get_MaxDelegateRowIndex();

		for(size_t iRowDelegate=1;iRowDelegate<=max_DelegateRowIndex;++iRowDelegate)
		{
			size_t max_DelegateColIndex = delegate_matrix_size - (iRowDelegate+1);

			for(size_t jColDelegate=1;jColDelegate<=max_DelegateColIndex;++jColDelegate)
			{
				std::pair<size_t,size_t> gDelegate_cell(iRowDelegate,jColDelegate);
				gMatrixMapping.reset_gDelegate(empty_delegate_matrix(iRowDelegate,jColDelegate) ,gDelegate_cell);

				std::ostringstream local_gDelegate_file; 
				local_gDelegate_file<< "test_CascadeResetGMatrixMapping_reset_"<<iRowDelegate<<"row_"<< jColDelegate<<"col"  <<".csv";
				gMatrixMapping.print( local_gDelegate_file.str() );	
			}	
		}
	}
}
开发者ID:JBLMM,项目名称:LMM,代码行数:48,代码来源:Test_GMatrixMapping.cpp

示例5: lmmTenorStructure_

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();
}
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:45,代码来源:UpperTriangleVanillaSwaptionQuotes.cpp

示例6: test_GlobalResetGMatrixMapping

void test_GlobalResetGMatrixMapping()
{
	std::cout<<"hello test_GlobalResetGMatrixMapping() "<<std::endl;

	size_t nbYear = 5;
	Tenor tenorfixedleg = Tenor::_1YR;
	Tenor tenorfloatleg = Tenor::_6M;
	const double increment_matrix = 10;

	LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
	size_t horizon = pLmmTenorStructure->get_horizon() ;

	size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
	size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

	UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

	Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

	UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

	GMatrixMapping gMatrixMapping(
		g_matrix_size
		, empty_delegate_matrix
		, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

	gMatrixMapping.print("test_GlobalResetGMatrixMapping.csv");

	//check_gMatrix(gMatrixMapping.get_g_Ref(), increment_matrix);

	QuantLib::Array x = gMatrixMapping.get_DelegateArray();

	std::cout<<std::endl<<std::endl<<x<<std::endl;

	LmmGnuplotPrinterMatrix gnuplot_printer(pLmmTenorStructure);
	const LowerTriangularDoubleMatrix& lower_matrix = gMatrixMapping.get_g_Ref();

	gnuplot_printer.printVolMatrix(lower_matrix,"test_GlobalResetGMatrixMapping");
}
开发者ID:JBLMM,项目名称:LMM,代码行数:41,代码来源:Test_GMatrixMapping.cpp

示例7: test_TruncatedCascadeResetGMatrixMapping

void test_TruncatedCascadeResetGMatrixMapping()
{
	// use of reset parallelograme truncated row
	{
		size_t nbYear = 5;
		Tenor tenorfixedleg = Tenor::_1YR;
		Tenor tenorfloatleg = Tenor::_6M;
		const double increment_matrix = 10;

		LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

		size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
		size_t horizon = pLmmTenorStructure->get_horizon() ;

		size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
		size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

		UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

		UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

		GMatrixMapping gMatrixMapping(
			g_matrix_size
			, empty_delegate_matrix
			, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

		gMatrixMapping.print("test_TruncatedCascadeResetGMatrixMapping_init.csv");

		//Initiate_UpperTriangularDoubleMatrixConstantDiagonal(empty_delegate_matrix, increment_matrix);
		Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

		std::vector<std::pair<size_t,size_t> > truncated_cells;

		truncated_cells.push_back(std::pair<size_t,size_t>(1,1) );
		//truncated_cells.push_back(std::pair<size_t,size_t>(1,4) );
		//truncated_cells.push_back(std::pair<size_t,size_t>(2,2) );
		//truncated_cells.push_back(std::pair<size_t,size_t>(4,1) );
				
		for(size_t i=0;i<truncated_cells.size();++i)
		{
			gMatrixMapping.add_Truncated_gDelegate_Cells(truncated_cells[i]);
		}
		
		// loop reset delegate rows
		size_t max_DelegateRowIndex =	gMatrixMapping.get_MaxDelegateRowIndex();

		for(size_t iRowDelegate=1;iRowDelegate<=max_DelegateRowIndex;++iRowDelegate)
		{

			size_t max_DelegateColIndex = delegate_matrix_size - (iRowDelegate+1);

			for(size_t jColDelegate=1;jColDelegate<=max_DelegateColIndex;++jColDelegate)
			{
				std::pair<size_t,size_t> gDelegate_cell(iRowDelegate,jColDelegate);
				if( std::find(truncated_cells.begin(),truncated_cells.end(),gDelegate_cell) == truncated_cells.end() )
				{
						std::pair<size_t,size_t> gDelegate_cell(iRowDelegate,jColDelegate);
						gMatrixMapping.reset_gDelegate(empty_delegate_matrix(iRowDelegate,jColDelegate) , gDelegate_cell);

						std::ostringstream local_gDelegate_file; 
						local_gDelegate_file<< "test_TruncatedCascadeResetGMatrixMapping_reset_"<<iRowDelegate<<"row_"<< jColDelegate<<"col"  <<".csv";
						gMatrixMapping.print( local_gDelegate_file.str() );	
				}
			}	
		}
	}
}
开发者ID:JBLMM,项目名称:LMM,代码行数:67,代码来源:Test_GMatrixMapping.cpp

示例8: test_TruncatedGlobalResetGMatrixMapping

void test_TruncatedGlobalResetGMatrixMapping()
{
	{
		size_t nbYear = 6;
		Tenor tenorfixedleg = Tenor::_1YR;
		Tenor tenorfloatleg = Tenor::_6M;
		const double increment_matrix = 10;

		LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

		size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
		size_t horizon = pLmmTenorStructure->get_horizon() ;

		size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
		size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

		UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

		Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

		UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

		GMatrixMapping gMatrixMapping(
			g_matrix_size
			, empty_delegate_matrix
			, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

		std::vector<std::pair<size_t,size_t> > truncated_cells;
		truncated_cells.push_back( std::pair<size_t,size_t>(1,1) );
		truncated_cells.push_back( std::pair<size_t,size_t>(1,5) );
		truncated_cells.push_back( std::pair<size_t,size_t>(5,1) );
				
		for(size_t iCell=0;iCell<truncated_cells.size();++iCell)
		{
			gMatrixMapping.add_Truncated_gDelegate_Cells( truncated_cells[iCell] );
		}

		QuantLib::Array x = gMatrixMapping.get_DelegateArray();

		for(size_t i=0;i<x.size();++i){ x[i]=(1+i)*0.1;}
			
		gMatrixMapping.reset_gDelegate(x);

		gMatrixMapping.print("test_TruncatedGlobalResetGMatrixMapping_Extrapolation.csv");
	}

		{
		size_t nbYear = 6;
		Tenor tenorfixedleg = Tenor::_1YR;
		Tenor tenorfloatleg = Tenor::_6M;
		const double increment_matrix = 10;

		LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

		size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);
		size_t horizon = pLmmTenorStructure->get_horizon() ;

		size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
		size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(horizon,fixedfloatRatio );

		UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

		Initiate_UpperTriangularDoubleMatrix(empty_delegate_matrix, increment_matrix);

		UpperTriangleVanillaSwaptionQuotes_ConstPTR atm_swaption_implied_vol_ptr = create_UpperTriangleVanillaSwaptionQuotes(pLmmTenorStructure, tenorfixedleg, tenorfloatleg);

		GMatrixMapping gMatrixMapping(
			g_matrix_size
			, empty_delegate_matrix
			, atm_swaption_implied_vol_ptr->get_UpperTriangularIndexPairMatrix() );

		std::vector<std::pair<size_t,size_t> > truncated_cells;
		truncated_cells.push_back( std::pair<size_t,size_t>(2,2) );
		truncated_cells.push_back( std::pair<size_t,size_t>(1,3) );
		truncated_cells.push_back( std::pair<size_t,size_t>(3,1) );
		truncated_cells.push_back( std::pair<size_t,size_t>(3,3) );

		for(size_t iCell=0;iCell<truncated_cells.size();++iCell)
		{
			gMatrixMapping.add_Truncated_gDelegate_Cells( truncated_cells[iCell] );
		}

		QuantLib::Array x = gMatrixMapping.get_DelegateArray();

		for(size_t i=0;i<x.size();++i){ x[i]=(1+i)*0.1;}
			
		gMatrixMapping.reset_gDelegate(x);

		gMatrixMapping.print("test_TruncatedGlobalResetGMatrixMapping_Interpolation.csv");
	}


	//{
	//	size_t nbYear = 6;
	//	Tenor tenorfixedleg = Tenor::_1YR;
	//	Tenor tenorfloatleg = Tenor::_6M;
	//	const double increment_matrix = 10;

	//	LMMTenorStructure_PTR pLmmTenorStructure( new LMMTenorStructure(tenorfloatleg, nbYear) );

//.........这里部分代码省略.........
开发者ID:JBLMM,项目名称:LMM,代码行数:101,代码来源:Test_GMatrixMapping.cpp

示例9: Test_McGeneticSwapLMMPricer

void Test_McGeneticSwapLMMPricer()
{

	//! Parameters
	double	strike			=	0.02;
	LMM::Index	indexStart	=	0;
	LMM::Index	indexEnd	=	20;
	Tenor	floatingTenor	=	Tenor::_6M;
	Tenor	fixedTenor		=	Tenor::_12M;
	Tenor	tenorStruture	=	Tenor::_6M;
	size_t	horizonYear		=	10;
	LMMTenorStructure_PTR lmmTenorStructure( new LMMTenorStructure(tenorStruture, horizonYear));

	cout	<<	"strike:                        "	<<	strike												<<	endl;
	cout	<<	"indexStart:                    "	<<	indexStart											<<	endl;
	cout	<<	"indexEnd:                      "	<<	indexEnd											<<	endl;
	cout	<<	"tenorStrutureYearFraction:     "	<<	lmmTenorStructure->get_tenorType().YearFraction()	<<	endl;
	cout	<<	"floatingVStenorStrutureRatio:  "	<<	floatingTenor.ratioTo(tenorStruture)				<<	endl;
	cout	<<	"fixedVStenorStrutureRatio:     "	<<	fixedTenor.ratioTo(tenorStruture)					<<	endl;

	double	fwdRate		=	0.02;
	std::vector<double> liborsInitValue(lmmTenorStructure->get_horizon()+1, fwdRate);
	cout	<<	"myInitialLibor:  ";
	for (size_t i = 0; i <liborsInitValue.size(); i++)
	{
		cout	<<	liborsInitValue[i]	<<	" ";
	}
	cout	<<	 endl;
	cout	<<	 endl;


	//VanillaSwap_Chi_Trang
	VanillaSwap firstVersionVanillaSwap(strike, indexStart , indexEnd, floatingTenor, fixedTenor, lmmTenorStructure);
	LmmVanillaSwapPricer myVSP(lmmTenorStructure);
	double FirstVersionSwapPrice	=	myVSP.swapNPV_Analytical_1(firstVersionVanillaSwap, liborsInitValue);

	//---------------------------Build Lmm and McLmm's structure--------------------------------------
	//! Parameter of h
	double a = -0.06;
	double b = 0.17;
	double c = 0.54;
	double d = 0.17;
	Shifted_HGVolatilityParam::ABCDParameter abcdParam (a,b,c,d);
	//Parameter of hg
	double g_constParam = 1.0;
	double shift_constParam = -0.01;
	ConstShifted_HGVolatilityParam_PTR hgParam( new ConstShifted_HGVolatilityParam(lmmTenorStructure,abcdParam,g_constParam,shift_constParam));
	
	//! Correlation 1
	size_t nbFactor       = 3; // need to test nbFactor  = 3, and nbFactor = 
	size_t correlFullRank = lmmTenorStructure->get_horizon()+1;
	size_t correlReducedRank = nbFactor;
	//!"Check Parameters(): Condition not implemented yet."
	std::cout << "checkParams(): ";
	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.
	correlation->print("test_McTerminalLmm_Correlation.csv");
	//hgVolatilityFunction
	ConstShifted_HGVolatilityFunction_PTR hgVolatilityFunction (new ConstShifted_HGVolatilityFunction(lmmTenorStructure, correlation, hgParam)); 
	hgVolatilityFunction->print("test_McTerminalLmm_Volatility.csv");
	//! Dispersion
	Dispersion dispersion(hgVolatilityFunction);

	unsigned long seed = 5033;
	RNGenerator_PTR  rnGenerator(new McGenerator(seed));

	//build lmm and mcLmm model
	Lmm_PTR shiftedLmm (new Lmm(dispersion));
	McLmm_PTR mcLmm(new McTerminalLmm(shiftedLmm, liborsInitValue, rnGenerator, MCSchemeType::EULER));

	//build a McGeneticSwapLMMPricer
	McGeneticSwapLMMPricer_PTR mcGeneticSwapLMMPricer(new McGeneticSwapLMMPricer(mcLmm));

	//build the geneticVanillaSwap
	GeneticSwap_CONSTPTR vanillaSwap_Genetic=InstrumentFactory::createVanillaSwap(
			strike,indexStart,indexEnd,floatingTenor,fixedTenor,lmmTenorStructure,1.0);

	//use Monte Carlo Method
	size_t nbSimulation=10000;
	double	MonteCarloPrice		=	mcGeneticSwapLMMPricer->swapNPV(vanillaSwap_Genetic, nbSimulation);

	//ordinaryGeneticVanillaSwapPricer
	GeneticVanillaSwapPricer_PTR geneticVanillaSwapPricer(new GeneticVanillaSwapPricer());
	double	OrdinaryGeneticVanillaSwapPrice		=	geneticVanillaSwapPricer->geneticVanillaSwap_Analytical(vanillaSwap_Genetic,liborsInitValue);

	//subVanillaSwap
	LMM::Index	subIndexStart	=	10;
	LMM::Index	subIndexEnd		=	16;
	GeneticSwap_CONSTPTR subVanillaSwap_Genetic=InstrumentFactory::createVanillaSwap(
			strike,subIndexStart,subIndexEnd,floatingTenor,fixedTenor,lmmTenorStructure,1.0);
	double	subMonteCarloPrice	=	mcGeneticSwapLMMPricer->swapNPV(subVanillaSwap_Genetic, nbSimulation);
	//subOrdinaryGeneticVanillaSwapPrice
	double	subOrdinaryGeneticVanillaSwapPrice		=	geneticVanillaSwapPricer->geneticVanillaSwap_Analytical(subVanillaSwap_Genetic,liborsInitValue);
	//subFirstVersionVanillaSwapPrice
	VanillaSwap subFirstVersionVanillaSwap(strike, subIndexStart , subIndexEnd, floatingTenor, fixedTenor, lmmTenorStructure);
	double subFirstVersionSwapPrice		=	myVSP.swapNPV_Analytical_1(subFirstVersionVanillaSwap, liborsInitValue);

//.........这里部分代码省略.........
开发者ID:JBLMM,项目名称:JBLMM,代码行数:101,代码来源:Test_McGeneticSwapLMMPricer.cpp

示例10: marketData_LMM_Local_gCalibration

void marketData_LMM_Local_gCalibration( const LmmCalibrationConfig& config
									   , LmmSwaptionMarketData_PTR pLmmSwaptionMarketData 
									   , const QuantLib::Array& abcd_param 
									   , Correlation_PTR found_correlation_ptr  
									   , GMatrixMapping_PTR init_gMapping 
									   )
{
	assert(config.use_local_calib_);
	size_t nbYear = pLmmSwaptionMarketData->get_nbYear();
	std::string base_file_name = pLmmSwaptionMarketData->get_MarketDataBaseFileName();

	Tenor tenorfixedleg = Tenor::_1YR ;
	Tenor tenorfloatleg = Tenor::_6M  ;
	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);

	std::string base_name;
	base_name = base_file_name+"_gMatrixLocalCalibration" ;

	//create LMM components
	LMMTenorStructure_PTR pLMMTenorStructure( new LMMTenorStructure(tenorfloatleg,nbYear) );

	const double a=abcd_param[0];
	const double b=abcd_param[1];
	const double c=abcd_param[2];
	const double d=abcd_param[3];

	Shifted_HGVolatilityParam::ABCDParameter abcdParam(a,b,c,d);
	ConstShifted_HGVolatilityParam_PTR pNoShifted_HGVolatilityParam( new ConstShifted_HGVolatilityParam(pLMMTenorStructure, abcdParam, 1., 0.));

	Shifted_HGVolatilityFunction_PTR pVolatilityFunction (new ConstShifted_HGVolatilityFunction(pLMMTenorStructure, found_correlation_ptr , pNoShifted_HGVolatilityParam)); 
	Dispersion dispersion(pVolatilityFunction);
	Lmm_PTR lmm_ptr(new Lmm(dispersion) );

	LmmVanillaSwaptionApproxPricer_Rebonato_PTR pLmmVanillaSwaptionApproxPricer_Rebonato(new LmmVanillaSwaptionApproxPricer_Rebonato(lmm_ptr));	

	// create gMatrixMapping
	size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
	size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(pLMMTenorStructure->get_horizon() ,fixedfloatRatio );
	UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

	GMatrixMapping_PTR pGMatrixMapping;
	if(init_gMapping)
	{
		pGMatrixMapping = init_gMapping;
	}
	else
	{
		//initiate gMatrixMapping all gDelegate to 1
		pGMatrixMapping.reset( new GMatrixMapping(g_matrix_size, empty_delegate_matrix, pLmmSwaptionMarketData->get_SwaptionQuotes_ATM()->get_UpperTriangularIndexPairMatrix())  );
		QuantLib::Array g_delegate_vector =  pGMatrixMapping->get_DelegateArray();
		for(size_t i=0;i<g_delegate_vector.size();++i) g_delegate_vector[i] = 1.;
		pGMatrixMapping->reset_gDelegate(g_delegate_vector);
	}

	pNoShifted_HGVolatilityParam->reset_g_matrix( pGMatrixMapping->get_g_Ref() );
	pLmmVanillaSwaptionApproxPricer_Rebonato->update_VolatilityParam(pNoShifted_HGVolatilityParam);

	LmmBaseCostFunction_PTR pLmmCostFunction(new LmmLocal_gCostFunction
		(
		pLmmVanillaSwaptionApproxPricer_Rebonato,
		pLmmSwaptionMarketData->get_LiborQuotes(),
		pLmmSwaptionMarketData->get_SwaptionQuotes_ATM(),
		pGMatrixMapping,
		pNoShifted_HGVolatilityParam
		) );

	//costumize swaptions weights
	UpperTriangularDoubleMatrix swpm_weight_matrix = pLmmCostFunction->get_SwaptionWeightMatrix();
	//swpm_weight_matrix(7,1)=1e-6;
	//swpm_weight_matrix(10,1)=1e-6;
	//swpm_weight_matrix(5,3)=0.;
	pLmmCostFunction->reset_SwaptionWeightMatrix(swpm_weight_matrix);

	// Create Calibrator
	LmmLocal_gCalibrator lmmCalibrator
		(
		*pGMatrixMapping.get()
		, 3000 //maxIter
		, 1e-11   //x_epsilon
		, 1e-11   //f_epsilon    
		, pLmmCostFunction
		);

	if(config.use_positive_constraint_)
		lmmCalibrator.activate_PositiveConstraint();

	lmmCalibrator.solve();

	std::ostringstream file_result_stream;file_result_stream<<base_name<<"_result.csv";
	std::string file_calibration_result(file_result_stream.str());
	lmmCalibrator.printPlusPlus(file_calibration_result);

	std::ostringstream file_gDelegate_stream;file_gDelegate_stream<<base_name<<"_gDelegate.csv";
	std::string file_gDelegate_vol(file_gDelegate_stream.str() );
	pGMatrixMapping->print(file_gDelegate_vol);

	std::ostringstream file_vol_stream;file_vol_stream<<base_name<<"_vol.csv";
	std::string file_calibrated_vol(file_vol_stream.str() );
	pNoShifted_HGVolatilityParam->print( file_calibrated_vol );

//.........这里部分代码省略.........
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:101,代码来源:Test.cpp

示例11: Test_evaluation_basis

void Test_evaluation_basis()
{
	LMM::Index  indexStart = 2;		//1Y
	LMM::Index  indexEnd   = 20;		//10Y
	Tenor	floatingLegTenorType = Tenor::_6M;
	Tenor	fixedLegTenorType    = Tenor::_1YR;
	assert(indexStart%2==0&&indexEnd%2==0);
	LMMTenorStructure_PTR lmmTenorStructure( new LMMTenorStructure(floatingLegTenorType, indexEnd/2));

	std::vector<std::string> mkt_file_list = InputFileManager::get_VCUB_FileList();
	const std::string& mkt_data_file = mkt_file_list.back();
	std::string folder_name;   // = "TotalCalib\\" ;  config.use_positive_constraint_=true;
	std::string base_name_file = LMMPATH::get_BaseFileName(mkt_data_file) + "\\";
	folder_name+=base_name_file;
	LMMPATH::reset_Output_SubFolder(folder_name );

	LmmCalibrationConfig config;

	config.floatLegTenor_=floatingLegTenorType;
	config.fixedLegTenor_=fixedLegTenorType;

	config.model_nbYear_		=	indexEnd/2;
	size_t fixedFloatRatio		=	config.fixedLegTenor_.ratioTo(config.floatLegTenor_);
	config.correl_FullRank_		=	fixedFloatRatio*config.model_nbYear_+1;

	LmmSwaptionMarketData_PTR pLmmSwaptionMarketData	=	get_LmmSwaptionMarketData(config, mkt_data_file);
	const std::vector<double>&	initLiborValues			=	pLmmSwaptionMarketData->get_LiborQuotes()->get_InitLibor();

	double strike = 0.0137;

	std::vector<LMM::Index> exerciseDates;
	exerciseDates.push_back(2);
	//exerciseDates.push_back(4);
	//exerciseDates.push_back(6);
	//exerciseDates.push_back(8);
	//exerciseDates.push_back(10);
	//exerciseDates.push_back(12);
	//exerciseDates.push_back(14);
	//exerciseDates.push_back(16);
	//exerciseDates.push_back(18);
	exerciseDates.push_back(20);

	McLmm_PTR mcLmm_for_pricer = getMcLmmExample(lmmTenorStructure, initLiborValues, LmmCalibrationConfig());

	size_t fixedFloatingRatio = fixedLegTenorType.ratioTo(floatingLegTenorType);

	std::vector<std::vector<size_t>> subset;
	for(size_t i = 0; i <= 2; i++) 
	{
		subset.push_back(std::vector<size_t>());
		subset.back().push_back(0);
		subset.back().push_back(0);
		subset.back().push_back(i);							
	}
	//for(size_t j = 1; j <= 2; j++) 
	//{
	//	subset.push_back(std::vector<size_t>());
	//	subset.back().push_back(0);
	//	subset.back().push_back(j);
	//	subset.back().push_back(0);
	//}	
/*	for(size_t k = 1; k <= 2; k++) 
	{
		subset.push_back(std::vector<size_t>());
		subset.back().push_back(k);
		subset.back().push_back(0);
		subset.back().push_back(0);
	}	*/			



	size_t regressionIndex=2;
	LMM::Index liborIndex	= indexStart + regressionIndex*fixedFloatingRatio;
	LMM::Index paymentIndex = indexStart + regressionIndex*fixedFloatingRatio + 1;

	VanillaSwap vanillaSwap(	strike, 
								liborIndex, 
								indexEnd, 
								floatingLegTenorType, 
								fixedLegTenorType, 
								lmmTenorStructure);
		
	std::vector<Basis_CONSTPTR> basis_vect;
	std::vector<Basis_Evaluator_CONSTPTR> basis_evaluator_vect;

	for(size_t basisIndex = 0; basisIndex<subset.size(); basisIndex++)
	{
			basis_vect.push_back(getBasis(subset[basisIndex], 1.0, vanillaSwap, strike, liborIndex));
			basis_evaluator_vect.push_back(getBasisEvaluator(subset[basisIndex], McLmmVanillaSwapPricer(mcLmm_for_pricer)));	
	}

	LS::Regression rg(LS::RegressionRepresentation(basis_vect, basis_evaluator_vect));

	McLmm_PTR mcLmm = getMcLmmExample(lmmTenorStructure, initLiborValues, LmmCalibrationConfig());
	McLmm_LS mcLmm_LS(mcLmm);
	mcLmm_LS.simulateLMM(1);

	size_t nb = 30000;
	clock_t startTime = clock();
	std::vector<std::vector<double>> vect(nb);
//.........这里部分代码省略.........
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:101,代码来源:Test_evaluation_basis.cpp

示例12: JB_marketData_LMM_ABCD_calibration

Shifted_HGVolatilityFunction_PTR JB_marketData_LMM_ABCD_calibration(const LmmCalibrationConfig& config, LmmSwaptionMarketData_PTR pLmmSwaptionMarketData)
{
	std::string base_name = pLmmSwaptionMarketData->get_MarketDataBaseFileName() ;

	size_t nbYear = pLmmSwaptionMarketData->get_nbYear();
	Tenor tenorfixedleg = Tenor::_1YR ;      // A corriger
	Tenor tenorfloatleg = Tenor::_6M  ;
	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);

	//create LMM components
	LMMTenorStructure_PTR pLMMTenorStructure( new LMMTenorStructure(tenorfloatleg,nbYear) );


	ConstShifted_HGVolatilityParam_PTR pNoShifted_HGVolatilityParam( new ConstShifted_HGVolatilityParam(pLMMTenorStructure, config.vol_abcd_ , 1., 0.));

	//! create correlation
	Correlation_PTR pCorrelation = JB_create_InitCorrelation(config);

	Shifted_HGVolatilityFunction_PTR pVolatilityFunction (new ConstShifted_HGVolatilityFunction(pLMMTenorStructure, pCorrelation, pNoShifted_HGVolatilityParam)); 
	Dispersion dispersion(pVolatilityFunction);
	Lmm_PTR lmm_ptr(new Lmm(dispersion) );

	//! Create Approximation Rebonato 
	LmmVanillaSwaptionApproxPricer_Rebonato_PTR pLmmVanillaSwaptionApproxPricer_Rebonato(new LmmVanillaSwaptionApproxPricer_Rebonato(lmm_ptr));	

	pLmmVanillaSwaptionApproxPricer_Rebonato->update_VolatilityParam(pNoShifted_HGVolatilityParam);

	LmmBaseCostFunction_PTR abcd_costFucntion (new LmmABCDCostFunction ( pLmmVanillaSwaptionApproxPricer_Rebonato
		, pLmmSwaptionMarketData->get_LiborQuotes()
		, pLmmSwaptionMarketData->get_SwaptionQuotes_ATM()
		, pNoShifted_HGVolatilityParam
		));

	QuantLib::Array init_abcd(4);
	init_abcd[0]=config.vol_abcd_.a_;
	init_abcd[1]=config.vol_abcd_.b_;
	init_abcd[2]=config.vol_abcd_.c_;
	init_abcd[3]=config.vol_abcd_.d_;

	size_t maxIterations = 1000;
	size_t minStatIterations = 100;
	double rootEpsilon =1e-14;
	double functionEpsilon =1e-14;
	double gradientNormEpsilon =0;

	LmmABCDCalibrator  lmm_abcd_calibrator(init_abcd, maxIterations, rootEpsilon,functionEpsilon,abcd_costFucntion);


	lmm_abcd_calibrator.add_ConstraintCell(std::pair<size_t,size_t>(1,1) );
	lmm_abcd_calibrator.add_ConstraintCell(std::pair<size_t,size_t>(2,2) );
	lmm_abcd_calibrator.add_ConstraintCell(std::pair<size_t,size_t>(1,3) );
	lmm_abcd_calibrator.add_ConstraintCell(std::pair<size_t,size_t>(3,1) );
	//lmm_abcd_calibrator.add_ConstraintCell(std::pair<size_t,size_t>(6,6) );
	//lmm_abcd_calibrator.add_ConstraintCell(std::pair<size_t,size_t>(8,8) );

	lmm_abcd_calibrator.activate_PositiveConstraint();
	lmm_abcd_calibrator.solve();

	std::string result_file =base_name + "_abcd_calibration_result.csv";
	lmm_abcd_calibrator.printPlusPlus(result_file);

	std::string calibrated_abcd_file = base_name + "_abcd_calibrated.csv";
	pNoShifted_HGVolatilityParam->print(calibrated_abcd_file);

	// print in a common file
	{
		std::string common_result_file_name = "calib_result_ABCD.csv";
		std::string full_common_result_file = LMMPATH::get_Root_OutputPath() + common_result_file_name ;

		std::ofstream final_result ;
		final_result.open(full_common_result_file.c_str(), std::ios::app);

		final_result<<std::endl<<std::endl<< "============= Test At    "<<LMMPATH::get_TimeDateNow()
			<<",,,,,, Error LInf, "<<lmm_abcd_calibrator.get_QuoteError_LInf() <<std::endl ;
		final_result<< lmm_abcd_calibrator.get_BaseGeneral_Result_Info();

		final_result.close();	
	}
	
	return pVolatilityFunction;
}
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:81,代码来源:JBTest.cpp

示例13: JB_marketData_LMM_shift_Calibration

Shifted_HGVolatilityFunction_PTR JB_marketData_LMM_shift_Calibration(	const LmmCalibrationConfig& config
											, LmmSwaptionMarketData_PTR pLmmSwaptionMarketData 
											, Shifted_HGVolatilityFunction_PTR param_h_g_function
											)
{
	assert(!config.use_local_calib_);
	size_t  nbYear= pLmmSwaptionMarketData->get_nbYear();
	std::string base_file_name = pLmmSwaptionMarketData->get_MarketDataBaseFileName();

	Tenor tenorfixedleg = Tenor::_1YR ;
	Tenor tenorfloatleg = Tenor::_6M  ;
	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);

	std::string base_name;
	base_name = base_file_name+"_shift_gMatrix_Calibration" ;

	Shifted_HGVolatilityParam_PTR	param_h_g	=	param_h_g_function->get_ShiftedHGVolatilityParam_PTR();

	//create LMM components
	LMMTenorStructure_PTR pLMMTenorStructure( new LMMTenorStructure(tenorfloatleg,nbYear) );
	const double a=param_h_g->get_ABCD().a_;
	const double b=param_h_g->get_ABCD().b_;
	const double c=param_h_g->get_ABCD().c_;
	const double d=param_h_g->get_ABCD().d_;

	Shifted_HGVolatilityParam::ABCDParameter abcdParam(a,b,c,d);

	const Shifted_HGVolatilityParam::LowerTriangularMatrix& gMatrix=param_h_g->get_gMatrix();

	QuantLib::Array shiftValues_QL = param_h_g->get_ArrayFrom_Shift();
	std::vector<double> shiftValues(shiftValues_QL.size());
	for(size_t i=0; i<shiftValues_QL.size(); i++)
		shiftValues[i]=shiftValues_QL[i];
	//const std::vector<double> shiftedVector(gMatrix.size1(), 0.0);

	ConstShifted_HGVolatilityParam_PTR pShifted_HGVolatilityParam( new ConstShifted_HGVolatilityParam(
																pLMMTenorStructure, abcdParam, gMatrix, shiftValues));
	Shifted_HGVolatilityFunction_PTR pShifted_VolatilityFunction (new ConstShifted_HGVolatilityFunction(
										pLMMTenorStructure, param_h_g_function->get_Correlation_PTR(), pShifted_HGVolatilityParam)); 
	Dispersion dispersion(pShifted_VolatilityFunction);
	Lmm_PTR lmm_ptr(new Lmm(dispersion) );

	LmmVanillaSwaptionApproxPricer_Rebonato_PTR pLmmVanillaSwaptionApproxPricer_Rebonato(new LmmVanillaSwaptionApproxPricer_Rebonato(lmm_ptr));	

	// create gMatrixMapping
	//size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
	//size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(pLMMTenorStructure->get_horizon() ,fixedfloatRatio );
	//UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);



	//pShifted_HGVolatilityParam->reset_g_matrix(gMatrix);
	pLmmVanillaSwaptionApproxPricer_Rebonato->update_VolatilityParam(pShifted_HGVolatilityParam);

	// Create const function
	//LmmPenalty_PTR pLmmPenalty(new LmmPenalty(config.penalty_time_homogeneity_,config.penalty_libor_) );

	//LmmBaseCostFunction_PTR pLmmCostFunction(new LmmGlobal_gCostFunction
	//	(
	//	pLmmVanillaSwaptionApproxPricer_Rebonato,
	//	pLmmSwaptionMarketData->get_LiborQuotes(),
	//	pLmmSwaptionMarketData->get_SwaptionQuotes_ATM(),
	//	pGMatrixMapping,
	//	pNoShifted_HGVolatilityParam,
	//	pLmmPenalty
	//	) );

	const double const_rate=0.02;
	const double quoted_strike_bump=0.0001;
	LmmSwaptionMarketData_PTR lmmSwaptionMarketData(new LmmSwaptionMarketData(tenorfixedleg, tenorfloatleg, gMatrix.size1()+3));

	

	LmmSkewCostFunction lmmSkewCostFunction(	pLmmVanillaSwaptionApproxPricer_Rebonato                // pricer  
											   , pLmmSwaptionMarketData->get_LiborQuotes()
											   , quoted_strike_bump
											   , pLmmSwaptionMarketData->get_SwaptionQuotes_skew()// instrument to calibrate 
											   , param_h_g );

	//for(size_t i = 0; i < 3; i++)
	//{
	//	for (size_t j = 1; j < nbYear-i; j++)
	//		{
	//			lmmSkewCostFunction.addContraintCell(std::pair<size_t,size_t>(j,nbYear-i-j));
	//		}
	//}

	//costumize swaptions weights
	//UpperTriangularDoubleMatrix swpm_weight_matrix = pLmmCostFunction->get_SwaptionWeightMatrix();
	//swpm_weight_matrix(7,1)=1e-6;
	//swpm_weight_matrix(10,1)=1e-6;
	//swpm_weight_matrix(5,3)=0.;
	//pLmmCostFunction->reset_SwaptionWeightMatrix(swpm_weight_matrix);

	// Create Calibrator
	QuantLib::Array init_shift(gMatrix.size1(),0.01);
	



//.........这里部分代码省略.........
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:101,代码来源:JBTest.cpp

示例14: JB_marketData_LMM_Global_gCalibration

GMatrix_Vol_gMapping JB_marketData_LMM_Global_gCalibration( const LmmCalibrationConfig& config
															, LmmSwaptionMarketData_PTR pLmmSwaptionMarketData 
															, Shifted_HGVolatilityFunction_PTR shifted_HGVolatilityFunction
															, Correlation_PTR found_correlation_ptr  
															, GMatrixMapping_PTR init_gMapping
															)
{
	assert(!config.use_local_calib_);				//?
	size_t nbYear = pLmmSwaptionMarketData->get_nbYear();				//nbYear
	std::string base_file_name = pLmmSwaptionMarketData->get_MarketDataBaseFileName();			

	Tenor tenorfixedleg = Tenor::_1YR ;     
	Tenor tenorfloatleg = Tenor::_6M  ;
	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);

	std::string base_name;
	base_name = base_file_name+"_gMatrixGlobalCalibration" ;

	Shifted_HGVolatilityParam_PTR shifted_HGVolatilityParam	=	shifted_HGVolatilityFunction->get_ShiftedHGVolatilityParam_PTR();

	//create LMM components
	LMMTenorStructure_PTR pLMMTenorStructure( new LMMTenorStructure(tenorfloatleg,nbYear) );

	const double a=shifted_HGVolatilityParam->get_ABCD().a_;
	const double b=shifted_HGVolatilityParam->get_ABCD().b_;
	const double c=shifted_HGVolatilityParam->get_ABCD().c_;
	const double d=shifted_HGVolatilityParam->get_ABCD().d_;

	QuantLib::Array shiftValues_QL = shifted_HGVolatilityParam->get_ArrayFrom_Shift();
	std::vector<double> shiftValues(shiftValues_QL.size());
	for(size_t i=0; i<shiftValues_QL.size(); i++)
		shiftValues[i]=shiftValues_QL[i];
	const Shifted_HGVolatilityParam::LowerTriangularMatrix pGMatrix(shifted_HGVolatilityParam->get_gMatrix());
	Shifted_HGVolatilityParam::ABCDParameter abcdParam(a,b,c,d);

	ConstShifted_HGVolatilityParam_PTR pShifted_HGVolatilityParam( new ConstShifted_HGVolatilityParam(
				pLMMTenorStructure, abcdParam, pGMatrix, shiftValues));

	Shifted_HGVolatilityFunction_PTR pVolatilityFunction (new ConstShifted_HGVolatilityFunction(pLMMTenorStructure,  found_correlation_ptr, pShifted_HGVolatilityParam)); 
	Dispersion dispersion(pVolatilityFunction);
	Lmm_PTR lmm_ptr(new Lmm(dispersion) );

	LmmVanillaSwaptionApproxPricer_Rebonato_PTR pLmmVanillaSwaptionApproxPricer_Rebonato(new LmmVanillaSwaptionApproxPricer_Rebonato(lmm_ptr));	

	// create gMatrixMapping
	size_t        g_matrix_size = GMatrixMapping::get_gSizeFromNbYear(nbYear,fixedfloatRatio );
	size_t delegate_matrix_size = GMatrixMapping::get_gDelegateSizeFromHorizon(pLMMTenorStructure->get_horizon() ,fixedfloatRatio );
	UpperTriangularDoubleMatrix empty_delegate_matrix(delegate_matrix_size,delegate_matrix_size);

	GMatrixMapping_PTR pGMatrixMapping;
	if(init_gMapping)
	{
		pGMatrixMapping = init_gMapping;
	}
	else
	{
		//initiate gMatrixMapping all gDelegate to 1
		pGMatrixMapping.reset( new GMatrixMapping(g_matrix_size, empty_delegate_matrix, pLmmSwaptionMarketData->get_SwaptionQuotes_ATM()->get_UpperTriangularIndexPairMatrix())  );
		QuantLib::Array g_delegate_vector =  pGMatrixMapping->get_DelegateArray();
		for(size_t i=0;i<g_delegate_vector.size();++i) g_delegate_vector[i] = 1.;
		pGMatrixMapping->reset_gDelegate(g_delegate_vector);
	}

	pShifted_HGVolatilityParam->reset_g_matrix( pGMatrixMapping->get_g_Ref() );
	pLmmVanillaSwaptionApproxPricer_Rebonato->update_VolatilityParam(pShifted_HGVolatilityParam);

	// Create const function
	LmmPenalty_PTR pLmmPenalty(new LmmPenalty(config.penalty_time_homogeneity_,config.penalty_libor_) );

	LmmBaseCostFunction_PTR pLmmCostFunction(new LmmGlobal_gCostFunction
		(
		pLmmVanillaSwaptionApproxPricer_Rebonato,
		pLmmSwaptionMarketData->get_LiborQuotes(),
		pLmmSwaptionMarketData->get_SwaptionQuotes_ATM(),
		pGMatrixMapping,
		pShifted_HGVolatilityParam,
		pLmmPenalty
		) );

	//costumize swaptions weights
	UpperTriangularDoubleMatrix swpm_weight_matrix = pLmmCostFunction->get_SwaptionWeightMatrix();
	//swpm_weight_matrix(7,1)=1e-6;
	//swpm_weight_matrix(10,1)=1e-6;
	//swpm_weight_matrix(5,3)=0.;
	pLmmCostFunction->reset_SwaptionWeightMatrix(swpm_weight_matrix);

	//std::ostringstream file_costfunc_stream;file_costfunc_stream<<base_name<<"Calibration_"<<nbYear<<"YR_pel_time"<<penalty_time_homogene<<"_pel_lib"<<penalty_libor <<"_LmmCostFunction.csv";
	//pLmmCostFunction->print( file_costfunc_stream.str() );

	// Create Calibrator
	LmmGlobal_gCalibrator lmmCalibrator
		(
		*pGMatrixMapping.get()
		, 200 //maxIter
		, 1e-11   //x_epsilon
		, 1e-11   //f_epsilon    
		, pLmmCostFunction
		);

	if(config.use_positive_constraint_)
//.........这里部分代码省略.........
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:101,代码来源:JBTest.cpp

示例15: JB_marketData_LMM_Correlation_calibration

Correlation_PTR JB_marketData_LMM_Correlation_calibration(const LmmCalibrationConfig& config, LmmSwaptionMarketData_PTR pLmmSwaptionMarketData , const QuantLib::Array& found_abcd)
{
	size_t nbYear = pLmmSwaptionMarketData->get_nbYear();                   
	std::string base_name = pLmmSwaptionMarketData->get_MarketDataBaseFileName() ;

	Tenor tenorfixedleg = Tenor::_1YR ;
	Tenor tenorfloatleg = Tenor::_6M  ;
	size_t fixedfloatRatio = tenorfixedleg.ratioTo(tenorfloatleg);

	//create LMM components
	LMMTenorStructure_PTR pLMMTenorStructure( new LMMTenorStructure(tenorfloatleg,nbYear) );

	const double a=found_abcd[0],b=found_abcd[1],c=found_abcd[2],d=found_abcd[3];

	Shifted_HGVolatilityParam::ABCDParameter abcdParam(a,b,c,d);
	ConstShifted_HGVolatilityParam_PTR pNoShifted_HGVolatilityParam( new ConstShifted_HGVolatilityParam(pLMMTenorStructure, abcdParam, 1., 0.));

	//! create correlation
	Correlation_PTR pCorrelation = JB_create_InitCorrelation(config);

	Shifted_HGVolatilityFunction_PTR pVolatilityFunction (new ConstShifted_HGVolatilityFunction(pLMMTenorStructure, pCorrelation, pNoShifted_HGVolatilityParam)); 
	Dispersion dispersion(pVolatilityFunction);
	Lmm_PTR lmm_ptr(new Lmm(dispersion) );

	//! Create Approximation Rebonato 
	LmmVanillaSwaptionApproxPricer_Rebonato_PTR pLmmVanillaSwaptionApproxPricer_Rebonato(new LmmVanillaSwaptionApproxPricer_Rebonato(lmm_ptr));	

	pLmmVanillaSwaptionApproxPricer_Rebonato->update_VolatilityParam(pNoShifted_HGVolatilityParam);

	LmmBaseCostFunction_PTR pLmmCorrelationCostFunction(new LmmCorrelationCostFunction
		(
		pLmmVanillaSwaptionApproxPricer_Rebonato
		, pLmmSwaptionMarketData->get_LiborQuotes()
		, pLmmSwaptionMarketData->get_SwaptionQuotes_ATM()
		, pCorrelation
		) );


	////// Correlation calibrator
	QuantLib::Array xy_correlation_init = pCorrelation->get_ArrayFrom_Correlation();
	QuantLib::Size maxIterations =1000;
	QuantLib::Size minStatIterations =100;
	QuantLib::Real rootEpsilon = 1e-8;
	QuantLib::Real functionEpsilon =  1e-8;


	LmmCorrelationCalibrator lmmCorrelationCalibrator
		(
		xy_correlation_init
		, maxIterations
		, rootEpsilon
		,functionEpsilon
		, pLmmCorrelationCostFunction
		);

	lmmCorrelationCalibrator.solve();

	std::string result_file =base_name + "_correlation_calibration_result.csv";
	lmmCorrelationCalibrator.printPlusPlus(result_file);

	std::string calibrated_correlation_file =base_name + "_correlation_calibrated.csv";
	Correlation_PTR calibrated_correl_ptr = lmmCorrelationCalibrator.get_Found_Correlation() ;
	calibrated_correl_ptr->print(calibrated_correlation_file);

	// print in a common file
	{
		std::string common_result_file_name = "calib_result_Correlation.csv";
		std::string full_common_result_file = LMMPATH::get_Root_OutputPath() + common_result_file_name ;

		std::ofstream final_result ;
		final_result.open(full_common_result_file.c_str(), std::ios::app);

		final_result<<std::endl<<std::endl<< "============= Test At    "<<LMMPATH::get_TimeDateNow()
			<<",,,,,, Error LInf, "<<lmmCorrelationCalibrator.get_QuoteError_LInf() <<std::endl ;
		final_result<< lmmCorrelationCalibrator.get_BaseGeneral_Result_Info();

		final_result.close();	
	}

	return calibrated_correl_ptr ;
}
开发者ID:lunalogicIntern2015,项目名称:LunaLibrary,代码行数:81,代码来源:JBTest.cpp


注:本文中的Tenor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。