21#include <ql/cashflows/simplecashflow.hpp>
22#include <ql/instruments/cpicapfloor.hpp>
23#include <ql/pricingengines/blackformula.hpp>
29using QuantLib::blackFormula;
30using QuantLib::CPICapFloor;
32using QuantLib::Handle;
33using QuantLib::NullCalendar;
34using QuantLib::Option;
35using QuantLib::Period;
38using QuantLib::Settings;
39using QuantLib::SimpleCashFlow;
41using QuantLib::Unadjusted;
42using QuantLib::YoYInflationCapFloor;
43using QuantLib::YoYInflationIndex;
44using QuantLib::ZeroInflationIndex;
52 bool indexIsInterpolated)
53 : model_(model), index_(index), indexIsInterpolated_(indexIsInterpolated) {}
57 QL_REQUIRE(
model_,
"AnalyticJyYoYCapFloorEngine requires a model.");
59 Date today = Settings::instance().evaluationDate();
64 const auto yoyCap = YoYInflationCapFloor::Cap;
65 const auto yoyFlr = YoYInflationCapFloor::Floor;
66 const auto yoyClr = YoYInflationCapFloor::Collar;
69 Real indFlr = type == yoyFlr ? 1.0 : -1.0;
72 auto yts =
model_->irlgm1f(irIdx)->termStructure();
84 for (Size i = 0; i <
arguments_.payDates.size(); ++i) {
88 SimpleCashFlow cf(0.0, payDate);
93 auto df = yts->discount(payDate);
103 const auto& fixingDate =
arguments_.fixingDates[i];
104 if (fixingDate <= today) {
107 auto yoyFixing =
arguments_.index->fixing(fixingDate);
109 if (type == yoyCap || type == yoyClr) {
110 payoff =
max(yoyFixing - c, 0.0);
113 if (type == yoyFlr || type == yoyClr) {
114 payoff += indFlr *
max(f - yoyFixing, 0.0);
117 results_.value += n * g * dt * payoff * df;
122 Date denFixingDate = fixingDate - 1 * Years;
123 auto zts =
model_->infjy(
index_)->realRate()->termStructure();
131 if (type == yoyCap || type == yoyClr) {
132 payoff = blackFormula(Option::Call, c, mean, stdDev, df, 0.0);
134 if (type == yoyFlr || type == yoyClr) {
135 payoff += indFlr * blackFormula(Option::Put, f, mean, stdDev, df, 0.0);
138 results_.value += n * g * dt * payoff;
144 using namespace CrossAssetAnalytics;
161 Real var =
integral(*
model_,
P(
az(i),
az(i),
LC(H_n_T, -1.0,
Hz(i)),
LC(H_n_T, -1.0,
Hz(i))), S, T);
162 var +=
integral(*
model_,
P(
ay(j),
ay(j),
LC(H_r_T, -1.0,
Hy(j)),
LC(H_r_T, -1.0,
Hy(j))), S, T);
164 var -= 2 *
integral(*
model_,
P(
rzy(i, j, 0),
az(i),
LC(H_n_T, -1.0,
Hz(i)),
ay(j),
LC(H_r_T, -1.0,
Hy(j))), S, T);
165 var += 2 *
integral(*
model_,
P(
rzy(i, j, 1),
az(i),
LC(H_n_T, -1.0,
Hz(i)),
sy(j)), S, T);
166 var -= 2 *
integral(*
model_,
P(
ryy(j, j, 0, 1),
ay(j),
LC(H_r_T, -1.0,
Hy(j)),
sy(j)), S, T);
167 var += (H_n_T - H_n_S) * (H_n_T - H_n_S) * z_n_S;
168 var += (H_r_T - H_r_S) * (H_r_T - H_r_S) * z_r_S;
Analytic Jarrow Yildrim (JY) CPI cap floor engine.
Analytic Jarrow Yildrim (JY) year on year cap floor engine.
const Instrument::results * results_
AnalyticJyYoYCapFloorEngine(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, QuantLib::Size index, bool indexIsInterpolated)
QuantLib::Real varianceLogRatio(QuantLib::Time S, QuantLib::Time T) const
bool indexIsInterpolated_
void calculate() const override
const QuantLib::ext::shared_ptr< CrossAssetModel > model_
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.
Jarrow Yildrim (JY) pricer for capped or floored year on year (YoY) inflation coupons.
RandomVariable sqrt(RandomVariable x)
Real jyExpectedIndexRatio(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index, Time S, Time T, bool indexIsInterpolated)
Time inflationTime(const Date &date, const QuantLib::ext::shared_ptr< InflationTermStructure > &inflationTs, bool indexIsInterpolated, const DayCounter &dayCounter)
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)
INF H component. May relate to real rate portion of JY model or z component of DK model.
QuantLib::Real eval(const CrossAssetModel &x, const QuantLib::Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
INF alpha component. May relate to real rate portion of JY model or z component of DK model.
JY INF index sigma component.
INF zeta component. May relate to real rate portion of JY model or z component of DK model.
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
Swap::arguments * arguments_