QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
inflationcapfloor.hpp
Go to the documentation of this file.
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 <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 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>
29#include <ql/handle.hpp>
30
31namespace 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 */
56 public:
57 enum Type { Cap, Floor, Collar };
58 class arguments;
59 class engine;
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 Type type() const { return type_; }
73 const std::vector<Rate>& capRates() const { return capRates_; }
74 const std::vector<Rate>& floorRates() const { return floorRates_; }
75 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
86 Real price,
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:
96 std::vector<Rate> capRates_;
97 std::vector<Rate> floorRates_;
98 };
99
100 //! Concrete YoY Inflation cap class
101 /*! \ingroup instruments */
103 public:
105 const std::vector<Rate>& exerciseRates)
107 exerciseRates, std::vector<Rate>()) {}
108 };
109
110 //! Concrete YoY Inflation floor class
111 /*! \ingroup instruments */
113 public:
115 const std::vector<Rate>& exerciseRates)
117 std::vector<Rate>(), exerciseRates) {}
118 };
119
120 //! Concrete YoY Inflation collar class
121 /*! \ingroup instruments */
123 public:
125 const std::vector<Rate>& capRates,
126 const std::vector<Rate>& floorRates)
129 };
130
131
132 //! %Arguments for YoY Inflation cap/floor calculation
134 : public virtual PricingEngine::arguments {
135 public:
138 ext::shared_ptr<YoYInflationIndex> index;
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
154 : public GenericEngine<YoYInflationCapFloor::arguments,
155 YoYInflationCapFloor::results> {};
156
157 std::ostream& operator<<(std::ostream&, YoYInflationCapFloor::Type);
158
159 // inline
160
162 Real,
165 Real,
166 Natural,
168 Volatility) const {
169 QL_FAIL("not implemented yet");
170 }
171
172}
173
174#endif
Concrete cap class.
Definition: capfloor.hpp:108
Concrete collar class.
Definition: capfloor.hpp:128
Concrete date class.
Definition: date.hpp:125
Concrete floor class.
Definition: capfloor.hpp:118
template base class for option pricing engines
Shared handle to an observable.
Definition: handle.hpp:41
Abstract instrument class.
Definition: instrument.hpp:44
Interest-rate term structure.
Arguments for YoY Inflation cap/floor calculation
ext::shared_ptr< YoYInflationIndex > index
base class for cap/floor engines
Base class for yoy inflation cap-like instruments.
virtual Volatility impliedVolatility(Real price, const Handle< YoYInflationTermStructure > &yoyCurve, Volatility guess, Real accuracy=1.0e-4, Natural maxEvaluations=100, Volatility minVol=1.0e-7, Volatility maxVol=4.0) const
implied term volatility
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
const std::vector< Rate > & capRates() const
ext::shared_ptr< YoYInflationCoupon > lastYoYInflationCoupon() const
virtual Rate atmRate(const YieldTermStructure &discountCurve) const
const std::vector< Rate > & floorRates() const
ext::shared_ptr< YoYInflationCapFloor > optionlet(Size n) const
Returns the n-th optionlet as a cap/floor with only one cash flow.
Concrete YoY Inflation cap class.
YoYInflationCap(const Leg &yoyLeg, const std::vector< Rate > &exerciseRates)
Concrete YoY Inflation collar class.
YoYInflationCollar(const Leg &yoyLeg, const std::vector< Rate > &capRates, const std::vector< Rate > &floorRates)
Concrete YoY Inflation floor class.
YoYInflationFloor(const Leg &yoyLeg, const std::vector< Rate > &exerciseRates)
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Globally accessible relinkable pointer.
Abstract instrument class.
Definition: any.hpp:35
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.
Coupon paying a yoy inflation index.