/* -*- 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 "libormarketmodelprocess.hpp" #include "utilities.hpp" #include #include #include #include #include #include #include #include #include #include #include using namespace QuantLib; using namespace boost::unit_test_framework; QL_BEGIN_TEST_LOCALS(LiborMarketModelProcessTest) Size len = 10; boost::shared_ptr makeIndex() { DayCounter dayCounter = Actual360(); std::vector dates; std::vector rates; dates.push_back(Date(4,September,2005)); dates.push_back(Date(4,September,2018)); rates.push_back(0.01); rates.push_back(0.08); RelinkableHandle termStructure( boost::shared_ptr( new ZeroCurve(dates,rates,dayCounter))); boost::shared_ptr index(new Euribor1Y(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 makeCapVolCurve(const Date& todaysDate) { Volatility vols[] = {14.40, 17.15, 16.81, 16.64, 16.17, 15.78, 15.40, 15.21, 14.86, 14.54}; std::vector dates; std::vector capletVols; boost::shared_ptr process( new LiborForwardModelProcess(len+1, makeIndex())); for (Size i=0; i < len; ++i) { capletVols.push_back(vols[i]/100); dates.push_back(process->fixingDates()[i+1]); } return boost::shared_ptr( new CapletVarianceCurve(todaysDate, dates, capletVols, ActualActual())); } boost::shared_ptr makeProcess(const Matrix& volaComp = Matrix()) { Size factors = (volaComp.empty() ? 1 : volaComp.columns()); boost::shared_ptr index = makeIndex(); boost::shared_ptr process( new LiborForwardModelProcess(len, index)); boost::shared_ptr fct( new LfmHullWhiteParameterization( process, makeCapVolCurve(Settings::instance().evaluationDate()), volaComp * transpose(volaComp), factors)); process->setCovarParam(fct); return process; } void teardown() { Settings::instance().evaluationDate() = Date(); } QL_END_TEST_LOCALS(LiborMarketModelProcessTest) void LiborMarketModelProcessTest::testInitialisation() { BOOST_MESSAGE("Testing caplet LMM process initialisation..."); QL_TEST_BEGIN DayCounter dayCounter = Actual360(); RelinkableHandle termStructure( flatRate(Date::todaysDate(), 0.04, dayCounter)); boost::shared_ptr index(new Euribor6M(termStructure)); boost::shared_ptr capletVol(new CapletConstantVolatility(termStructure->referenceDate(), 0.2, termStructure->dayCounter())); Calendar calendar = index->fixingCalendar(); for (Integer daysOffset=0; daysOffset < 1825 /* 5 year*/; daysOffset+=8) { Date todaysDate = calendar.adjust(Date::todaysDate()+daysOffset); Settings::instance().evaluationDate() = todaysDate; Date settlementDate = calendar.advance(todaysDate, index->fixingDays(), Days); termStructure.linkTo(flatRate(settlementDate, 0.04, dayCounter)); LiborForwardModelProcess process(60, index); std::vector