Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
JyImpliedYoYInflationTermStructure Class Reference

#include <qle/models/jyimpliedyoyinflationtermstructure.hpp>

+ Inheritance diagram for JyImpliedYoYInflationTermStructure:
+ Collaboration diagram for JyImpliedYoYInflationTermStructure:

Public Member Functions

 JyImpliedYoYInflationTermStructure (const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index, bool indexIsInterpolated)
 
- Public Member Functions inherited from YoYInflationModelTermStructure
 YoYInflationModelTermStructure (const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index, bool indexIsInterpolated)
 
void update () override
 
QuantLib::Date maxDate () const override
 
QuantLib::Time maxTime () const override
 
const QuantLib::Date & referenceDate () const override
 
QuantLib::Date baseDate () const override
 
virtual void referenceDate (const QuantLib::Date &d)
 Set the reference date. More...
 
void state (const QuantLib::Array &s)
 Set the current state variables. More...
 
void move (const QuantLib::Date &d, const QuantLib::Array &s)
 Set the current state and move the reference date to date d. More...
 
QuantLib::Real yoyRate (const QuantLib::Date &d, const QuantLib::Period &obsLag=-1 *QuantLib::Days, bool forceLinearInterpolation=false, bool extrapolate=false) const
 

YoYInflationModelTermStructure interface

std::map< QuantLib::Date, QuantLib::Real > yoyRates (const std::vector< QuantLib::Date > &dates, const QuantLib::Period &obsLag=-1 *QuantLib::Days) const override
 
QuantLib::Real yoySwaplet (QuantLib::Time S, QuantLib::Time T) const
 Year on year swaplet price for the period from S to T. More...
 
void checkState () const override
 

Additional Inherited Members

- Protected Member Functions inherited from YoYInflationModelTermStructure
QuantLib::Real yoyRateImpl (QuantLib::Time t) const override
 This cannot be called. The implementation is set to throw an exception. More...
 
- Protected Attributes inherited from YoYInflationModelTermStructure
QuantLib::ext::shared_ptr< CrossAssetModelmodel_
 
QuantLib::Size index_
 
bool indexIsInterpolated_
 
QuantLib::Date referenceDate_
 
QuantLib::Time relativeTime_
 
QuantLib::Array state_
 

Detailed Description

Jarrow Yildrim (JY) implied year on year inflation term structure

Definition at line 35 of file jyimpliedyoyinflationtermstructure.hpp.

Constructor & Destructor Documentation

◆ JyImpliedYoYInflationTermStructure()

JyImpliedYoYInflationTermStructure ( const QuantLib::ext::shared_ptr< CrossAssetModel > &  model,
QuantLib::Size  index,
bool  indexIsInterpolated 
)

Constructor taking the cross asset model, model, and the index of the relevant inflation component within the model, index.

Definition at line 45 of file jyimpliedyoyinflationtermstructure.cpp.

47 : YoYInflationModelTermStructure(model, index, indexIsInterpolated) {}
YoYInflationModelTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index, bool indexIsInterpolated)

Member Function Documentation

◆ yoyRates()

map< Date, Real > yoyRates ( const std::vector< QuantLib::Date > &  dates,
const QuantLib::Period &  obsLag = -1 *QuantLib::Days 
) const
overridevirtual

Return the year-on-year rates for the maturities associated with dates. If an obsLag is explicitly provided and not set to -1 * QuantLib::Days, it is used as the observation lag. Otherwise, the term structure's observation lag is used.

Implements YoYInflationModelTermStructure.

Definition at line 49 of file jyimpliedyoyinflationtermstructure.cpp.

49 {
50
51 // First step is to calculate the YoY swap rate for each maturity date in dts and store in yyiisRates.
52 map<Date, Real> yoySwaplets;
53 map<Date, Real> discounts;
54 map<Date, Real> yyiisRates;
55 auto irIdx = model_->ccyIndex(model_->infjy(index_)->currency());
56
57 // Will need a YoY index below in the helpers.
58 QuantLib::ext::shared_ptr<YoYInflationIndex> index =
59 QuantLib::ext::make_shared<YoYInflationIndexWrapper>(model_->infjy(index_)->inflationIndex(), indexIsInterpolated());
60
61 for (const auto& maturity : dts) {
62
63 // Schedule for the YoY swap with maturity date equal to `maturity`
64 Schedule schedule = MakeSchedule()
65 .from(referenceDate_)
66 .to(maturity)
67 .withTenor(1 * Years)
68 .withConvention(Unadjusted)
69 .withCalendar(calendar())
70 .backwards();
71
72 // Store the value of the model implied YoY leg and the value of the fixed leg annuity.
73 Real yoyLegValue = 0.0;
74 Real fixedLegAnnuity = 0.0;
75
76 for (Size i = 1; i < schedule.dates().size(); ++i) {
77
78 // Start and end of the current YoY swaplet period.
79 const auto& start = schedule.dates()[i - 1];
80 const auto& end = schedule.dates()[i];
81
82 // If we have already calculated the YoY swaplet price for this period, use it.
83 // We should always have a discount factor in this case also.
84 auto it = yoySwaplets.find(end);
85 if (it != yoySwaplets.end()) {
86 yoyLegValue += it->second;
87 fixedLegAnnuity += discounts.at(end);
88 continue;
89 }
90
91 // Need to calculate the YoY swaplet value over the period [start, end]
92 Real swaplet;
93 auto T = relativeTime_ + dayCounter().yearFraction(referenceDate_, end);
94 auto discount = model_->discountBond(irIdx, relativeTime_, T, state_[2]);
95 if (i == 1) {
96 // The first YoY swaplet is a zero coupon swaplet because I_{start} is known.
97 auto growth =
99 swaplet = discount * (growth - 1.0);
100 } else {
101 auto S = relativeTime_ + dayCounter().yearFraction(referenceDate_, start);
102 swaplet = yoySwaplet(S, T);
103 }
104
105 // Cache the swaplet value and the discount factor related to this swaplet end date.
106 yoySwaplets[end] = swaplet;
107 discounts[end] = discount;
108
109 // Update the YoY leg value and the fixed leg annuity
110 yoyLegValue += swaplet;
111 fixedLegAnnuity += discount;
112 }
113
114 // The model implied YoY inflation swap rate
115 yyiisRates[maturity] = yoyLegValue / fixedLegAnnuity;
116 }
117
118 QL_REQUIRE(!yyiisRates.empty(), "JyImpliedYoYInflationTermStructure: yoyRates did not create any YoY swap rates.");
119
120 // Will need a discount term structure in the bootstrap below so create it here from the discounts map.
121 vector<Date> dfDates;
122 vector<Real> dfValues;
123
124 if (discounts.count(referenceDate_) == 0) {
125 dfDates.push_back(referenceDate_);
126 dfValues.push_back(1.0);
127 }
128
129 for (const auto& kv : discounts) {
130 dfDates.push_back(kv.first);
131 dfValues.push_back(kv.second);
132 }
133
134 auto irTs = model_->irlgm1f(irIdx)->termStructure();
135 Handle<YieldTermStructure> yts(
136 QuantLib::ext::make_shared<InterpolatedDiscountCurve<LogLinear>>(dfDates, dfValues, irTs->dayCounter(), LogLinear()));
137
138 // Create the YoY swap helpers from the YoY swap rates calculated above.
139 // Using the curve's day counter as the helper's day counter for now.
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));
146 }
147
148 // Create a YoY curve from the helpers
149 // Use Linear here in line with what is in scenariosimmarket and todaysmarket but should probably be more generic.
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);
154
155 // Read the necessary YoY rates from the bootstrapped YoY inflation curve
156 map<Date, Real> result;
157 for (const auto& maturity : dts) {
158 result[maturity] = yoyCurve->yoyRate(maturity);
159 }
160
161 return result;
162}
QuantLib::Real yoySwaplet(QuantLib::Time S, QuantLib::Time T) const
Year on year swaplet price for the period from S to T.
QuantLib::ext::shared_ptr< CrossAssetModel > model_
Real inflationGrowth(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index, Time S, Time T, Real irState, Real rrState, bool indexIsInterpolated)
+ Here is the call graph for this function:

◆ yoySwaplet()

Real yoySwaplet ( QuantLib::Time  S,
QuantLib::Time  T 
) const
protected

Year on year swaplet price for the period from S to T.

Definition at line 164 of file jyimpliedyoyinflationtermstructure.cpp.

164 {
165
166 // The JY implied swap rate at time t for the period from S to T is:
167 // N \tau(S, T) \left\{ P_n(t,S) \frac{P_r(t,T)}{P_r(t,S)} e^{C(t,S,T)} - P_n(t,T) \right\}
168 // where N is the nominal, \tau(S, T) is the daycount which we assume equals 1 here.
169 // e^{C(t,S,T)} is the correction term which we deal with below.
170
171 // Get P_n(t,S) and P_n(t,T).
172 auto irIdx = model_->ccyIndex(model_->infjy(index_)->currency());
173 auto irTs = model_->irlgm1f(irIdx)->termStructure();
174 auto p_n_t_S = model_->discountBond(irIdx, relativeTime_, S, state_[2]);
175 auto p_n_t_T = model_->discountBond(irIdx, relativeTime_, T, state_[2]);
176
177 // Get the rrRatio := P_r(t,T)}{P_r(t,S)}.
178 auto rrParam = model_->infjy(index_)->realRate();
179 auto H_r_S = rrParam->H(S);
180 auto H_r_T = rrParam->H(T);
181 auto zeta_r_t = rrParam->zeta(relativeTime_);
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);
183
184 const auto& zts = model_->infjy(index_)->realRate()->termStructure();
185 rrRatio *= (irTs->discount(T) * inflationGrowth(zts, T, indexIsInterpolated_)) /
186 (irTs->discount(S) * inflationGrowth(zts, S, indexIsInterpolated_));
187
188 // Calculate the correction term C(t,S,T)
189 using CrossAssetAnalytics::ay;
190 using CrossAssetAnalytics::az;
191 using CrossAssetAnalytics::Hy;
192 using CrossAssetAnalytics::Hz;
196 using CrossAssetAnalytics::ryy;
197 using CrossAssetAnalytics::rzy;
198 using CrossAssetAnalytics::sy;
199
200 auto H_n_S = model_->irlgm1f(irIdx)->H(S);
201 auto zeta_r_S = rrParam->zeta(S);
202
203 auto c = H_r_S * (zeta_r_S - zeta_r_t);
204 c -= H_n_S * integral(*model_, P(rzy(irIdx, index_, 0), az(irIdx), ay(index_)), relativeTime_, S);
205 c += integral(*model_,
206 LC(0.0, -1.0, P(ay(index_), ay(index_), Hy(index_)), 1.0,
207 P(rzy(irIdx, index_, 0), az(irIdx), ay(index_), Hz(irIdx)), -1.0,
208 P(ryy(index_, index_, 0, 1), ay(index_), sy(index_))),
209 relativeTime_, S);
210 c *= (H_r_S - H_r_T);
211
212 return p_n_t_S * rrRatio * exp(c) - p_n_t_T;
213}
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)
CompiledFormula exp(CompiledFormula x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkState()

void checkState ( ) const
overrideprotectedvirtual

Override this method to perform checks on the state variable array when the state and move methods are called.

Reimplemented from YoYInflationModelTermStructure.

Definition at line 215 of file jyimpliedyoyinflationtermstructure.cpp.

215 {
216 // For JY YoY, expect the state to be three variables i.e. z_I and c_I and z_{ir}.
217 QL_REQUIRE(state_.size() == 3, "JyImpliedYoYInflationTermStructure: expected state to have "
218 << "three elements but got " << state_.size());
219}