/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2006 Giorgio Facchinetti 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 #ifndef SWAPTIONVOLCUBE_VEGAWEIGHTED_TOL #define SWAPTIONVOLCUBE_VEGAWEIGHTED_TOL 15.0e-4 #endif #ifndef SWAPTIONVOLCUBE_TOL #define SWAPTIONVOLCUBE_TOL 100.0e-4 #endif namespace QuantLib { //=======================================================================// // SwaptionVolCube1 // //=======================================================================// SwaptionVolCube1::SwaptionVolCube1( const Handle& atmVolStructure, const std::vector& optionTenors, const std::vector& swapTenors, const std::vector& strikeSpreads, const std::vector > >& volSpreads, const boost::shared_ptr& swapIndexBase, bool vegaWeightedSmileFit, const std::vector > >& parametersGuess, const std::vector& isParameterFixed, bool isAtmCalibrated, const boost::shared_ptr& endCriteria, Real maxErrorTolerance) : SwaptionVolatilityCube(atmVolStructure, optionTenors, swapTenors, strikeSpreads, volSpreads, swapIndexBase, vegaWeightedSmileFit), parametersGuessQuotes_(parametersGuess), isParameterFixed_(isParameterFixed), isAtmCalibrated_(isAtmCalibrated), endCriteria_(endCriteria) { if(maxErrorTolerance != Null()){ maxErrorTolerance_ = maxErrorTolerance; } else{ maxErrorTolerance_ = SWAPTIONVOLCUBE_VEGAWEIGHTED_TOL; if (vegaWeightedSmileFit_) maxErrorTolerance_ = SWAPTIONVOLCUBE_TOL; } registerWithParametersGuess(); } void SwaptionVolCube1::registerWithParametersGuess() { for (Size i=0; i<4; i++) for (Size j=0; jvalue()); } parametersGuess_.updateInterpolators(); //! set marketVolCube_ by volSpreads_ quotes marketVolCube_ = Cube(optionDates_, swapTenors_, optionTimes_, swapLengths_, nStrikes_); Rate atmForward; Volatility vol; for (Size i=0; ivalue() + atmVol_->volatility(optionDates_[j], swapTenors_[k], atmForward); marketVolCube_.setElement(i, j, k, vol); } marketVolCube_.updateInterpolators(); sparseParameters_ = sabrCalibration(marketVolCube_); //parametersGuess_ = sparseParameters_; sparseParameters_.updateInterpolators(); //parametersGuess_.updateInterpolators(); volCubeAtmCalibrated_= marketVolCube_; if(isAtmCalibrated_){ fillVolatilityCube(); denseParameters_ = sabrCalibration(volCubeAtmCalibrated_); denseParameters_.updateInterpolators(); } } SwaptionVolCube1::Cube SwaptionVolCube1::sabrCalibration(const Cube& marketVolCube) const { const std::vector