/src/quantlib/ql/experimental/volatility/extendedblackvariancecurve.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) 2008 Frank Hövermann |
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 extendedblackvariancecurve.hpp |
21 | | \brief Black volatility curve modelled as variance curve |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_extended_black_variance_curve_hpp |
25 | | #define quantlib_extended_black_variance_curve_hpp |
26 | | |
27 | | #include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp> |
28 | | #include <ql/math/interpolation.hpp> |
29 | | #include <ql/handle.hpp> |
30 | | #include <ql/quote.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | //! Black volatility curve modelled as variance curve |
35 | | /*! This class is similar to BlackVarianceCurve, but extends it to |
36 | | use quotes for the input volatilities. |
37 | | */ |
38 | | class ExtendedBlackVarianceCurve : public BlackVarianceTermStructure { |
39 | | public: |
40 | | ExtendedBlackVarianceCurve(const Date& referenceDate, |
41 | | const std::vector<Date>& dates, |
42 | | std::vector<Handle<Quote> > volatilities, |
43 | | DayCounter dayCounter, |
44 | | bool forceMonotoneVariance = true); |
45 | | |
46 | 0 | DayCounter dayCounter() const override { return dayCounter_; } |
47 | | Date maxDate() const override; |
48 | | Real minStrike() const override; |
49 | | Real maxStrike() const override; |
50 | | |
51 | | template <class Interpolator> |
52 | 0 | void setInterpolation(const Interpolator& i = Interpolator()) { |
53 | 0 | varianceCurve_ = i.interpolate(times_.begin(), times_.end(), |
54 | 0 | variances_.begin()); |
55 | 0 | varianceCurve_.update(); |
56 | 0 | notifyObservers(); |
57 | 0 | } |
58 | | |
59 | | void accept(AcyclicVisitor&) override; |
60 | | void update() override; |
61 | | |
62 | | private: |
63 | | Real blackVarianceImpl(Time t, Real) const override; |
64 | | void setVariances(); |
65 | | DayCounter dayCounter_; |
66 | | Date maxDate_; |
67 | | std::vector<Handle<Quote> > volatilities_; |
68 | | std::vector<Time> times_; |
69 | | std::vector<Real> variances_; |
70 | | Interpolation varianceCurve_; |
71 | | bool forceMonotoneVariance_; |
72 | | }; |
73 | | |
74 | 0 | inline Date ExtendedBlackVarianceCurve::maxDate() const { |
75 | 0 | return maxDate_; |
76 | 0 | } |
77 | | |
78 | 0 | inline Real ExtendedBlackVarianceCurve::minStrike() const { |
79 | 0 | return QL_MIN_REAL; |
80 | 0 | } |
81 | | |
82 | 0 | inline Real ExtendedBlackVarianceCurve::maxStrike() const { |
83 | 0 | return QL_MAX_REAL; |
84 | 0 | } |
85 | | |
86 | 0 | inline void ExtendedBlackVarianceCurve::accept(AcyclicVisitor& v) { |
87 | 0 | auto* v1 = dynamic_cast<Visitor<ExtendedBlackVarianceCurve>*>(&v); |
88 | 0 | if (v1 != nullptr) |
89 | 0 | v1->visit(*this); |
90 | 0 | else |
91 | 0 | BlackVarianceTermStructure::accept(v); |
92 | 0 | } |
93 | | } |
94 | | |
95 | | |
96 | | #endif |