/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2005, 2006 Klaus Spanderen This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #include "libormarketmodel.hpp" #include "utilities.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace QuantLib; using namespace boost::unit_test_framework; QL_BEGIN_TEST_LOCALS(LiborMarketModelTest) boost::shared_ptr makeIndex(std::vector dates, std::vector rates) { DayCounter dayCounter = Actual360(); RelinkableHandle termStructure; boost::shared_ptr index(new Euribor6M(termStructure)); Date todaysDate = index->fixingCalendar().adjust(Date(4,September,2005)); Settings::instance().evaluationDate() = todaysDate; dates[0] = index->fixingCalendar().advance(todaysDate, index->fixingDays(), Days); termStructure.linkTo(boost::shared_ptr(new ZeroCurve(dates, rates, dayCounter))); return index; } boost::shared_ptr makeIndex() { std::vector dates; std::vector rates; dates.push_back(Date(4,September,2005)); dates.push_back(Date(4,September,2018)); rates.push_back(0.039); rates.push_back(0.041); return makeIndex(dates, rates); } boost::shared_ptr makeCapVolCurve(const Date& todaysDate) { Volatility vols[] = {14.40, 17.15, 16.81, 16.64, 16.17, 15.78, 15.40, 15.21, 14.86}; std::vector dates; std::vector capletVols; boost::shared_ptr process( new LiborForwardModelProcess(10, makeIndex())); for (Size i=0; i < 9; ++i) { capletVols.push_back(vols[i]/100); dates.push_back(process->fixingDates()[i+1]); } return boost::shared_ptr( new CapletVarianceCurve(todaysDate, dates, capletVols, Actual360())); } void teardown() { Settings::instance().evaluationDate() = Date(); } QL_END_TEST_LOCALS(LiborMarketModelTest) void LiborMarketModelTest::testSimpleCovarianceModels() { BOOST_MESSAGE("Testing simple covariance models..."); QL_TEST_BEGIN const Size size = 10; const Real tolerance = 1e-14; Size i; boost::shared_ptr corrModel( new LmExponentialCorrelationModel(size, 0.1)); Matrix recon = corrModel->correlation(0.0) - corrModel->pseudoSqrt(0.0)*transpose(corrModel->pseudoSqrt(0.0)); for (i=0; i tolerance) BOOST_ERROR("Failed to reproduce correlation matrix" << "\n calculated: " << recon[i][j] << "\n expected: " << 0); } } std::vector