/src/quantlib/ql/instruments/inflationcapfloor.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2009 Chris Kenyon |
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 | | <https://www.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 inflationcapfloor.hpp |
21 | | \brief inflation cap and floor class, just year-on-year variety for now |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_instruments_inflationcapfloor_hpp |
25 | | #define quantlib_instruments_inflationcapfloor_hpp |
26 | | |
27 | | #include <ql/instrument.hpp> |
28 | | #include <ql/cashflows/yoyinflationcoupon.hpp> |
29 | | #include <ql/handle.hpp> |
30 | | |
31 | | namespace QuantLib { |
32 | | |
33 | | class YieldTermStructure; |
34 | | |
35 | | //! Base class for yoy inflation cap-like instruments |
36 | | /*! \ingroup instruments |
37 | | |
38 | | Note that the standard YoY inflation cap/floor defined here is |
39 | | different from nominal, because in nominal world standard |
40 | | cap/floors do not have the first optionlet. This is because |
41 | | they set in advance so there is no point. However, yoy |
42 | | inflation generally sets (effectively) in arrears, (actually |
43 | | in arrears vs lag of a few months) thus the first optionlet is |
44 | | relevant. Hence we can do a parity test without a special |
45 | | definition of the YoY cap/floor instrument. |
46 | | |
47 | | \test |
48 | | - the relationship between the values of caps, floors and the |
49 | | resulting collars is checked. |
50 | | - the put-call parity between the values of caps, floors and |
51 | | swaps is checked. |
52 | | - the correctness of the returned value is tested by checking |
53 | | it against a known good value. |
54 | | */ |
55 | | class YoYInflationCapFloor : public Instrument { |
56 | | public: |
57 | | enum Type { Cap, Floor, Collar }; |
58 | | class arguments; |
59 | | class engine; |
60 | | YoYInflationCapFloor(Type type, |
61 | | Leg yoyLeg, |
62 | | std::vector<Rate> capRates, |
63 | | std::vector<Rate> floorRates); |
64 | | YoYInflationCapFloor(Type type, Leg yoyLeg, const std::vector<Rate>& strikes); |
65 | | //! \name Instrument interface |
66 | | //@{ |
67 | | bool isExpired() const override; |
68 | | void setupArguments(PricingEngine::arguments*) const override; |
69 | | //@} |
70 | | //! \name Inspectors |
71 | | //@{ |
72 | 0 | Type type() const { return type_; } |
73 | 0 | const std::vector<Rate>& capRates() const { return capRates_; } |
74 | 0 | const std::vector<Rate>& floorRates() const { return floorRates_; } |
75 | 0 | const Leg& yoyLeg() const { return yoyLeg_; } |
76 | | |
77 | | Date startDate() const; |
78 | | Date maturityDate() const; |
79 | | ext::shared_ptr<YoYInflationCoupon> lastYoYInflationCoupon() const; |
80 | | //! Returns the n-th optionlet as a cap/floor with only one cash flow. |
81 | | ext::shared_ptr<YoYInflationCapFloor> optionlet(Size n) const; |
82 | | //@} |
83 | | virtual Rate atmRate(const YieldTermStructure& discountCurve) const; |
84 | | //! implied term volatility |
85 | | virtual Volatility impliedVolatility( |
86 | | Real price, |
87 | | const Handle<YoYInflationTermStructure>& yoyCurve, |
88 | | Volatility guess, |
89 | | Real accuracy = 1.0e-4, |
90 | | Natural maxEvaluations = 100, |
91 | | Volatility minVol = 1.0e-7, |
92 | | Volatility maxVol = 4.0) const; |
93 | | private: |
94 | | Type type_; |
95 | | Leg yoyLeg_; |
96 | | std::vector<Rate> capRates_; |
97 | | std::vector<Rate> floorRates_; |
98 | | }; |
99 | | |
100 | | //! Concrete YoY Inflation cap class |
101 | | /*! \ingroup instruments */ |
102 | | class YoYInflationCap : public YoYInflationCapFloor { |
103 | | public: |
104 | | YoYInflationCap(const Leg& yoyLeg, |
105 | | const std::vector<Rate>& exerciseRates) |
106 | | : YoYInflationCapFloor(YoYInflationCapFloor::Cap, yoyLeg, |
107 | 0 | exerciseRates, std::vector<Rate>()) {} |
108 | | }; |
109 | | |
110 | | //! Concrete YoY Inflation floor class |
111 | | /*! \ingroup instruments */ |
112 | | class YoYInflationFloor : public YoYInflationCapFloor { |
113 | | public: |
114 | | YoYInflationFloor(const Leg& yoyLeg, |
115 | | const std::vector<Rate>& exerciseRates) |
116 | | : YoYInflationCapFloor(YoYInflationCapFloor::Floor, yoyLeg, |
117 | 0 | std::vector<Rate>(), exerciseRates) {} |
118 | | }; |
119 | | |
120 | | //! Concrete YoY Inflation collar class |
121 | | /*! \ingroup instruments */ |
122 | | class YoYInflationCollar : public YoYInflationCapFloor { |
123 | | public: |
124 | | YoYInflationCollar(const Leg& yoyLeg, |
125 | | const std::vector<Rate>& capRates, |
126 | | const std::vector<Rate>& floorRates) |
127 | | : YoYInflationCapFloor(YoYInflationCapFloor::Collar, yoyLeg, |
128 | 0 | capRates, floorRates) {} |
129 | | }; |
130 | | |
131 | | |
132 | | //! %Arguments for YoY Inflation cap/floor calculation |
133 | | class YoYInflationCapFloor::arguments |
134 | | : public virtual PricingEngine::arguments { |
135 | | public: |
136 | 0 | arguments() : type(YoYInflationCapFloor::Type(-1)) {} |
137 | | YoYInflationCapFloor::Type type; |
138 | | ext::shared_ptr<YoYInflationIndex> index; |
139 | | Period observationLag; |
140 | | std::vector<Date> startDates; |
141 | | std::vector<Date> fixingDates; |
142 | | std::vector<Date> payDates; |
143 | | std::vector<Time> accrualTimes; |
144 | | std::vector<Rate> capRates; |
145 | | std::vector<Rate> floorRates; |
146 | | std::vector<Real> gearings; |
147 | | std::vector<Real> spreads; |
148 | | std::vector<Real> nominals; |
149 | | void validate() const override; |
150 | | }; |
151 | | |
152 | | //! base class for cap/floor engines |
153 | | class YoYInflationCapFloor::engine |
154 | | : public GenericEngine<YoYInflationCapFloor::arguments, |
155 | | YoYInflationCapFloor::results> {}; |
156 | | |
157 | | std::ostream& operator<<(std::ostream&, YoYInflationCapFloor::Type); |
158 | | |
159 | | // inline |
160 | | |
161 | | inline Volatility YoYInflationCapFloor::impliedVolatility( |
162 | | Real, |
163 | | const Handle<YoYInflationTermStructure>&, |
164 | | Volatility, |
165 | | Real, |
166 | | Natural, |
167 | | Volatility, |
168 | 0 | Volatility) const { |
169 | | QL_FAIL("not implemented yet"); |
170 | 0 | } |
171 | | |
172 | | } |
173 | | |
174 | | #endif |