QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
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->dayCounter(),
68 underlying->gearing(),
69 underlying->spread(),
70 underlying->referencePeriodStart(),
71 underlying->referencePeriodEnd()),
72 underlying_(underlying), isFloored_(false), isCapped_(false) {
74 registerWith(underlying);
75 }
76
77
79 const ext::shared_ptr<YoYInflationCouponPricer>& pricer) {
80
82 if (underlying_ != nullptr)
83 underlying_->setPricer(pricer);
84 }
85
86
88 return underlying_ != nullptr ? underlying_->rate() : YoYInflationCoupon::rate();
89 }
90
92 Rate swapletRate = underlyingRate();
93
94 auto couponPricer = underlying_ != nullptr ? underlying_->pricer() : pricer();
95
96 if (isFloored_ || isCapped_) {
97 QL_REQUIRE(couponPricer, "pricer not set");
98 }
99
100 Rate floorletRate = isFloored_ ? couponPricer->floorletRate(effectiveFloor()) : 0.0;
101 Rate capletRate = isCapped_? couponPricer->capletRate(effectiveCap()) : 0.0;
102
103 return swapletRate + floorletRate - capletRate;
104 }
105
106
108 if ( (gearing_ > 0) && isCapped_)
109 return cap_;
110 if ( (gearing_ < 0) && isFloored_)
111 return floor_;
112 return Null<Rate>();
113 }
114
115
117 if ( (gearing_ > 0) && isFloored_)
118 return floor_;
119 if ( (gearing_ < 0) && isCapped_)
120 return cap_;
121 return Null<Rate>();
122 }
123
124
126 return (cap_ - spread())/gearing();
127 }
128
129
131 return (floor_ - spread())/gearing();
132 }
133
134
137 }
138
139
141 typedef YoYInflationCoupon super;
142 auto* v1 = dynamic_cast<Visitor<CappedFlooredYoYInflationCoupon>*>(&v);
143
144 if (v1 != nullptr)
145 v1->visit(*this);
146 else
147 super::accept(v);
148 }
149
150}
151
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:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
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:35
ext::shared_ptr< BlackVolTermStructure > v