20#include <ql/time/schedule.hpp>
24using QuantLib::MakeSchedule;
25using QuantLib::Schedule;
34 const QuantLib::ext::shared_ptr<CrossAssetModel>& model, Size index,
bool indexIsInterpolated)
40 map<Date, Real> yoyswaplet;
41 map<Date, Real> yoydiscount;
42 Period useLag = obsLag == -1 * Days ? observationLag() : obsLag;
43 Calendar cal =
model_->infdk(
index_)->termStructure()->calendar();
44 DayCounter dc =
model_->infdk(
index_)->termStructure()->dayCounter();
47 for (Size j = 0; j < dts.size(); j++) {
50 maturity = dts[j] - useLag;
52 maturity = inflationPeriod(dts[j] - useLag, frequency()).first;
55 Schedule schedule = MakeSchedule()
59 .withConvention(Unadjusted)
63 Real yoyLegRate = 0.0;
64 Real fixedDiscounts = 0.0;
65 for (Size i = 1; i < schedule.dates().size(); i++) {
66 map<Date, Real>::const_iterator it = yoyswaplet.find(schedule.dates()[i]);
67 Real swapletPrice, discount;
68 if (it == yoyswaplet.end()) {
69 if (schedule.dates()[i - 1] <
baseDate()) {
72 Time t1 = dayCounter().yearFraction(
model_->infdk(
index_)->termStructure()->baseDate(),
73 schedule.dates()[i - 1]);
75 Time t2 = dc.yearFraction(
baseDate(), schedule.dates()[i]);
76 std::pair<Real, Real> II2 =
78 Real I2 = II2.first * II2.second;
81 swapletPrice = discount * ((I2 / I1) - 1);
83 Time t1 = dc.yearFraction(
baseDate(), schedule.dates()[i - 1]);
84 Time t2 = dc.yearFraction(
baseDate(), schedule.dates()[i]);
89 yoyswaplet[schedule.dates()[i]] = swapletPrice;
90 yoydiscount[schedule.dates()[i]] = discount;
92 swapletPrice = yoyswaplet[schedule.dates()[i]];
93 discount = yoydiscount[schedule.dates()[i]];
95 yoyLegRate += swapletPrice;
96 fixedDiscounts += discount;
98 Real
yoyRate = (yoyLegRate / fixedDiscounts);
100 if (hasSeasonality()) {
101 yoyRate = seasonality()->correctYoYRate(dts[j] - useLag,
yoyRate, *
this);
116 QL_REQUIRE(
state_.size() == 3,
"DkImpliedYoYInflationTermStructure: expected state to have " <<
117 "three elements but got " <<
state_.size());
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
QuantLib::Real yoySwapletRate(QuantLib::Time S, QuantLib::Time T) const
DkImpliedYoYInflationTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index, bool indexIsInterpolated)
QuantLib::Date baseDate() const override
bool indexIsInterpolated_
QuantLib::ext::shared_ptr< CrossAssetModel > model_
QuantLib::Real yoyRate(const QuantLib::Date &d, const QuantLib::Period &obsLag=-1 *QuantLib::Days, bool forceLinearInterpolation=false, bool extrapolate=false) const
QuantLib::Time relativeTime_
year on year inflation term structure implied by a Dodgson Kainth (DK) model