Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/termstructures/volatility/swaption/swaptionvoldiscrete.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) 2006 Ferdinando Ametrano
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 swaptionvoldiscrete.hpp
21
    \brief Discretized swaption volatility
22
*/
23
24
#ifndef quantlib_swaption_volatility_discrete_h
25
#define quantlib_swaption_volatility_discrete_h
26
27
#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
28
#include <ql/math/interpolation.hpp>
29
#include <ql/patterns/lazyobject.hpp>
30
31
namespace QuantLib {
32
33
    class SwaptionVolatilityDiscrete : public LazyObject,
34
                                       public SwaptionVolatilityStructure {
35
      public:
36
        SwaptionVolatilityDiscrete(const std::vector<Period>& optionTenors,
37
                                   const std::vector<Period>& swapTenors,
38
                                   Natural settlementDays,
39
                                   const Calendar& cal,
40
                                   BusinessDayConvention bdc,
41
                                   const DayCounter& dc);
42
        SwaptionVolatilityDiscrete(const std::vector<Period>& optionTenors,
43
                                   const std::vector<Period>& swapTenors,
44
                                   const Date& referenceDate,
45
                                   const Calendar& cal,
46
                                   BusinessDayConvention bdc,
47
                                   const DayCounter& dc);
48
        SwaptionVolatilityDiscrete(const std::vector<Date>& optionDates,
49
                                   const std::vector<Period>& swapTenors,
50
                                   const Date& referenceDate,
51
                                   const Calendar& cal,
52
                                   BusinessDayConvention bdc,
53
                                   const DayCounter& dc);
54
        const std::vector<Period>& optionTenors() const;
55
        const std::vector<Date>& optionDates() const;
56
        const std::vector<Time>& optionTimes() const;
57
        const std::vector<Period>& swapTenors() const;
58
        const std::vector<Time>& swapLengths() const;
59
        //@}
60
        //! \name Observer interface
61
        //@{
62
        void update() override;
63
        //@}
64
        //! \name LazyObject interface
65
        //@{
66
        void performCalculations() const override;
67
        //@}
68
        //! additional inspectors
69
        Date optionDateFromTime(Time optionTime) const;
70
71
      protected:
72
        Size nOptionTenors_;
73
        std::vector<Period> optionTenors_;
74
        mutable std::vector<Date> optionDates_;
75
        mutable std::vector<Time> optionTimes_;
76
        mutable Interpolation optionInterpolator_;
77
        mutable std::vector<Real> optionDatesAsReal_;
78
        mutable std::vector<Time> optionInterpolatorTimes_;
79
        mutable std::vector<Real> optionInterpolatorDatesAsReal_;
80
81
        Size nSwapTenors_;
82
        std::vector<Period> swapTenors_;
83
        mutable std::vector<Time> swapLengths_;
84
        mutable Date cachedReferenceDate_;
85
      private:
86
        void checkOptionTenors() const;
87
        void checkOptionDates(const Date& reference) const;
88
        void checkSwapTenors() const;
89
        void initializeOptionDatesAndTimes() const;
90
        void initializeOptionTimes() const;
91
        void initializeSwapLengths() const;
92
    };
93
94
    // inline
95
96
    inline const std::vector<Period>&
97
0
    SwaptionVolatilityDiscrete::optionTenors() const {
98
0
         return optionTenors_;
99
0
    }
100
101
    inline const std::vector<Date>&
102
0
    SwaptionVolatilityDiscrete::optionDates() const {
103
0
        return optionDates_;
104
0
    }
105
106
    inline const std::vector<Time>&
107
0
    SwaptionVolatilityDiscrete::optionTimes() const {
108
0
        return optionTimes_;
109
0
    }
110
111
    inline const std::vector<Period>&
112
0
    SwaptionVolatilityDiscrete::swapTenors() const {
113
0
     return swapTenors_;
114
0
    }
115
116
    inline const std::vector<Time>&
117
0
    SwaptionVolatilityDiscrete::swapLengths() const {
118
0
        return swapLengths_;
119
0
    }
120
121
0
    inline Date SwaptionVolatilityDiscrete::optionDateFromTime(Time optionTime) const {
122
0
        return Date(static_cast<Date::serial_type>(optionInterpolator_(optionTime)));
123
0
    }
124
}
125
126
#endif