/* -*- 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 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. */ /*! \file interpolatedsmilesection.hpp \brief Interpolated smile section class */ #ifndef quantlib_interpolated_smile_section_hpp #define quantlib_interpolated_smile_section_hpp #include #include #include #include #include namespace QuantLib { template class InterpolatedSmileSection : public SmileSection, public LazyObject { public: InterpolatedSmileSection( Time expiryTime, const std::vector& strikes, const std::vector >& stdDevHandles, const Interpolator& interpolator = Interpolator(), const DayCounter& dc = Actual365Fixed()); InterpolatedSmileSection( Time expiryTime, const std::vector& strikes, const std::vector& stdDevs, const Interpolator& interpolator = Interpolator(), const DayCounter& dc = Actual365Fixed()); InterpolatedSmileSection( const Date& d, const std::vector& strikes, const std::vector >& stdDevHandles, const DayCounter& dc = Actual365Fixed(), const Interpolator& interpolator = Interpolator(), const Date& referenceDate = Date()); InterpolatedSmileSection( const Date& d, const std::vector& strikes, const std::vector& stdDevs, const DayCounter& dc = Actual365Fixed(), const Interpolator& interpolator = Interpolator(), const Date& referenceDate = Date()); void performCalculations() const; Real variance(Rate strike) const; Volatility volatility(Rate strike) const; Real minStrike () const { return strikes_.front(); }; Real maxStrike () const { return strikes_.back(); }; private: Real exerciseTimeSquareRoot_; std::vector strikes_; std::vector > stdDevHandles_; mutable std::vector vols_; mutable Interpolation interpolation_; }; template InterpolatedSmileSection::InterpolatedSmileSection( Time timeToExpiry, const std::vector& strikes, const std::vector >& stdDevHandles, const Interpolator& interpolator, const DayCounter& dc) : SmileSection(timeToExpiry, dc), exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(strikes), stdDevHandles_(stdDevHandles), vols_(stdDevHandles.size()) { for (Size i=0; i InterpolatedSmileSection::InterpolatedSmileSection( Time timeToExpiry, const std::vector& strikes, const std::vector& stdDevs, const Interpolator& interpolator, const DayCounter& dc) : SmileSection(timeToExpiry, dc), exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(strikes), stdDevHandles_(stdDevs.size()), vols_(stdDevs.size()) { // fill dummy handles to allow generic handle-based // computations later on for (Size i=0; i(boost::shared_ptr(new SimpleQuote(stdDevs[i]))); // check strikes!!!!!!!!!!!!!!!!!!!! interpolation_ = interpolator.interpolate(strikes_.begin(), strikes_.end(), vols_.begin()); } template InterpolatedSmileSection::InterpolatedSmileSection( const Date& d, const std::vector& strikes, const std::vector >& stdDevHandles, const DayCounter& dc, const Interpolator& interpolator, const Date& referenceDate) : SmileSection(d, dc, referenceDate), exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(strikes), stdDevHandles_(stdDevHandles), vols_(stdDevHandles.size()) { for (Size i=0; i InterpolatedSmileSection::InterpolatedSmileSection( const Date& d, const std::vector& strikes, const std::vector& stdDevs, const DayCounter& dc, const Interpolator& interpolator, const Date& referenceDate) : SmileSection(d, dc, referenceDate), exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(strikes), stdDevHandles_(stdDevs.size()), vols_(stdDevs.size()) { //fill dummy handles to allow generic handle-based // computations later on for (Size i=0; i(boost::shared_ptr(new SimpleQuote(stdDevs[i]))); // check strikes!!!!!!!!!!!!!!!!!!!! interpolation_ = interpolator.interpolate(strikes_.begin(), strikes_.end(), vols_.begin()); } template inline void InterpolatedSmileSection::performCalculations() const { for (Size i=0; ivalue()/exerciseTimeSquareRoot_; interpolation_.update(); } #ifndef __DOXYGEN__ template Real InterpolatedSmileSection::variance(Real strike) const { calculate(); Real v = interpolation_(strike, true); return v*v*exerciseTime(); } template Real InterpolatedSmileSection::volatility(Real strike) const { calculate(); return interpolation_(strike, true); } #endif } #endif