Example #1
0
void Initiate_UpperTriangularDoubleMatrixConstantDiagonal(UpperTriangularDoubleMatrix& upper_matrix, double increment)
{

	const size_t matrix_size = upper_matrix.size1();
	assert( matrix_size == upper_matrix.size2());

	size_t nbSubDiagonal = matrix_size-2;
	size_t nbElement     = nbSubDiagonal*(nbSubDiagonal+1)/2;


	const double max_value = increment*matrix_size;
	double diag_value = max_value;
	size_t element_counter=0;

	for(size_t iDiag=0;iDiag<nbSubDiagonal;++iDiag)
	{
		size_t nbElementOnDiag = iDiag+1;

		for(size_t iElementOnDiag=0;iElementOnDiag<nbElementOnDiag;++iElementOnDiag)
		{
			size_t iRow = nbElementOnDiag-iElementOnDiag;
			size_t jCol = (nbElementOnDiag+1)-iRow;

			upper_matrix(iRow,jCol) = diag_value;

			++element_counter;
		}
		diag_value -= increment;
	}

	assert(element_counter == nbElement);
}
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();
}
Example #3
0
void Initiate_UpperTriangularDoubleMatrix(UpperTriangularDoubleMatrix& matrix, double increment)
{
	size_t nbRow = matrix.size1();
	size_t nbCol = matrix.size2();
	assert(nbRow == nbCol);
	for(size_t k=0;k<nbRow;++k) // empty first row and first column
	{
		matrix(0,k) = -1000000000;
		matrix(k,0) = -1000000000;
	}

	double value_counter = increment;

	for(size_t i=1;i<nbRow;++i)
	{
		for(size_t j=1;j<nbRow-i;++j)
		{
			matrix(i,j)=value_counter;
			value_counter+=increment;
		}
	}
}