QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
capflooredinflationcoupon.cpp
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
22
23namespace QuantLib {
24
26 Rate cap, Rate floor) {
27
28 isCapped_ = false;
29 isFloored_ = false;
30
31 if (gearing_ > 0) {
32 if (cap != Null<Rate>()) {
33 isCapped_ = true;
34 cap_ = cap;
35 }
36 if (floor != Null<Rate>()) {
37 floor_ = floor;
38 isFloored_ = true;
39 }
40 } else {
41 if (cap != Null<Rate>()){
42 floor_ = cap;
43 isFloored_ = true;
44 }
45 if (floor != Null<Rate>()){
46 isCapped_ = true;
47 cap_ = floor;
48 }
49 }
50 if (isCapped_ && isFloored_) {
51 QL_REQUIRE(cap >= floor, "cap level (" << cap <<
52 ") less than floor level (" << floor << ")");
53 }
54 }
55
56
58 const ext::shared_ptr<YoYInflationCoupon>& underlying,
59 Rate cap, Rate floor)
60 : YoYInflationCoupon(underlying->date(),
61 underlying->nominal(),
62 underlying->accrualStartDate(),
63 underlying->accrualEndDate(),
64 underlying->fixingDays(),
65 underlying->yoyIndex(),
66 underlying->observationLag(),
67 underlying->interpolation(),
68 underlying->dayCounter(),
69 underlying->gearing(),
70 underlying->spread(),
71 underlying->referencePeriodStart(),
72 underlying->referencePeriodEnd()),
73 underlying_(underlying), isFloored_(false), isCapped_(false) {
75 registerWith(underlying);
76 }
77
78
80 const ext::shared_ptr<YoYInflationCouponPricer>& pricer) {
81
83 if (underlying_ != nullptr)
84 underlying_->setPricer(pricer);
85 }
86
87
89 return underlying_ != nullptr ? underlying_->rate() : YoYInflationCoupon::rate();
90 }
91
93 Rate swapletRate = underlyingRate();
94
95 auto couponPricer = underlying_ != nullptr ? underlying_->pricer() : pricer();
96
97 if (isFloored_ || isCapped_) {
98 QL_REQUIRE(couponPricer, "pricer not set");
99 }
100
101 Rate floorletRate = isFloored_ ? couponPricer->floorletRate(effectiveFloor()) : 0.0;
102 Rate capletRate = isCapped_? couponPricer->capletRate(effectiveCap()) : 0.0;
103
104 return swapletRate + floorletRate - capletRate;
105 }
106
107
109 if ( (gearing_ > 0) && isCapped_)
110 return cap_;
111 if ( (gearing_ < 0) && isFloored_)
112 return floor_;
113 return Null<Rate>();
114 }
115
116
118 if ( (gearing_ > 0) && isFloored_)
119 return floor_;
120 if ( (gearing_ < 0) && isCapped_)
121 return cap_;
122 return Null<Rate>();
123 }
124
125
127 return (cap_ - spread())/gearing();
128 }
129
130
132 return (floor_ - spread())/gearing();
133 }
134
135
138 }
139
140
142 typedef YoYInflationCoupon super;
143 auto* v1 = dynamic_cast<Visitor<CappedFlooredYoYInflationCoupon>*>(&v);
144
145 if (v1 != nullptr)
146 v1->visit(*this);
147 else
148 super::accept(v);
149 }
150
151}
152
caplet and floorlet pricing for YoY inflation coupons
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
CappedFlooredYoYInflationCoupon(const ext::shared_ptr< YoYInflationCoupon > &underlying, Rate cap=Null< Rate >(), Rate floor=Null< Rate >())
ext::shared_ptr< YoYInflationCoupon > underlying_
void setPricer(const ext::shared_ptr< YoYInflationCouponPricer > &)
Rate effectiveCap() const
effective cap of fixing
Rate underlyingRate() const
this returns the expected rate before cap and floor are applied
Rate effectiveFloor() const
effective floor of fixing
virtual Rate rate() const =0
accrued rate
ext::shared_ptr< InflationCouponPricer > pricer() const
void setPricer(const ext::shared_ptr< InflationCouponPricer > &)
template class providing a null value for a given type.
Definition: null.hpp:59
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:226
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Coupon paying a YoY-inflation type index
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
Spread spread() const
spread paid over the fixing of the underlying index
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Rate
interest rates
Definition: types.hpp:70
inflation-coupon pricers
Definition: any.hpp:37
ext::shared_ptr< BlackVolTermStructure > v