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 | SwaptionVolatilityDiscrete::optionTenors() const { |
98 | return optionTenors_; |
99 | } |
100 | |
101 | inline const std::vector<Date>& |
102 | SwaptionVolatilityDiscrete::optionDates() const { |
103 | return optionDates_; |
104 | } |
105 | |
106 | inline const std::vector<Time>& |
107 | SwaptionVolatilityDiscrete::optionTimes() const { |
108 | return optionTimes_; |
109 | } |
110 | |
111 | inline const std::vector<Period>& |
112 | SwaptionVolatilityDiscrete::swapTenors() const { |
113 | return swapTenors_; |
114 | } |
115 | |
116 | inline const std::vector<Time>& |
117 | SwaptionVolatilityDiscrete::swapLengths() const { |
118 | return swapLengths_; |
119 | } |
120 | |
121 | inline Date SwaptionVolatilityDiscrete::optionDateFromTime(Time optionTime) const { |
122 | return Date(static_cast<Date::serial_type>(optionInterpolator_(optionTime))); |
123 | } |
124 | } |
125 | |
126 | #endif |
127 | |