19#include <ql/termstructures/inflation/inflationhelpers.hpp>
20#include <ql/termstructures/inflation/piecewiseyoyinflationcurve.hpp>
21#include <ql/termstructures/yield/discountcurve.hpp>
22#include <ql/time/schedule.hpp>
30using QuantLib::InterpolatedDiscountCurve;
31using QuantLib::Linear;
32using QuantLib::MakeSchedule;
33using QuantLib::PiecewiseYoYInflationCurve;
35using QuantLib::Schedule;
38using QuantLib::YearOnYearInflationSwapHelper;
46 Size index,
bool indexIsInterpolated)
52 map<Date, Real> yoySwaplets;
53 map<Date, Real> discounts;
54 map<Date, Real> yyiisRates;
58 QuantLib::ext::shared_ptr<YoYInflationIndex> index =
59 QuantLib::ext::make_shared<YoYInflationIndexWrapper>(
model_->infjy(
index_)->inflationIndex(), indexIsInterpolated());
61 for (
const auto& maturity : dts) {
64 Schedule schedule = MakeSchedule()
68 .withConvention(Unadjusted)
69 .withCalendar(calendar())
73 Real yoyLegValue = 0.0;
74 Real fixedLegAnnuity = 0.0;
76 for (Size i = 1; i < schedule.dates().size(); ++i) {
79 const auto& start = schedule.dates()[i - 1];
80 const auto& end = schedule.dates()[i];
84 auto it = yoySwaplets.find(end);
85 if (it != yoySwaplets.end()) {
86 yoyLegValue += it->second;
87 fixedLegAnnuity += discounts.at(end);
99 swaplet = discount * (growth - 1.0);
106 yoySwaplets[end] = swaplet;
107 discounts[end] = discount;
110 yoyLegValue += swaplet;
111 fixedLegAnnuity += discount;
115 yyiisRates[maturity] = yoyLegValue / fixedLegAnnuity;
118 QL_REQUIRE(!yyiisRates.empty(),
"JyImpliedYoYInflationTermStructure: yoyRates did not create any YoY swap rates.");
121 vector<Date> dfDates;
122 vector<Real> dfValues;
126 dfValues.push_back(1.0);
129 for (
const auto& kv : discounts) {
130 dfDates.push_back(kv.first);
131 dfValues.push_back(kv.second);
134 auto irTs =
model_->irlgm1f(irIdx)->termStructure();
135 Handle<YieldTermStructure> yts(
140 using YoYHelper = BootstrapHelper<YoYInflationTermStructure>;
141 vector<QuantLib::ext::shared_ptr<YoYHelper>> helpers;
142 for (
const auto& kv : yyiisRates) {
143 Handle<Quote> yyiisQuote(QuantLib::ext::make_shared<SimpleQuote>(kv.second));
144 helpers.push_back(QuantLib::ext::make_shared<YearOnYearInflationSwapHelper>(
145 yyiisQuote, observationLag(), kv.first, calendar(), Unadjusted, dayCounter(), index, yts));
150 auto lag = obsLag == -1 * Days ? observationLag() : obsLag;
151 auto baseRate = helpers.front()->quote()->value();
152 auto yoyCurve = QuantLib::ext::make_shared<PiecewiseYoYInflationCurve<Linear>>(
153 referenceDate_, calendar(), dayCounter(), lag, frequency(), indexIsInterpolated(), baseRate, helpers, 1e-12);
156 map<Date, Real> result;
157 for (
const auto& maturity : dts) {
158 result[maturity] = yoyCurve->yoyRate(maturity);
173 auto irTs =
model_->irlgm1f(irIdx)->termStructure();
179 auto H_r_S = rrParam->H(S);
180 auto H_r_T = rrParam->H(T);
182 auto rrRatio =
exp(-(H_r_T - H_r_S) *
state_[0] - 0.5 * (H_r_T * H_r_T - H_r_S * H_r_S) * zeta_r_t);
184 const auto& zts =
model_->infjy(
index_)->realRate()->termStructure();
200 auto H_n_S =
model_->irlgm1f(irIdx)->H(S);
201 auto zeta_r_S = rrParam->zeta(S);
203 auto c = H_r_S * (zeta_r_S - zeta_r_t);
210 c *= (H_r_S - H_r_T);
212 return p_n_t_S * rrRatio *
exp(c) - p_n_t_T;
217 QL_REQUIRE(
state_.size() == 3,
"JyImpliedYoYInflationTermStructure: expected state to have "
218 <<
"three elements but got " <<
state_.size());
InterpolatedDiscountCurve based on loglinear interpolation of DiscountFactors.
QuantLib::Real yoySwaplet(QuantLib::Time S, QuantLib::Time T) const
Year on year swaplet price for the period from S to T.
std::map< QuantLib::Date, QuantLib::Real > yoyRates(const std::vector< QuantLib::Date > &dates, const QuantLib::Period &obsLag=-1 *QuantLib::Days) const override
void checkState() const override
JyImpliedYoYInflationTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index, bool indexIsInterpolated)
bool indexIsInterpolated_
QuantLib::ext::shared_ptr< CrossAssetModel > model_
QuantLib::Date referenceDate_
QuantLib::Time relativeTime_
analytics for the cross asset model
const LC1_< E1 > LC(QuantLib::Real c, QuantLib::Real c1, const E1 &e1)
Real integral(const CrossAssetModel &model, const E &e, const Real a, const Real b)
const P2_< E1, E2 > P(const E1 &e1, const E2 &e2)
some inflation related utilities.
wrapper classes for inflation yoy and interpolation
year on year inflation term structure implied by a Jarrow Yildrim (JY) model
zero inflation term structure implied by a Jarrow Yildrim (JY) model
CompiledFormula exp(CompiledFormula x)
Real inflationGrowth(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index, Time S, Time T, Real irState, Real rrState, bool indexIsInterpolated)
INF H component. May relate to real rate portion of JY model or z component of DK model.
INF alpha component. May relate to real rate portion of JY model or z component of DK model.
JY INF index sigma component.