Coverage Report

Created: 2025-08-11 06:28

/src/quantlib/ql/experimental/volatility/abcdatmvolcurve.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) 2007 Cristina Duminuco
5
 Copyright (C) 2007 Ferdinando Ametrano
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
 <http://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 abcdatmvolcurve.hpp
22
    \brief Abcd-interpolated at-the-money (no-smile) interest rate vol curve
23
*/
24
25
#ifndef quantlib_abcd_atm_vol_curve_hpp
26
#define quantlib_abcd_atm_vol_curve_hpp
27
28
#include <ql/experimental/volatility/blackatmvolcurve.hpp>
29
#include <ql/patterns/lazyobject.hpp>
30
#include <ql/math/interpolations/abcdinterpolation.hpp>
31
#include <ql/time/daycounters/actual365fixed.hpp>
32
33
namespace QuantLib {
34
35
    class Quote;
36
37
    //! Abcd-interpolated at-the-money (no-smile) volatility curve
38
    /*! blah blah
39
    */
40
    class AbcdAtmVolCurve : public BlackAtmVolCurve,
41
                            public LazyObject {
42
      public:
43
        //! floating reference date, floating market data
44
        AbcdAtmVolCurve(Natural settlementDays,
45
                        const Calendar& cal,
46
                        const std::vector<Period>& optionTenors,
47
                        const std::vector<Handle<Quote> >& volsHandles,
48
                        std::vector<bool> inclusionInInterpolationFlag = std::vector<bool>(1, true),
49
                        BusinessDayConvention bdc = Following,
50
                        const DayCounter& dc = Actual365Fixed());
51
        //! Returns k adjustment factors for option tenors used in interpolation
52
        std::vector<Real> k() const;
53
        //! Returns k adjustment factor at time t
54
        Real k(Time t) const;
55
        Real a() const;
56
        Real b() const;
57
        Real c() const;
58
        Real d() const;
59
        Real rmsError() const;
60
        Real maxError() const;
61
        EndCriteria::Type endCriteria() const;
62
        //! \name TermStructure interface
63
        //@{
64
        Date maxDate() const override;
65
        //@}
66
        //! \name VolatilityTermStructure interface
67
        //@{
68
        Real minStrike() const override;
69
        Real maxStrike() const override;
70
        //@}
71
        //! \name LazyObject interface
72
        //@{
73
        void update() override;
74
        void performCalculations() const override;
75
        //@}
76
        //! \name some inspectors
77
        //@{
78
        const std::vector<Period>& optionTenors() const;
79
        const std::vector<Period>& optionTenorsInInterpolation() const;
80
        const std::vector<Date>& optionDates() const;
81
        const std::vector<Time>& optionTimes() const;
82
        //@}
83
        //! \name Visitability
84
        //@{
85
        void accept(AcyclicVisitor&) override;
86
        //@}
87
      protected:
88
        //! \name BlackAtmVolCurve interface
89
        //@{
90
        //! spot at-the-money variance calculation (k adjusted)
91
        Real atmVarianceImpl(Time t) const override;
92
        //! spot at-the-money volatility calculation (k adjusted)
93
        Volatility atmVolImpl(Time t) const override;
94
        //@}
95
      private:
96
        void checkInputs() const;
97
        void initializeOptionDatesAndTimes() const;
98
        void initializeVolatilities();
99
        void registerWithMarketData();
100
        void interpolate();
101
102
        Size nOptionTenors_;
103
        std::vector<Period> optionTenors_;
104
        mutable std::vector<Period> actualOptionTenors_;
105
        mutable std::vector<Date> optionDates_;
106
        mutable std::vector<Time> optionTimes_;
107
        mutable std::vector<Time> actualOptionTimes_;
108
        Date evaluationDate_;
109
110
        std::vector<Handle<Quote> > volHandles_;
111
        mutable std::vector<Volatility> vols_;
112
        mutable std::vector<Volatility> actualVols_;
113
114
        mutable std::vector<bool> inclusionInInterpolation_;
115
116
        ext::shared_ptr<AbcdInterpolation> interpolation_;
117
    };
118
119
    // inline
120
121
0
    inline Date AbcdAtmVolCurve::maxDate() const {
122
0
        calculate();
123
0
        return optionDateFromTenor(optionTenors_.back());
124
0
    }
125
126
0
    inline Real AbcdAtmVolCurve::minStrike() const {
127
0
        return QL_MIN_REAL;
128
0
    }
129
130
0
    inline Real AbcdAtmVolCurve::maxStrike() const {
131
0
        return QL_MAX_REAL;
132
0
    }
133
134
0
    inline Real AbcdAtmVolCurve::atmVarianceImpl(Time t) const {
135
0
        Volatility vol = atmVolImpl(t);
136
0
        return vol*vol*t;
137
0
    }
138
139
0
    inline Volatility AbcdAtmVolCurve::atmVolImpl(Time t) const {
140
0
        calculate();
141
0
        return k(t) * (*interpolation_)(t, true);
142
0
    }
143
144
0
    inline const std::vector<Period>& AbcdAtmVolCurve::optionTenors() const {
145
0
         return optionTenors_;
146
0
    }
147
148
0
    inline const std::vector<Period>& AbcdAtmVolCurve::optionTenorsInInterpolation() const {
149
0
        return actualOptionTenors_;
150
0
    }
151
152
    inline
153
0
    const std::vector<Date>& AbcdAtmVolCurve::optionDates() const {
154
0
        return optionDates_;
155
0
    }
156
157
    inline
158
0
    const std::vector<Time>& AbcdAtmVolCurve::optionTimes() const {
159
0
        return optionTimes_;
160
0
    }
161
162
    inline
163
0
    std::vector<Real> AbcdAtmVolCurve::k() const {
164
0
        return interpolation_->k();
165
0
    }
166
167
    inline
168
0
    Real AbcdAtmVolCurve::k(Time t) const {
169
0
        return interpolation_->k(t,actualOptionTimes_.begin(),actualOptionTimes_.end());
170
0
    }
171
172
0
    inline Real AbcdAtmVolCurve::a() const {
173
0
        return interpolation_->a();
174
0
    }
175
176
0
    inline Real AbcdAtmVolCurve::b() const {
177
0
        return interpolation_->b();
178
0
    }
179
180
0
    inline Real AbcdAtmVolCurve::c() const {
181
0
        return interpolation_->c();
182
0
    }
183
184
0
    inline Real AbcdAtmVolCurve::d() const {
185
0
        return interpolation_->d();
186
0
    }
187
188
0
    inline Real AbcdAtmVolCurve::rmsError() const {
189
0
        return interpolation_->rmsError();
190
0
    }
191
0
    inline Real AbcdAtmVolCurve::maxError() const {
192
0
        return interpolation_->maxError();
193
0
    }
194
195
0
    inline EndCriteria::Type AbcdAtmVolCurve::endCriteria() const { 
196
0
        return interpolation_->endCriteria();
197
0
    }
198
}
199
200
#endif