Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inflation.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/utilities/inflation.hpp
20 \brief some inflation related utilities.
21*/
22
23#ifndef quantext_inflation_hpp
24#define quantext_inflation_hpp
25
26#include <ql/indexes/inflationindex.hpp>
27#include <ql/instruments/bond.hpp>
28#include <ql/termstructures/inflation/inflationhelpers.hpp>
29#include <ql/termstructures/inflationtermstructure.hpp>
30#include <ql/termstructures/volatility/inflation/cpivolatilitystructure.hpp>
31#include <ql/time/period.hpp>
32namespace QuantExt {
33
34/*! Utility function for calculating the time to a given \p date based on a given inflation index,
35 \p inflationIndex, and a given inflation term structure, \p inflationTs. An optional \p dayCounter can be
36 provided to use instead of the inflation term structure day counter.
37
38 \ingroup utilities
39*/
40QuantLib::Time inflationTime(const QuantLib::Date& date,
41 const QuantLib::ext::shared_ptr<QuantLib::InflationTermStructure>& inflationTs,
42 bool indexIsInterpolated,
43 const QuantLib::DayCounter& dayCounter = QuantLib::DayCounter());
44
45/*! Utility for calculating the ratio \f$ \frac{P_r(0, t)}{P_n(0, t)} \f$ where \f$ P_r(0, t) \f$ is the real zero
46 coupon bond price at time zero for maturity \f$ t \f$ and \f$ P_n(0, t) \f$ is the nominal zero coupon bond price.
47*/
48QuantLib::Real inflationGrowth(const QuantLib::Handle<QuantLib::ZeroInflationTermStructure>& ts,
49 QuantLib::Time t,
50 const QuantLib::DayCounter& dc,
51 bool indexIsInterpolated);
52
53/*! Utility for calculating the ratio \f$ \frac{P_r(0, t)}{P_n(0, t)} \f$ where \f$ P_r(0, t) \f$ is the real zero
54 coupon bond price at time zero for maturity \f$ t \f$ and \f$ P_n(0, t) \f$ is the nominal zero coupon bond price.
55*/
56QuantLib::Real inflationGrowth(const QuantLib::Handle<QuantLib::ZeroInflationTermStructure>& ts,
57 QuantLib::Time t, bool indexIsInterpolated);
58
59/*! Calculate the Compound Factor to compute the nominal price from the real price
60 I(t_s)/I(t_0) with I(t_s) the CPI at settlement date and I(t_0) the bond's base CPI
61*/
62QuantLib::Real inflationLinkedBondQuoteFactor(const QuantLib::ext::shared_ptr<QuantLib::Bond>& bond);
63
64/*! Iterates over all bond cashflows, and extract all inflation underlyings */
65std::map<std::tuple<std::string, QuantLib::CPI::InterpolationType, QuantLib::Frequency, QuantLib::Period>,
66 QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>>
67extractAllInflationUnderlyingFromBond(const QuantLib::ext::shared_ptr<QuantLib::Bond>& bond);
68
69namespace ZeroInflation {
70
71//! Check if today - availabilityLag is already known, otherwise return the fixingDate of the previous fixing
72QuantLib::Date lastAvailableFixing(const QuantLib::ZeroInflationIndex& index, const QuantLib::Date& asof);
73
74
75//! Computes a CPI fixing giving an zeroIndex, with interpolation if needed
76QuantLib::Rate cpiFixing(const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index, const QuantLib::Date& maturity,
77 const QuantLib::Period& obsLag, bool interpolated);
78
79
80//! derives the zero inflation curve base date based on the useLastKnownFixing rule
81QuantLib::Date curveBaseDate(const bool baseDateLastKnownFixing, const QuantLib::Date& refDate,
82 const QuantLib::Period obsLagCurve, const QuantLib::Frequency curveFreq,
83 const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index);
84
85
86//! computes the fixingDate for ZC CPI Swap following the rule
87//! for an interpolated index it is d - obsLag but
88//! for an interpolated index the fixing date is per definition on the start of the
89//! inflation period in which d - obsLag falls
90QuantLib::Date fixingDate(const QuantLib::Date& d, const QuantLib::Period obsLag,
91 const QuantLib::Frequency,
92 bool interpolated);
93
94
95/*! Computes the base rate for curve construction so that zero inflation rate is constant up to the first pillar
96* Accounts for the acctual accrued inflation between the ZCIIS base date and the curve base date (e.g. last published fixing date)
97* If curve base date and ZCIIS are the same, then the base rate is the ZCIIS rate
98*/
99QuantLib::Rate guessCurveBaseRate(const bool baseDateLastKnownFixing, const QuantLib::Date& swapStart,
100 const QuantLib::Date& asof,
101 const QuantLib::Period& swapTenor, const QuantLib::DayCounter& swapZCLegDayCounter,
102 const QuantLib::Period& swapObsLag, const QuantLib::Rate zeroCouponRate,
103 const QuantLib::Period& curveObsLag, const QuantLib::DayCounter& curveDayCounter,
104 const QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex>& index, const bool interpolated,
105 const QuantLib::ext::shared_ptr<QuantLib::Seasonality>& seasonality = nullptr);
106
107
108//! checks if the vols are normal or lognormal
109//! if the volsurface is not derived from QuantExt::CPIVolatilitySurface we default to lognormal vols
110bool isCPIVolSurfaceLogNormal(const QuantLib::ext::shared_ptr<QuantLib::CPIVolatilitySurface>& surface);
111
112
113}
114
115} // namespace QuantExt
116
117#endif
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Definition: inflation.cpp:183
QuantLib::Date lastAvailableFixing(const QuantLib::ZeroInflationIndex &index, const QuantLib::Date &asof)
Check if today - availabilityLag is already known, otherwise return the fixingDate of the previous fi...
Definition: inflation.cpp:156
QuantLib::Rate cpiFixing(const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index, const QuantLib::Date &maturity, const QuantLib::Period &obsLag, bool interpolated)
Computes a CPI fixing giving an zeroIndex, with interpolation if needed.
Definition: inflation.cpp:166
QuantLib::Date curveBaseDate(const bool baseDateLastKnownFixing, const QuantLib::Date &refDate, const QuantLib::Period obsLagCurve, const QuantLib::Frequency curveFreq, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index)
derives the zero inflation curve base date based on the useLastKnownFixing rule
Definition: inflation.cpp:172
QuantLib::Rate guessCurveBaseRate(const bool baseDateLastKnownFixing, const QuantLib::Date &swapStart, const QuantLib::Date &asof, const QuantLib::Period &swapTenor, const QuantLib::DayCounter &swapZCLegDayCounter, const QuantLib::Period &swapObsLag, const QuantLib::Rate zeroCouponRate, const QuantLib::Period &curveObsLag, const QuantLib::DayCounter &curveDayCounter, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index, const bool interpolated, const QuantLib::ext::shared_ptr< QuantLib::Seasonality > &seasonality)
Definition: inflation.cpp:191
bool isCPIVolSurfaceLogNormal(const QuantLib::ext::shared_ptr< QuantLib::CPIVolatilitySurface > &surface)
Definition: inflation.cpp:302
std::map< std::tuple< std::string, QuantLib::CPI::InterpolationType, QuantLib::Frequency, QuantLib::Period >, QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > > extractAllInflationUnderlyingFromBond(const QuantLib::ext::shared_ptr< QuantLib::Bond > &bond)
Definition: inflation.cpp:136
Real inflationLinkedBondQuoteFactor(const QuantLib::ext::shared_ptr< QuantLib::Bond > &bond)
Definition: inflation.cpp:83
Time inflationTime(const Date &date, const QuantLib::ext::shared_ptr< InflationTermStructure > &inflationTs, bool indexIsInterpolated, const DayCounter &dayCounter)
Definition: inflation.cpp:61
Real inflationGrowth(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index, Time S, Time T, Real irState, Real rrState, bool indexIsInterpolated)