/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2006 Ferdinando Ametrano Copyright (C) 2006 François du Vignaud Copyright (C) 2006 Katiuscia Manzoni Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl 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 #include #include #include #include namespace QuantLib { // floating reference date, floating market data SwaptionVolatilityMatrix::SwaptionVolatilityMatrix( const Calendar& cal, const std::vector& optionTenors, const std::vector& swapTenors, const std::vector > >& vols, const DayCounter& dc, BusinessDayConvention bdc) : SwaptionVolatilityDiscrete(optionTenors, swapTenors, 0, cal, dc, bdc), volHandles_(vols), volatilities_(vols.size(), vols.front().size()) { checkInputs(volatilities_.rows(), volatilities_.columns()); registerWithMarketData(); interpolation_ = BilinearInterpolation( swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(), optionTimes_.end(), volatilities_); } // fixed reference date, floating market data SwaptionVolatilityMatrix::SwaptionVolatilityMatrix( const Date& referenceDate, const Calendar& cal, const std::vector& optionTenors, const std::vector& swapTenors, const std::vector > >& vols, const DayCounter& dc, BusinessDayConvention bdc) : SwaptionVolatilityDiscrete(optionTenors, swapTenors, referenceDate, cal, dc, bdc), volHandles_(vols), volatilities_(vols.size(), vols.front().size()) { checkInputs(volatilities_.rows(), volatilities_.columns()); registerWithMarketData(); interpolation_ = BilinearInterpolation( swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(), optionTimes_.end(), volatilities_); } // floating reference date, fixed market data SwaptionVolatilityMatrix::SwaptionVolatilityMatrix( const Calendar& cal, const std::vector& optionTenors, const std::vector& swapTenors, const Matrix& vols, const DayCounter& dc, BusinessDayConvention bdc) : SwaptionVolatilityDiscrete(optionTenors, swapTenors, 0, cal, dc, bdc), volHandles_(vols.rows()), volatilities_(vols.rows(), vols.columns()) { checkInputs(vols.rows(), vols.columns()); // fill dummy handles to allow generic handle-based // computations later on for (Size i=0; i(boost::shared_ptr( new SimpleQuote(vols[i][j]))); } } registerWithMarketData(); interpolation_ = BilinearInterpolation( swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(), optionTimes_.end(), volatilities_); } // fixed reference date, fixed market data SwaptionVolatilityMatrix::SwaptionVolatilityMatrix( const Date& refDate, const Calendar& cal, const std::vector& optionTenors, const std::vector& swapTenors, const Matrix& vols, const DayCounter& dc, BusinessDayConvention bdc) : SwaptionVolatilityDiscrete(optionTenors, swapTenors, refDate, cal, dc, bdc), volHandles_(vols.rows()), volatilities_(vols.rows(), vols.columns()) { checkInputs(vols.rows(), vols.columns()); // fill dummy handles to allow generic handle-based // computations later on for (Size i=0; i(boost::shared_ptr( new SimpleQuote(vols[i][j]))); } } registerWithMarketData(); interpolation_ = BilinearInterpolation( swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(), optionTimes_.end(), volatilities_); } // fixed reference date and fixed market data, option dates SwaptionVolatilityMatrix::SwaptionVolatilityMatrix( const Date& today, const std::vector& optionDates, const std::vector& swapTenors, const Matrix& vols, const DayCounter& dc) : SwaptionVolatilityDiscrete(optionDates, swapTenors, today, Calendar(), dc), volHandles_(vols.rows()), volatilities_(vols.rows(), vols.columns()) { checkInputs(vols.rows(), vols.columns()); // fill dummy handles to allow generic handle-based // computations later on for (Size i=0; i(boost::shared_ptr( new SimpleQuote(vols[i][j]))); } } registerWithMarketData(); interpolation_ = BilinearInterpolation( swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(), optionTimes_.end(), volatilities_); } void SwaptionVolatilityMatrix::performCalculations() const { if (moving_) // check if date recalculation could be avoided initializeOptionDatesAndTimes(); // we might use iterators here... for (Size i=0; ivalue(); } void SwaptionVolatilityMatrix::registerWithMarketData() { for (Size i=0; i SwaptionVolatilityMatrix::smileSectionImpl(Time optionTime, Time swapLength) const { // dummy strike Volatility atmVol = volatility(optionTime, swapLength, 0.05); return boost::shared_ptr(new FlatSmileSection(optionTime, atmVol)); } void SwaptionVolatilityMatrix::checkInputs(Size volRows, Size volsColumns) const { QL_REQUIRE(nOptionTenors_==volRows, "mismatch between number of option dates (" << nOptionTenors_ << ") and number of rows (" << volRows << ") in the vol matrix"); QL_REQUIRE(nSwapTenors_==volsColumns, "mismatch between number of tenors (" << nSwapTenors_ << ") and number of rows (" << volsColumns << ") in the vol matrix"); } }