/src/quantlib/ql/experimental/volatility/noarbsabrinterpolatedsmilesection.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) 2014 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 noarbsabrinterpolatedsmilesection.hpp |
21 | | \brief noarb sabr interpolating smile section |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_noarbsabr_interpolated_smile_section_hpp |
25 | | #define quantlib_noarbsabr_interpolated_smile_section_hpp |
26 | | |
27 | | #include <ql/handle.hpp> |
28 | | #include <ql/patterns/lazyobject.hpp> |
29 | | #include <ql/termstructures/volatility/smilesection.hpp> |
30 | | #include <ql/experimental/volatility/noarbsabrinterpolation.hpp> |
31 | | #include <ql/time/daycounters/actual365fixed.hpp> |
32 | | |
33 | | namespace QuantLib { |
34 | | |
35 | | class Quote; |
36 | | class NoArbSabrInterpolatedSmileSection : public SmileSection, |
37 | | public LazyObject { |
38 | | public: |
39 | | //! \name Constructors |
40 | | //@{ |
41 | | //! all market data are quotes |
42 | | NoArbSabrInterpolatedSmileSection( |
43 | | const Date& optionDate, |
44 | | Handle<Quote> forward, |
45 | | const std::vector<Rate>& strikes, |
46 | | bool hasFloatingStrikes, |
47 | | Handle<Quote> atmVolatility, |
48 | | const std::vector<Handle<Quote> >& volHandles, |
49 | | Real alpha, |
50 | | Real beta, |
51 | | Real nu, |
52 | | Real rho, |
53 | | bool isAlphaFixed = false, |
54 | | bool isBetaFixed = false, |
55 | | bool isNuFixed = false, |
56 | | bool isRhoFixed = false, |
57 | | bool vegaWeighted = true, |
58 | | ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(), |
59 | | ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>(), |
60 | | const DayCounter& dc = Actual365Fixed()); |
61 | | //! no quotes |
62 | | NoArbSabrInterpolatedSmileSection( |
63 | | const Date& optionDate, |
64 | | const Rate& forward, |
65 | | const std::vector<Rate>& strikes, |
66 | | bool hasFloatingStrikes, |
67 | | const Volatility& atmVolatility, |
68 | | const std::vector<Volatility>& vols, |
69 | | Real alpha, |
70 | | Real beta, |
71 | | Real nu, |
72 | | Real rho, |
73 | | bool isAlphaFixed = false, |
74 | | bool isBetaFixed = false, |
75 | | bool isNuFixed = false, |
76 | | bool isRhoFixed = false, |
77 | | bool vegaWeighted = true, |
78 | | ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(), |
79 | | ext::shared_ptr<OptimizationMethod> method = ext::shared_ptr<OptimizationMethod>(), |
80 | | const DayCounter& dc = Actual365Fixed()); |
81 | | //@} |
82 | | //! \name LazyObject interface |
83 | | //@{ |
84 | | void performCalculations() const override; |
85 | | void update() override; |
86 | | //@} |
87 | | //! \name SmileSection interface |
88 | | //@{ |
89 | | Real minStrike() const override; |
90 | | Real maxStrike() const override; |
91 | | Real atmLevel() const override; |
92 | | //@} |
93 | | Real varianceImpl(Rate strike) const override; |
94 | | Volatility volatilityImpl(Rate strike) const override; |
95 | | //! \name Inspectors |
96 | | //@{ |
97 | | Real alpha() const; |
98 | | Real beta() const; |
99 | | Real nu() const; |
100 | | Real rho() const; |
101 | | Real rmsError() const; |
102 | | Real maxError() const; |
103 | | EndCriteria::Type endCriteria() const; |
104 | | //@} |
105 | | |
106 | | protected: |
107 | | |
108 | | //! Creates the mutable SABRInterpolation |
109 | | void createInterpolation() const; |
110 | | mutable ext::shared_ptr<NoArbSabrInterpolation> noArbSabrInterpolation_; |
111 | | |
112 | | //! Market data |
113 | | const Handle<Quote> forward_; |
114 | | const Handle<Quote> atmVolatility_; |
115 | | std::vector<Handle<Quote> > volHandles_; |
116 | | mutable std::vector<Rate> strikes_; |
117 | | //! Only strikes corresponding to valid market data |
118 | | mutable std::vector<Rate> actualStrikes_; |
119 | | bool hasFloatingStrikes_; |
120 | | |
121 | | mutable Real forwardValue_; |
122 | | mutable std::vector<Volatility> vols_; |
123 | | //! Sabr parameters |
124 | | Real alpha_, beta_, nu_, rho_; |
125 | | //! Sabr interpolation settings |
126 | | bool isAlphaFixed_, isBetaFixed_, isNuFixed_, isRhoFixed_; |
127 | | bool vegaWeighted_; |
128 | | const ext::shared_ptr<EndCriteria> endCriteria_; |
129 | | const ext::shared_ptr<OptimizationMethod> method_; |
130 | | }; |
131 | | |
132 | 0 | inline void NoArbSabrInterpolatedSmileSection::update() { |
133 | 0 | LazyObject::update(); |
134 | 0 | SmileSection::update(); |
135 | 0 | } |
136 | | |
137 | 0 | inline Real NoArbSabrInterpolatedSmileSection::volatilityImpl(Rate strike) const { |
138 | 0 | calculate(); |
139 | 0 | return (*noArbSabrInterpolation_)(strike, true); |
140 | 0 | } |
141 | | |
142 | 0 | inline Real NoArbSabrInterpolatedSmileSection::alpha() const { |
143 | 0 | calculate(); |
144 | 0 | return noArbSabrInterpolation_->alpha(); |
145 | 0 | } |
146 | | |
147 | 0 | inline Real NoArbSabrInterpolatedSmileSection::beta() const { |
148 | 0 | calculate(); |
149 | 0 | return noArbSabrInterpolation_->beta(); |
150 | 0 | } |
151 | | |
152 | 0 | inline Real NoArbSabrInterpolatedSmileSection::nu() const { |
153 | 0 | calculate(); |
154 | 0 | return noArbSabrInterpolation_->nu(); |
155 | 0 | } |
156 | | |
157 | 0 | inline Real NoArbSabrInterpolatedSmileSection::rho() const { |
158 | 0 | calculate(); |
159 | 0 | return noArbSabrInterpolation_->rho(); |
160 | 0 | } |
161 | | |
162 | 0 | inline Real NoArbSabrInterpolatedSmileSection::rmsError() const { |
163 | 0 | calculate(); |
164 | 0 | return noArbSabrInterpolation_->rmsError(); |
165 | 0 | } |
166 | | |
167 | 0 | inline Real NoArbSabrInterpolatedSmileSection::maxError() const { |
168 | 0 | calculate(); |
169 | 0 | return noArbSabrInterpolation_->maxError(); |
170 | 0 | } |
171 | | |
172 | 0 | inline EndCriteria::Type NoArbSabrInterpolatedSmileSection::endCriteria() const { |
173 | 0 | calculate(); |
174 | 0 | return noArbSabrInterpolation_->endCriteria(); |
175 | 0 | } |
176 | | |
177 | 0 | inline Real NoArbSabrInterpolatedSmileSection::minStrike() const { |
178 | 0 | calculate(); |
179 | 0 | return actualStrikes_.front(); |
180 | |
|
181 | 0 | } |
182 | | |
183 | 0 | inline Real NoArbSabrInterpolatedSmileSection::maxStrike() const { |
184 | 0 | calculate(); |
185 | 0 | return actualStrikes_.back(); |
186 | 0 | } |
187 | | |
188 | 0 | inline Real NoArbSabrInterpolatedSmileSection::atmLevel() const { |
189 | 0 | calculate(); |
190 | 0 | return forwardValue_; |
191 | 0 | } |
192 | | |
193 | | |
194 | | } |
195 | | |
196 | | #endif |