QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
inflationcouponpricer.cpp
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#include <ql/cashflows/inflationcouponpricer.hpp>
21#include <ql/pricingengines/blackformula.hpp>
22#include <ql/termstructures/volatility/inflation/yoyinflationoptionletvolatilitystructure.hpp>
23#include <utility>
24
25namespace QuantLib {
26
27 void setCouponPricer(const Leg& leg,
28 const ext::shared_ptr<InflationCouponPricer>& p) {
29 for (const auto& i : leg) {
30 ext::shared_ptr<InflationCoupon> c = ext::dynamic_pointer_cast<InflationCoupon>(i);
31 if (c != nullptr)
32 c->setPricer(p);
33 }
34 }
35
36
38 Handle<YieldTermStructure> nominalTermStructure)
39 : nominalTermStructure_(std::move(nominalTermStructure)) {
41 }
42
45 Handle<YieldTermStructure> nominalTermStructure)
46 : capletVol_(std::move(capletVol)), nominalTermStructure_(std::move(nominalTermStructure)) {
49 }
50
51
54 QL_REQUIRE(!capletVol.empty(),"empty capletVol handle");
55 capletVol_ = capletVol;
57 }
58
59
62 return gearing_ * floorletPrice;
63 }
64
67 return gearing_ * capletPrice;
68 }
69
70
72 return gearing_ * optionletRate(Option::Put, effectiveFloor);
73 }
74
76 return gearing_ * optionletRate(Option::Call, effectiveCap);
77 }
78
79
82 Real,
83 Real,
84 Real) const {
85 QL_FAIL("you must implement this to get a vol-dependent price");
86 }
87
88
90 Real effStrike) const {
91 QL_REQUIRE(discount_ != Null<Real>(), "no nominal term structure provided");
92 return optionletRate(optionType, effStrike) * coupon_->accrualPeriod() * discount_;
93 }
94
95
97 Real effStrike) const {
98 Date fixingDate = coupon_->fixingDate();
99 if (fixingDate <= capletVolatility()->baseDate()) {
100 // the amount is determined
101 Real a, b;
102 if (optionType==Option::Call) {
103 a = coupon_->indexFixing();
104 b = effStrike;
105 } else {
106 a = effStrike;
107 b = coupon_->indexFixing();
108 }
109 return std::max(a - b, 0.0);
110 } else {
111 // not yet determined, use Black/DD1/Bachelier/whatever from Impl
112 QL_REQUIRE(!capletVolatility().empty(), "missing optionlet volatility");
113
114 Real stdDev =
115 std::sqrt(capletVolatility()->totalVariance(fixingDate,
116 effStrike,
117 Period(0, Days)));
118 return optionletPriceImp(optionType,
119 effStrike,
121 stdDev);
122 }
123 }
124
125
127
128 if (fixing == Null<Rate>())
129 fixing = coupon_->indexFixing();
130
131 // no adjustment
132 return fixing;
133 }
134
135
137 coupon_ = dynamic_cast<const YoYInflationCoupon*>(&coupon);
138 QL_REQUIRE(coupon_, "year-on-year inflation coupon needed");
142
143 // past or future fixing is managed in YoYInflationIndex::fixing()
144 // use yield curve from index (which sets discount)
145
146 discount_ = 1.0;
147 if (nominalTermStructure_.empty()) {
148 // allow to extract rates, but mark the discount as invalid for prices
150 } else {
151 if (paymentDate_ > nominalTermStructure_->referenceDate())
153 }
154 }
155
156
158 QL_REQUIRE(discount_ != Null<Real>(), "no nominal term structure provided");
160 }
161
162
164 // This way we do not require the index to have
165 // a yield curve, i.e. we do not get the problem
166 // that a discounting-instrument-pricer is used
167 // with a different yield curve
168 return gearing_ * adjustedFixing() + spread_;
169 }
170
171
172 //=========================================================================
173 // vol-dependent pricers, note that these do not discount
174 //=========================================================================
175
176
177
179 Real effStrike,
180 Real forward,
181 Real stdDev
182 ) const {
183
184 return blackFormula(optionType,
185 effStrike,
186 forward,
187 stdDev);
188 }
189
191 Real effStrike,
192 Real forward,
193 Real stdDev
194 ) const {
195
196 return blackFormula(optionType,
197 effStrike + 1.0,
198 forward + 1.0,
199 stdDev);
200 }
201
203 Real effStrike,
204 Real forward,
205 Real stdDev
206 ) const {
207 return bachelierBlackFormula(optionType,
208 effStrike,
209 forward,
210 stdDev);
211 }
212
213}
Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const override
Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const override
Date date() const override
Definition: coupon.hpp:53
Time accrualPeriod() const
accrual period as fraction of year
Definition: coupon.cpp:44
Concrete date class.
Definition: date.hpp:125
Shared handle to an observable.
Definition: handle.hpp:41
bool empty() const
checks if the contained shared pointer points to anything
Definition: handle.hpp:166
Base inflation-coupon class.
virtual Date fixingDate() const
fixing date
virtual Rate indexFixing() const
fixing of the underlying index, as observed by the coupon
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
Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const override
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
void initialize(const InflationCoupon &) override
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
virtual Rate adjustedFixing(Rate fixing=Null< Rate >()) const
Handle< YieldTermStructure > nominalTermStructure_
virtual Real optionletPrice(Option::Type optionType, Real effStrike) const
virtual Handle< YoYOptionletVolatilitySurface > capletVolatility() const
virtual Real optionletRate(Option::Type optionType, Real effStrike) const
virtual Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const
Real floorletPrice(Rate effectiveFloor) const override
virtual void setCapletVolatility(const Handle< YoYOptionletVolatilitySurface > &capletVol)
Handle< YoYOptionletVolatilitySurface > capletVol_
data
Rate capletRate(Rate effectiveCap) const override
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
Real bachelierBlackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount)
void setCouponPricer(const Leg &leg, const ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.