/src/quantlib/ql/termstructures/volatility/optionlet/capletvariancecurve.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) 2005 Klaus Spanderen |
5 | | Copyright (C) 2015 Peter Caspers |
6 | | |
7 | | This file is part of QuantLib, a free-software/open-source library |
8 | | for financial quantitative analysts and developers - http://quantlib.org/ |
9 | | |
10 | | QuantLib is free software: you can redistribute it and/or modify it |
11 | | under the terms of the QuantLib license. You should have received a |
12 | | copy of the license along with this program; if not, please email |
13 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
14 | | <https://www.quantlib.org/license.shtml>. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but WITHOUT |
17 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
18 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | /*! \file capletvariancecurve.hpp |
22 | | \brief caplet variance curve |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_caplet_variance_curve_hpp |
26 | | #define quantlib_caplet_variance_curve_hpp |
27 | | |
28 | | #include <ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp> |
29 | | #include <ql/termstructures/volatility/equityfx/blackvariancecurve.hpp> |
30 | | #include <ql/termstructures/volatility/flatsmilesection.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | class CapletVarianceCurve : public OptionletVolatilityStructure { |
35 | | public: |
36 | | CapletVarianceCurve(const Date &referenceDate, |
37 | | const std::vector< Date > &dates, |
38 | | const std::vector< Volatility > &capletVolCurve, |
39 | | const DayCounter &dayCounter, |
40 | | VolatilityType type = ShiftedLognormal, |
41 | | Real displacement = 0.0); |
42 | | //! \name TermStructure interface |
43 | | //@{ |
44 | | DayCounter dayCounter() const override; |
45 | | Date maxDate() const override; |
46 | | //@} |
47 | | Real minStrike() const override; |
48 | | Real maxStrike() const override; |
49 | | VolatilityType volatilityType() const override; |
50 | | Real displacement() const override; |
51 | | |
52 | | protected: |
53 | | ext::shared_ptr<SmileSection> smileSectionImpl(Time t) const override; |
54 | | Volatility volatilityImpl(Time t, Rate) const override; |
55 | | |
56 | | private: |
57 | | BlackVarianceCurve blackCurve_; |
58 | | VolatilityType type_; |
59 | | Real displacement_; |
60 | | }; |
61 | | |
62 | | inline CapletVarianceCurve::CapletVarianceCurve( |
63 | | const Date &referenceDate, const std::vector< Date > &dates, |
64 | | const std::vector< Volatility > &capletVolCurve, |
65 | | const DayCounter &dayCounter, VolatilityType type, Real displacement) |
66 | | : OptionletVolatilityStructure(referenceDate, Calendar(), Following), |
67 | | blackCurve_(referenceDate, dates, capletVolCurve, dayCounter, false), |
68 | | type_(type), displacement_(displacement) {} |
69 | | |
70 | 0 | inline DayCounter CapletVarianceCurve::dayCounter() const { |
71 | 0 | return blackCurve_.dayCounter(); |
72 | 0 | } |
73 | | |
74 | 0 | inline Date CapletVarianceCurve::maxDate() const { |
75 | 0 | return blackCurve_.maxDate(); |
76 | 0 | } |
77 | | |
78 | 0 | inline Real CapletVarianceCurve::minStrike() const { |
79 | 0 | return blackCurve_.minStrike(); |
80 | 0 | } |
81 | | |
82 | 0 | inline Real CapletVarianceCurve::maxStrike() const { |
83 | 0 | return blackCurve_.maxStrike(); |
84 | 0 | } |
85 | | |
86 | | inline ext::shared_ptr<SmileSection> |
87 | 0 | CapletVarianceCurve::smileSectionImpl(Time t) const { |
88 | | // dummy strike |
89 | 0 | Volatility atmVol = blackCurve_.blackVol(t, 0.05, true); |
90 | 0 | return ext::make_shared<FlatSmileSection>(t, atmVol, dayCounter()); |
91 | 0 | } |
92 | | |
93 | | inline |
94 | 0 | Volatility CapletVarianceCurve::volatilityImpl(Time t, Rate r) const { |
95 | 0 | return blackCurve_.blackVol(t, r, true); |
96 | 0 | } |
97 | | |
98 | 0 | inline VolatilityType CapletVarianceCurve::volatilityType() const { |
99 | 0 | return type_; |
100 | 0 | } |
101 | | |
102 | 0 | inline Real CapletVarianceCurve::displacement() const { |
103 | 0 | return displacement_; |
104 | 0 | } |
105 | | } |
106 | | |
107 | | #endif |