/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2006 Ferdinando Ametrano Copyright (C) 2006 Katiuscia Manzoni 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 namespace QuantLib { SwaptionVolCube2::SwaptionVolCube2( 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) : SwaptionVolatilityCube(atmVolStructure, optionTenors, swapTenors, strikeSpreads, volSpreads, swapIndexBase, vegaWeightedSmileFit), volSpreadsInterpolator_(nStrikes_), volSpreadsMatrix_(nStrikes_, Matrix(optionTenors.size(), swapTenors.size(), 0.0)) { } void SwaptionVolCube2::performCalculations() const{ //! set volSpreadsMatrix_ by volSpreads_ quotes for (Size i=0; ivalue(); } //! create volSpreadsInterpolator_ for (Size i=0; i SwaptionVolCube2::smileSectionImpl(Time optionTime, Time swapLength) const { Date optionDate = Date(static_cast( optionInterpolator_(optionTime))); Rounding rounder(0); Period swapTenor(static_cast(rounder(swapLength/12.0)), Months); return smileSection(optionDate, swapTenor); } boost::shared_ptr SwaptionVolCube2::smileSection(const Date& optionDate, const Period& swapTenor) const { calculate(); Rate atmForward = atmStrike(optionDate, swapTenor); Volatility atmVol = atmVol_->volatility(optionDate, swapTenor, atmForward); std::pair p = convertDates(optionDate, swapTenor); Real exerciseTimeSqrt = std::sqrt(p.first); std::vector strikes, stdDevs; strikes.reserve(nStrikes_); stdDevs.reserve(nStrikes_); for (Size i=0; i(new InterpolatedSmileSection(p.first, strikes, stdDevs)); } }