/src/quantlib/ql/experimental/basismodels/tenorswaptionvts.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2018 Sebastian Schlenkrich |
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 tenorswaptionvts.hpp |
21 | | \brief swaption volatility term structure based on volatility transformation |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_tenorswaptionvts_hpp |
25 | | #define quantlib_tenorswaptionvts_hpp |
26 | | |
27 | | #include <ql/instruments/swaption.hpp> |
28 | | #include <ql/option.hpp> |
29 | | #include <ql/termstructures/volatility/smilesection.hpp> |
30 | | #include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp> |
31 | | #include <ql/termstructures/yieldtermstructure.hpp> |
32 | | #include <ql/time/date.hpp> |
33 | | #include <utility> |
34 | | |
35 | | namespace QuantLib { |
36 | | |
37 | | class TenorSwaptionVTS : public SwaptionVolatilityStructure { |
38 | | protected: |
39 | | class TenorSwaptionSmileSection : public SmileSection { |
40 | | protected: |
41 | | ext::shared_ptr<SmileSection> baseSmileSection_; |
42 | | Real swapRateBase_; |
43 | | Real swapRateTarg_; |
44 | | Real swapRateFinl_; |
45 | | Real lambda_; |
46 | | Real annuityScaling_; |
47 | | // implement transformation formula |
48 | | Volatility volatilityImpl(Rate strike) const override; |
49 | | |
50 | | public: |
51 | | // constructor includes actual transformation details |
52 | | TenorSwaptionSmileSection(const TenorSwaptionVTS& volTS, |
53 | | Time optionTime, |
54 | | Time swapLength); |
55 | | |
56 | | // further SmileSection interface methods |
57 | 0 | Real minStrike() const override { |
58 | 0 | return baseSmileSection_->minStrike() + swapRateTarg_ - swapRateBase_; |
59 | 0 | } |
60 | 0 | Real maxStrike() const override { |
61 | 0 | return baseSmileSection_->maxStrike() + swapRateTarg_ - swapRateBase_; |
62 | 0 | } |
63 | 0 | Real atmLevel() const override { return swapRateFinl_; } |
64 | | }; |
65 | | |
66 | | Handle<SwaptionVolatilityStructure> baseVTS_; |
67 | | Handle<YieldTermStructure> discountCurve_; |
68 | | |
69 | | ext::shared_ptr<IborIndex> baseIndex_; |
70 | | ext::shared_ptr<IborIndex> targIndex_; |
71 | | Period baseFixedFreq_; |
72 | | Period targFixedFreq_; |
73 | | DayCounter baseFixedDC_; |
74 | | DayCounter targFixedDC_; |
75 | | |
76 | | public: |
77 | | // constructor |
78 | | TenorSwaptionVTS(const Handle<SwaptionVolatilityStructure>& baseVTS, |
79 | | Handle<YieldTermStructure> discountCurve, |
80 | | ext::shared_ptr<IborIndex> baseIndex, |
81 | | ext::shared_ptr<IborIndex> targIndex, |
82 | | const Period& baseFixedFreq, |
83 | | const Period& targFixedFreq, |
84 | | DayCounter baseFixedDC, |
85 | | DayCounter targFixedDC) |
86 | | : SwaptionVolatilityStructure(baseVTS->referenceDate(), |
87 | | baseVTS->calendar(), |
88 | | baseVTS->businessDayConvention(), |
89 | | baseVTS->dayCounter()), |
90 | | baseVTS_(baseVTS), discountCurve_(std::move(discountCurve)), |
91 | | baseIndex_(std::move(baseIndex)), targIndex_(std::move(targIndex)), |
92 | | baseFixedFreq_(baseFixedFreq), targFixedFreq_(targFixedFreq), |
93 | 0 | baseFixedDC_(std::move(baseFixedDC)), targFixedDC_(std::move(targFixedDC)) {} |
94 | | |
95 | | // Termstructure interface |
96 | | |
97 | | //! the latest date for which the curve can return values |
98 | 0 | Date maxDate() const override { return baseVTS_->maxDate(); } |
99 | | |
100 | | // SwaptionVolatility interface |
101 | | |
102 | | //! the minimum strike for which the term structure can return vols |
103 | 0 | Rate minStrike() const override { return baseVTS_->minStrike(); } |
104 | | //! the maximum strike for which the term structure can return vols |
105 | 0 | Rate maxStrike() const override { return baseVTS_->maxStrike(); } |
106 | | |
107 | | |
108 | | // SwaptionVolatilityStructure interface |
109 | | |
110 | | //! the largest length for which the term structure can return vols |
111 | 0 | const Period& maxSwapTenor() const override { return baseVTS_->maxSwapTenor(); } |
112 | | |
113 | | ext::shared_ptr<SmileSection> smileSectionImpl(Time optionTime, |
114 | 0 | Time swapLength) const override { |
115 | 0 | return ext::shared_ptr<SmileSection>( |
116 | 0 | new TenorSwaptionSmileSection(*this, optionTime, swapLength)); |
117 | 0 | } |
118 | | |
119 | 0 | Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override { |
120 | 0 | return smileSectionImpl(optionTime, swapLength)->volatility(strike, Normal, 0.0); |
121 | 0 | } |
122 | | |
123 | | // the methodology is designed for normal volatilities |
124 | 0 | VolatilityType volatilityType() const override { return Normal; } |
125 | | }; |
126 | | |
127 | | } |
128 | | |
129 | | #endif |