QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
capfloor.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) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2006, 2014 Ferdinando Ametrano
6 Copyright (C) 2006 François du Vignaud
7 Copyright (C) 2006, 2007 StatPro Italia srl
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23/*! \file capfloor.hpp
24 \brief cap and floor class
25*/
26
27#ifndef quantlib_instruments_capfloor_hpp
28#define quantlib_instruments_capfloor_hpp
29
30#include <ql/instrument.hpp>
32#include <ql/handle.hpp>
34
35namespace QuantLib {
36
37 class YieldTermStructure;
38
39 //! Base class for cap-like instruments
40 /*! \ingroup instruments
41
42 \test
43 - the correctness of the returned value is tested by checking
44 that the price of a cap (resp. floor) decreases
45 (resp. increases) with the strike rate.
46 - the relationship between the values of caps, floors and the
47 resulting collars is checked.
48 - the put-call parity between the values of caps, floors and
49 swaps is checked.
50 - the correctness of the returned implied volatility is tested
51 by using it for reproducing the target value.
52 - the correctness of the returned value is tested by checking
53 it against a known good value.
54 */
55 class CapFloor : public Instrument {
56 public:
57 enum Type { Cap, Floor, Collar };
58 class arguments;
59 class engine;
62 std::vector<Rate> capRates,
63 std::vector<Rate> floorRates);
64 CapFloor(Type type, Leg floatingLeg, const std::vector<Rate>& strikes);
65 //! \name Observable interface
66 //@{
67 void deepUpdate() override;
68 //@}
69 //! \name Instrument interface
70 //@{
71 bool isExpired() const override;
72 void setupArguments(PricingEngine::arguments*) const override;
73 //@}
74 //! \name Inspectors
75 //@{
76 Type type() const { return type_; }
77 const std::vector<Rate>& capRates() const { return capRates_; }
78 const std::vector<Rate>& floorRates() const { return floorRates_; }
79 const Leg& floatingLeg() const { return floatingLeg_; }
80
81 Date startDate() const;
82 Date maturityDate() const;
83 ext::shared_ptr<FloatingRateCoupon> lastFloatingRateCoupon() const;
84 //! Returns the n-th optionlet as a new CapFloor with only one cash flow.
85 ext::shared_ptr<CapFloor> optionlet(Size n) const;
86 //@}
87 Rate atmRate(const YieldTermStructure& discountCurve) const;
88 //! implied term volatility
90 Real price,
92 Volatility guess,
93 Real accuracy = 1.0e-4,
94 Natural maxEvaluations = 100,
95 Volatility minVol = 1.0e-7,
96 Volatility maxVol = 4.0,
98 Real displacement = 0.0) const;
99 private:
102 std::vector<Rate> capRates_;
103 std::vector<Rate> floorRates_;
104 };
105
106 //! Concrete cap class
107 /*! \ingroup instruments */
108 class Cap : public CapFloor {
109 public:
111 const std::vector<Rate>& exerciseRates)
113 exerciseRates, std::vector<Rate>()) {}
114 };
115
116 //! Concrete floor class
117 /*! \ingroup instruments */
118 class Floor : public CapFloor {
119 public:
121 const std::vector<Rate>& exerciseRates)
123 std::vector<Rate>(), exerciseRates) {}
124 };
125
126 //! Concrete collar class
127 /*! \ingroup instruments */
128 class Collar : public CapFloor {
129 public:
131 const std::vector<Rate>& capRates,
132 const std::vector<Rate>& floorRates)
134 };
135
136
137 //! %Arguments for cap/floor calculation
139 public:
142 std::vector<Date> startDates;
143 std::vector<Date> fixingDates;
144 std::vector<Date> endDates;
145 std::vector<Time> accrualTimes;
146 std::vector<Rate> capRates;
147 std::vector<Rate> floorRates;
148 std::vector<Rate> forwards;
149 std::vector<Real> gearings;
150 std::vector<Real> spreads;
151 std::vector<Real> nominals;
152 std::vector<ext::shared_ptr<InterestRateIndex> > indexes;
153 void validate() const override;
154 };
155
156 //! base class for cap/floor engines
158 : public GenericEngine<CapFloor::arguments, CapFloor::results> {};
159
160 std::ostream& operator<<(std::ostream&, CapFloor::Type);
161
162}
163
164#endif
Arguments for cap/floor calculation
Definition: capfloor.hpp:138
std::vector< Time > accrualTimes
Definition: capfloor.hpp:145
std::vector< Rate > forwards
Definition: capfloor.hpp:148
std::vector< Date > startDates
Definition: capfloor.hpp:142
std::vector< Real > gearings
Definition: capfloor.hpp:149
std::vector< Rate > floorRates
Definition: capfloor.hpp:147
std::vector< ext::shared_ptr< InterestRateIndex > > indexes
Definition: capfloor.hpp:152
std::vector< Real > nominals
Definition: capfloor.hpp:151
std::vector< Date > endDates
Definition: capfloor.hpp:144
std::vector< Rate > capRates
Definition: capfloor.hpp:146
std::vector< Date > fixingDates
Definition: capfloor.hpp:143
std::vector< Real > spreads
Definition: capfloor.hpp:150
void validate() const override
Definition: capfloor.cpp:278
base class for cap/floor engines
Definition: capfloor.hpp:158
Base class for cap-like instruments.
Definition: capfloor.hpp:55
Volatility impliedVolatility(Real price, const Handle< YieldTermStructure > &disc, Volatility guess, Real accuracy=1.0e-4, Natural maxEvaluations=100, Volatility minVol=1.0e-7, Volatility maxVol=4.0, VolatilityType type=ShiftedLognormal, Real displacement=0.0) const
implied term volatility
Definition: capfloor.cpp:323
ext::shared_ptr< CapFloor > optionlet(Size n) const
Returns the n-th optionlet as a new CapFloor with only one cash flow.
Definition: capfloor.cpp:195
void setupArguments(PricingEngine::arguments *) const override
Definition: capfloor.cpp:210
bool isExpired() const override
returns whether the instrument might have value greater than zero.
Definition: capfloor.cpp:172
const std::vector< Rate > & capRates() const
Definition: capfloor.hpp:77
const Leg & floatingLeg() const
Definition: capfloor.hpp:79
void deepUpdate() override
Definition: capfloor.cpp:271
Date startDate() const
Definition: capfloor.cpp:179
ext::shared_ptr< FloatingRateCoupon > lastFloatingRateCoupon() const
Definition: capfloor.cpp:188
Rate atmRate(const YieldTermStructure &discountCurve) const
Definition: capfloor.cpp:315
Date maturityDate() const
Definition: capfloor.cpp:183
const std::vector< Rate > & floorRates() const
Definition: capfloor.hpp:78
std::vector< Rate > capRates_
Definition: capfloor.hpp:102
std::vector< Rate > floorRates_
Definition: capfloor.hpp:103
Type type() const
Definition: capfloor.hpp:76
Concrete cap class.
Definition: capfloor.hpp:108
Cap(const Leg &floatingLeg, const std::vector< Rate > &exerciseRates)
Definition: capfloor.hpp:110
Concrete collar class.
Definition: capfloor.hpp:128
Collar(const Leg &floatingLeg, const std::vector< Rate > &capRates, const std::vector< Rate > &floorRates)
Definition: capfloor.hpp:130
Concrete date class.
Definition: date.hpp:125
Concrete floor class.
Definition: capfloor.hpp:118
Floor(const Leg &floatingLeg, const std::vector< Rate > &exerciseRates)
Definition: capfloor.hpp:120
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.
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.
Coupon paying a Libor-type index.
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.
volatility types