QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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 : nominalTermStructure_(std::move(nominalTermStructure)) {
29 }
30
32 Handle<YieldTermStructure> nominalTermStructure)
33 : capletVol_(std::move(capletVol)), nominalTermStructure_(std::move(nominalTermStructure)) {
36 }
37
39 const Handle<CPIVolatilitySurface>& capletVol) {
40 QL_REQUIRE(!capletVol.empty(),"empty capletVol handle");
41 capletVol_ = capletVol;
43 }
44
45
48 return gearing_ * floorletPrice;
49 }
50
53 return gearing_ * capletPrice;
54 }
55
56
57 Rate CPICouponPricer::floorletRate(Rate effectiveFloor) const {
58 return gearing_ * optionletRate(Option::Put, effectiveFloor);
59 }
60
62 return gearing_ * optionletRate(Option::Call, effectiveCap);
63 }
64
65
67 Real,
68 Real,
69 Real) const {
70 QL_FAIL("you must implement this to get a vol-dependent price");
71 }
72
73
75 Real effStrike) const {
76 QL_REQUIRE(discount_ != Null<Real>(), "no nominal term structure provided");
77 return optionletRate(optionType, effStrike) * coupon_->accrualPeriod() * discount_;
78 }
79
80
82 Real effStrike) const {
83 Date fixingDate = coupon_->fixingDate();
84 if (fixingDate <= Settings::instance().evaluationDate()) {
85 // the amount is determined
86 Real a, b;
87 if (optionType==Option::Call) {
88 a = coupon_->indexFixing();
89 b = effStrike;
90 } else {
91 a = effStrike;
93 }
94 return std::max(a - b, 0.0);
95 } else {
96 // not yet determined, use Black/DD1/Bachelier/whatever from Impl
98 "missing optionlet volatility");
99 Real stdDev =
100 std::sqrt(capletVolatility()->totalVariance(fixingDate,
101 effStrike));
102 return optionletPriceImp(optionType,
103 effStrike,
105 stdDev);
106 }
107 }
108
109
111 coupon_ = dynamic_cast<const CPICoupon*>(&coupon);
114
115 // past or future fixing is managed in YoYInflationIndex::fixing()
116 // use yield curve from index (which sets discount)
117
118 discount_ = 1.0;
119 if (nominalTermStructure_.empty()) {
120 // allow to extract rates, but mark the discount as invalid for prices
122 } else {
123 if (paymentDate_ > nominalTermStructure_->referenceDate())
125 }
126 }
127
128
130 QL_REQUIRE(discount_ != Null<Real>(), "no nominal term structure provided");
132 }
133
134
137 }
138
139
140 Rate CPICouponPricer::accruedRate(Date settlementDate) const {
141 return gearing_ * coupon_->indexRatio(settlementDate);
142 }
143
144}
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:267
Rate indexRatio(Date d) const
the ratio between the index fixing at the passed date and the base CPI
Definition: cpicoupon.cpp:112
Real fixedRate() const
fixed rate that will be inflated by the index ratio
Definition: cpicoupon.hpp:259
void initialize(const InflationCoupon &) override
Handle< CPIVolatilitySurface > capletVol_
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
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
virtual Real optionletRate(Option::Type optionType, Real effStrike) const
virtual Real optionletPriceImp(Option::Type, Real strike, Real forward, Real stdDev) const
virtual Handle< CPIVolatilitySurface > capletVolatility() const
CPICouponPricer(Handle< YieldTermStructure > nominalTermStructure=Handle< YieldTermStructure >())
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:188
Base inflation-coupon class.
virtual Date fixingDate() const
fixing date
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
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
std::function< Real(Real)> b
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:37
STL namespace.