QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cpicouponpricer.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, 2011 Chris Kenyon
5 Copyright (C) 2022 Quaternion Risk Management Ltd
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19 */
20
22#include <utility>
23
24namespace QuantLib {
25
27
29 : nominalTermStructure_(std::move(nominalTermStructure)) {
31 }
32
34 Handle<YieldTermStructure> nominalTermStructure)
35 : capletVol_(std::move(capletVol)), nominalTermStructure_(std::move(nominalTermStructure)) {
38 }
39
41
43 const Handle<CPIVolatilitySurface>& capletVol) {
44 QL_REQUIRE(!capletVol.empty(),"empty capletVol handle");
45 capletVol_ = capletVol;
47 }
48
49
52 return gearing_ * floorletPrice;
53 }
54
57 return gearing_ * capletPrice;
58 }
59
60
61 Rate CPICouponPricer::floorletRate(Rate effectiveFloor) const {
62 return gearing_ * optionletRate(Option::Put, effectiveFloor);
63 }
64
66 return gearing_ * optionletRate(Option::Call, effectiveCap);
67 }
68
69
71 Real,
72 Real,
73 Real) const {
74 QL_FAIL("you must implement this to get a vol-dependent price");
75 }
76
77
79 Real effStrike) const {
80 QL_REQUIRE(discount_ != Null<Real>(), "no nominal term structure provided");
81 return optionletRate(optionType, effStrike) * coupon_->accrualPeriod() * discount_;
82 }
83
84
86 Real effStrike) const {
87 Date fixingDate = coupon_->fixingDate();
88 if (fixingDate <= Settings::instance().evaluationDate()) {
89 // the amount is determined
90 Real a, b;
91 if (optionType==Option::Call) {
92 a = coupon_->indexFixing();
93 b = effStrike;
94 } else {
95 a = effStrike;
97 }
98 return std::max(a - b, 0.0);
99 } else {
100 // not yet determined, use Black/DD1/Bachelier/whatever from Impl
101 QL_REQUIRE(!capletVolatility().empty(),
102 "missing optionlet volatility");
103 Real stdDev =
104 std::sqrt(capletVolatility()->totalVariance(fixingDate,
105 effStrike));
107 return optionletPriceImp(optionType,
108 effStrike,
110 stdDev);
112 }
113 }
114
115
117 if (fixing != Null<Rate>())
118 return fixing;
119
121 }
122
123
125 coupon_ = dynamic_cast<const CPICoupon*>(&coupon);
131
132 // past or future fixing is managed in YoYInflationIndex::fixing()
133 // use yield curve from index (which sets discount)
134
135 discount_ = 1.0;
136 if (nominalTermStructure_.empty()) {
137 // allow to extract rates, but mark the discount as invalid for prices
139 } else {
140 if (paymentDate_ > nominalTermStructure_->referenceDate())
142 }
143 }
144
145
147 QL_REQUIRE(discount_ != Null<Real>(), "no nominal term structure provided");
149 }
150
151
154 return gearing_ * adjustedFixing() + spread_;
156 // after deprecating and removing adjustedFixing:
157 // return accruedRate(coupon_->accrualEndDate());
158 }
159
160
161 Rate CPICouponPricer::accruedRate(Date settlementDate) const {
163 return gearing_ * coupon_->indexRatio(settlementDate) + spread_;
165 }
166
167}
Coupon paying the performance of a CPI (zero inflation) index
Definition: cpicoupon.hpp:55
Rate indexFixing() const override
the index value observed (with a lag) at the end date
Definition: cpicoupon.hpp:354
Rate indexRatio(Date d) const
the ratio between the index fixing at the passed date and the base CPI
Definition: cpicoupon.cpp:172
Spread spread() const
Definition: cpicoupon.hpp:342
Real fixedRate() const
fixed rate that will be inflated by the index ratio
Definition: cpicoupon.hpp:338
void initialize(const InflationCoupon &) override
Handle< CPIVolatilitySurface > capletVol_
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
virtual Rate adjustedFixing(Rate fixing=Null< Rate >()) const
virtual QL_DEPRECATED_ENABLE_WARNING Handle< CPIVolatilitySurface > capletVolatility() const
virtual void setCapletVolatility(const Handle< CPIVolatilitySurface > &capletVol)
Handle< YieldTermStructure > nominalTermStructure_
virtual Real optionletPrice(Option::Type optionType, Real effStrike) const
virtual Rate accruedRate(Date settlementDate) const
CPICouponPricer(Handle< YieldTermStructure > nominalTermStructure=Handle< YieldTermStructure >())
virtual Real optionletRate(Option::Type optionType, Real effStrike) const
virtual Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const
Rate swapletRate() const override
Real floorletPrice(Rate effectiveFloor) const override
Real swapletPrice() const override
Rate capletRate(Rate effectiveCap) const override
const Date & accrualEndDate() const
end of the accrual period
Definition: coupon.hpp:108
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:191
Base inflation-coupon class.
virtual Date fixingDate() const
fixing date
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
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
zero inflation-coupon pricer
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
ext::function< Real(Real)> b
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217