1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2013 Peter Caspers 5 6 This file is part of QuantLib, a free-software/open-source library 7 for financial quantitative analysts and developers - http://quantlib.org/ 8 9 QuantLib is free software: you can redistribute it and/or modify it 10 under the terms of the QuantLib license. You should have received a 11 copy of the license along with this program; if not, please email 12 <quantlib-dev@lists.sf.net>. The license is also available online at 13 <http://quantlib.org/license.shtml>. 14 15 This program is distributed in the hope that it will be useful, but WITHOUT 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 FOR A PARTICULAR PURPOSE. See the license for more details. 18 */ 19 20 /*! \file atmadjustedsmilesection.hpp 21 \brief smile section that allows for alternate specification of atm level 22 and recentering the source volatility accordingly 23 */ 24 25 #ifndef quantlib_atm_adjusted_smile_section_hpp 26 #define quantlib_atm_adjusted_smile_section_hpp 27 28 #include <ql/termstructures/volatility/smilesection.hpp> 29 30 namespace QuantLib { 31 32 class AtmAdjustedSmileSection : public SmileSection { 33 34 public: 35 explicit AtmAdjustedSmileSection(const ext::shared_ptr<SmileSection>& source, 36 Real atm = Null<Real>(), 37 bool recenterSmile = false); 38 minStrike() const39 Real minStrike() const { return source_->minStrike(); } maxStrike() const40 Real maxStrike() const { return source_->maxStrike(); } atmLevel() const41 Real atmLevel() const { return f_; } exerciseDate() const42 const Date& exerciseDate() const { return source_->exerciseDate(); } exerciseTime() const43 Time exerciseTime() const { return source_->exerciseTime(); } dayCounter() const44 const DayCounter& dayCounter() const { return source_->dayCounter(); } referenceDate() const45 const Date& referenceDate() const { return source_->referenceDate(); } volatilityType() const46 VolatilityType volatilityType() const { 47 return source_->volatilityType(); 48 } shift() const49 Rate shift() const { return source_->shift(); } 50 optionPrice(Rate strike,Option::Type type=Option::Call,Real discount=1.0) const51 Real optionPrice(Rate strike, Option::Type type = Option::Call, 52 Real discount = 1.0) const { 53 return source_->optionPrice(adjustedStrike(strike), type, discount); 54 } 55 digitalOptionPrice(Rate strike,Option::Type type=Option::Call,Real discount=1.0,Real gap=1.0e-5) const56 Real digitalOptionPrice(Rate strike, Option::Type type = Option::Call, 57 Real discount = 1.0, Real gap = 1.0e-5) const { 58 return source_->digitalOptionPrice(adjustedStrike(strike), type, 59 discount, gap); 60 } 61 vega(Rate strike,Real discount=1.0) const62 Real vega(Rate strike, Real discount = 1.0) const { 63 return source_->vega(adjustedStrike(strike), discount); 64 } 65 density(Rate strike,Real discount=1.0,Real gap=1.0E-4) const66 Real density(Rate strike, Real discount = 1.0, 67 Real gap = 1.0E-4) const { 68 return source_->density(adjustedStrike(strike), discount, gap); 69 } 70 71 protected: 72 73 Real varianceImpl(Rate strike) const; 74 Volatility volatilityImpl(Rate strike) const; 75 76 private: 77 78 Real adjustedStrike(Real strike) const; 79 ext::shared_ptr<SmileSection> source_; 80 Real adjustment_; 81 Real f_; 82 }; 83 } 84 85 #endif 86