/src/quantlib/ql/termstructures/volatility/atmadjustedsmilesection.hpp
Line | Count | Source |
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 | | <https://www.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 | | |
39 | 0 | Real minStrike() const override { return source_->minStrike(); } |
40 | 0 | Real maxStrike() const override { return source_->maxStrike(); } |
41 | 0 | Real atmLevel() const override { return f_; } |
42 | 0 | const Date& exerciseDate() const override { return source_->exerciseDate(); } |
43 | 0 | Time exerciseTime() const override { return source_->exerciseTime(); } |
44 | 0 | const DayCounter& dayCounter() const override { return source_->dayCounter(); } |
45 | 0 | const Date& referenceDate() const override { return source_->referenceDate(); } |
46 | 0 | VolatilityType volatilityType() const override { return source_->volatilityType(); } |
47 | 0 | Rate shift() const override { return source_->shift(); } |
48 | | |
49 | | Real optionPrice(Rate strike, |
50 | | Option::Type type = Option::Call, |
51 | 0 | Real discount = 1.0) const override { |
52 | 0 | return source_->optionPrice(adjustedStrike(strike), type, discount); |
53 | 0 | } |
54 | | |
55 | | Real digitalOptionPrice(Rate strike, |
56 | | Option::Type type = Option::Call, |
57 | | Real discount = 1.0, |
58 | 0 | Real gap = 1.0e-5) const override { |
59 | 0 | return source_->digitalOptionPrice(adjustedStrike(strike), type, |
60 | 0 | discount, gap); |
61 | 0 | } |
62 | | |
63 | 0 | Real vega(Rate strike, Real discount = 1.0) const override { |
64 | 0 | return source_->vega(adjustedStrike(strike), discount); |
65 | 0 | } |
66 | | |
67 | 0 | Real density(Rate strike, Real discount = 1.0, Real gap = 1.0E-4) const override { |
68 | 0 | return source_->density(adjustedStrike(strike), discount, gap); |
69 | 0 | } |
70 | | |
71 | | protected: |
72 | | Real varianceImpl(Rate strike) const override; |
73 | | Volatility volatilityImpl(Rate strike) const override; |
74 | | |
75 | | private: |
76 | | |
77 | | Real adjustedStrike(Real strike) const; |
78 | | ext::shared_ptr<SmileSection> source_; |
79 | | Real adjustment_; |
80 | | Real f_; |
81 | | }; |
82 | | } |
83 | | |
84 | | #endif |