27namespace CrossAssetAnalytics {
48 "inf_jy_expectation_1: should only be used for JY CAM inflation component.");
50 auto res = make_pair(0.0, 0.0);
60 res.first -=
integral(x,
P(
rxy(i_i - 1, i, 0),
ay(i),
sx(i_i - 1)), t0, t0 + dt);
64 const auto& zts = x.
infjy(i)->realRate()->termStructure();
65 bool indexIsInterpolated =
true;
69 res.second -= 0.5 * (
vy(i).
eval(x, t0 + dt) -
vy(i).
eval(x, t0));
72 Real Hi_i_s =
Hz(i_i).
eval(x, t0);
73 Real Hi_s =
Hy(i).
eval(x, t0);
74 Real Hi_i_e =
Hz(i_i).
eval(x, t0 + dt);
75 Real Hi_e =
Hy(i).
eval(x, t0 + dt);
78 Real zetai_i_e =
zetaz(i_i).
eval(x, t0 + dt);
80 res.second += 0.5 * (Hi_i_e * Hi_i_e * zetai_i_e - Hi_i_s * Hi_i_s * zetai_i_s);
81 res.second -= 0.5 *
integral(x,
P(
Hz(i_i),
Hz(i_i),
az(i_i),
az(i_i)), t0, t0 + dt);
82 res.second -= 0.5 * (Hi_e * Hi_e * zetai_e - Hi_s * Hi_s * zetai_s);
89 P(
LC(Hi_e, -1.0,
Hy(i)),
LC(0.0, -1.0,
P(
Hy(i),
ay(i),
ay(i)), 1.0,
P(
Hz(0),
az(0),
ay(i),
rzy(0, i)),
90 -1.0,
P(
ryy(i, i, 0, 1),
ay(i),
sy(i)))),
95 P(
LC(Hi_i_e, -1.0,
Hz(i_i)),
96 LC(0.0, -1.0,
P(
Hz(i_i),
az(i_i),
az(i_i)), 1.0,
P(
Hz(0),
az(0),
az(i_i),
rzz(0, i_i)),
97 -1.0,
P(
rzx(i_i, i_i - 1),
az(i_i),
sx(i_i - 1)))),
99 res.second -=
integral(x,
P(
rxy(i_i - 1, i, 1),
sy(i),
sx(i_i - 1)), t0, t0 + dt);
100 res.second +=
integral(x,
P(
LC(Hi_e, -1.0,
Hy(i)),
ay(i),
sx(i_i - 1),
rxy(i_i - 1, i)), t0, t0 + dt);
107 Real zi_i_0, Real dt) {
110 "inf_jy_expectation_2: should only be used for JY CAM inflation component.");
118 res.second += (
Hz(i_i).
eval(x, t0 + dt) -
Hz(i_i).
eval(x, t0)) * zi_i_0;
119 res.second -= (
Hy(i).
eval(x, t0 + dt) -
Hy(i).
eval(x, t0)) * state_0.first;
126 Real H0_a =
Hz(0).
eval(x, t0);
127 Real Hi_a =
Hz(i + 1).
eval(x, t0);
128 Real H0_b =
Hz(0).
eval(x, t0 + dt);
129 Real Hi_b =
Hz(i + 1).
eval(x, t0 + dt);
132 Real zeta0_b =
zetaz(0).
eval(x, t0 + dt);
133 Real zetai_b =
zetaz(i + 1).
eval(x, t0 + dt);
134 Real res = std::log(x.
irlgm1f(i + 1)->termStructure()->discount(t0 + dt) /
135 x.
irlgm1f(i + 1)->termStructure()->discount(t0) * x.
irlgm1f(0)->termStructure()->discount(t0) /
136 x.
irlgm1f(0)->termStructure()->discount(t0 + dt));
137 res -= 0.5 * (
vx(i).
eval(x, t0 + dt) -
vx(i).
eval(x, t0));
139 0.5 * (H0_b * H0_b * zeta0_b - H0_a * H0_a * zeta0_a -
integral(x,
P(
Hz(0),
Hz(0),
az(0),
az(0)), t0, t0 + dt));
140 res -= 0.5 * (Hi_b * Hi_b * zetai_b - Hi_a * Hi_a * zetai_a -
143 res -= Hi_b * (-
integral(x,
P(
Hz(i + 1),
az(i + 1),
az(i + 1)), t0, t0 + dt) +
146 res += -
integral(x,
P(
Hz(i + 1),
Hz(i + 1),
az(i + 1),
az(i + 1)), t0, t0 + dt) +
157 const Real z0_0,
const Real dt) {
158 Real res = xi_0 + (
Hz(0).
eval(x, t0 + dt) -
Hz(0).
eval(x, t0)) * z0_0 -
159 (
Hz(i + 1).
eval(x, t0 + dt) -
Hz(i + 1).
eval(x, t0)) * zi_0;
165 Size eps_i = (i == 0) ? 0 : 1;
166 Real Hi_a =
Hz(i).
eval(x, t0);
167 Real Hi_b =
Hz(i).
eval(x, t0 + dt);
169 Real zetai_b =
zetaz(i).
eval(x, t0 + dt);
171 x.
eqbs(k)->equityDivYieldCurveToday()->discount(t0 + dt) / x.
eqbs(k)->equityDivYieldCurveToday()->discount(t0) *
172 x.
eqbs(k)->equityIrCurveToday()->discount(t0) / x.
eqbs(k)->equityIrCurveToday()->discount(t0 + dt));
173 res -= 0.5 * (
vs(k).
eval(x, t0 + dt) -
vs(k).
eval(x, t0));
175 0.5 * (Hi_b * Hi_b * zetai_b - Hi_a * Hi_a * zetai_a -
integral(x,
P(
Hz(i),
Hz(i),
az(i),
az(i)), t0, t0 + dt));
195 Real Hi_a =
Hz(i).
eval(x, t0);
196 Real Hi_b =
Hz(i).
eval(x, t0 + dt);
197 Real res = sk_0 + (Hi_b - Hi_a) * zi_0;
216 Real H0 =
Hz(0).
eval(x, t0 + dt);
217 Real Hi =
Hz(i + 1).
eval(x, t0 + dt);
218 Real Hj =
Hz(j + 1).
eval(x, t0 + dt);
247 Hi * Hj *
integral(x,
P(
az(i + 1),
az(j + 1),
rzz(i + 1, j + 1)), t0, t0 + dt) -
248 Hj *
integral(x,
P(
Hz(i + 1),
az(i + 1),
az(j + 1),
rzz(i + 1, j + 1)), t0, t0 + dt) -
249 Hi *
integral(x,
P(
Hz(j + 1),
az(j + 1),
az(i + 1),
rzz(j + 1, i + 1)), t0, t0 + dt) +
272 Real Hi_j =
Hz(i_j).
eval(x, t0 + dt);
274 Real Hj =
Hy(j).
eval(x, t0 + dt);
298 Real Hi_i =
Hz(i_i).
eval(x, t0 + dt);
300 Real Hi =
Hy(i).
eval(x, t0 + dt);
303 res =
integral(x,
P(
rzy(i_i, j),
Hy(j),
ay(j),
az(i_i),
LC(Hi_i, -1.0,
Hz(i_i))), t0, t0 + dt);
304 res -=
integral(x,
P(
ryy(i, j, 0, 0),
Hy(j),
ay(j),
ay(i),
LC(Hi, -1.0,
Hy(i))), t0, t0 + dt);
312 Real Hi_j =
Hz(i_j).
eval(x, t0 + dt);
314 Real Hj =
Hy(j).
eval(x, t0 + dt);
317 res =
integral(x,
P(
rzy(i_j, i),
Hy(i),
ay(i),
az(i_j),
LC(Hi_j, -1.0,
Hz(i_j))), t0, t0 + dt);
318 res -=
integral(x,
P(
ryy(i, j, 0, 0),
Hy(i),
ay(i),
ay(j),
LC(Hj, -1.0,
Hy(j))), t0, t0 + dt);
327 Real Hi_i =
Hz(i_i).
eval(x, t0 + dt);
328 Real Hi_j =
Hz(i_j).
eval(x, t0 + dt);
330 Real Hi =
Hy(i).
eval(x, t0 + dt);
331 Real Hj =
Hy(j).
eval(x, t0 + dt);
333 res =
integral(x,
P(
rzz(i_i, i_j),
az(i_i),
LC(Hi_i, -1.0,
Hz(i_i)),
az(i_j),
LC(Hi_j, -1.0,
Hz(i_j))), t0,
336 integral(x,
P(
rzy(i_i, j, 0),
az(i_i),
LC(Hi_i, -1.0,
Hz(i_i)),
ay(j),
LC(Hj, -1.0,
Hy(j))), t0, t0 + dt);
337 res +=
integral(x,
P(
rzy(i_i, j, 1),
az(i_i),
LC(Hi_i, -1.0,
Hz(i_i)),
sy(j)), t0, t0 + dt);
339 integral(x,
P(
rzy(i_j, i, 0),
ay(i),
LC(Hi, -1.0,
Hy(i)),
az(i_j),
LC(Hi_j, -1.0,
Hz(i_j))), t0, t0 + dt);
340 res +=
integral(x,
P(
ryy(i, j),
ay(i),
LC(Hi, -1.0,
Hy(i)),
ay(j),
LC(Hj, -1.0,
Hy(j))), t0, t0 + dt);
341 res -=
integral(x,
P(
ryy(i, j, 0, 1),
ay(i),
LC(Hi, -1.0,
Hy(i)),
sy(j)), t0, t0 + dt);
342 res +=
integral(x,
P(
rzy(i_j, i, 1),
sy(i),
az(i_j),
LC(Hi_j, -1.0,
Hz(i_j))), t0, t0 + dt);
343 res -=
integral(x,
P(
ryy(i, j, 1, 0),
sy(i),
ay(j),
LC(Hj, -1.0,
Hy(j))), t0, t0 + dt);
362 Real Hi_j =
Hz(i_j).
eval(x, t0 + dt);
364 Real Hj =
Hy(j).
eval(x, t0 + dt);
367 res -=
integral(x,
P(
rzy(i, j, 0),
az(i),
ay(j),
LC(Hj, -1.0,
Hy(j))), t0, t0 + dt);
375 Real H0 =
Hz(0).
eval(x, t0 + dt);
376 Real Hi =
Hz(i + 1).
eval(x, t0 + dt);
388 Real H0 =
Hz(0).
eval(x, t0 + dt);
389 Real Hi =
Hz(i + 1).
eval(x, t0 + dt);
402 Real Hi_j =
Hz(i_j).
eval(x, t0 + dt);
404 Real Hj =
Hy(j).
eval(x, t0 + dt);
406 res =
integral(x,
P(
rzz(i_j, 0),
az(i_j),
LC(Hi_j, -1.0,
Hz(i_j)),
az(0),
LC(H0, -1.0,
Hz(0))), t0, t0 + dt);
407 res -=
integral(x,
P(
rzz(i_j, i + 1),
az(i_j),
LC(Hi_j, -1.0,
Hz(i_j)),
az(i + 1),
LC(Hi, -1.0,
Hz(i + 1))), t0,
410 res -=
integral(x,
P(
rzy(0, j, 0),
ay(j),
LC(Hj, -1.0,
Hy(j)),
az(0),
LC(H0, -1.0,
Hz(0))), t0, t0 + dt);
411 res +=
integral(x,
P(
rzy(i + 1, j, 0),
ay(j),
LC(Hj, -1.0,
Hy(j)),
az(i + 1),
LC(Hi, -1.0,
Hz(i + 1))), t0,
414 res +=
integral(x,
P(
rzy(0, j, 1),
sy(j),
az(0),
LC(H0, -1.0,
Hz(0))), t0, t0 + dt);
415 res -=
integral(x,
P(
rzy(i + 1, j, 1),
sy(j),
az(i + 1),
LC(Hi, -1.0,
Hz(i + 1))), t0, t0 + dt);
448 Real H0 =
Hz(0).
eval(x, t0 + dt);
449 Real Hi =
Hz(i + 1).
eval(x, t0 + dt);
459 Real H0 =
Hz(0).
eval(x, t0 + dt);
460 Real Hi =
Hz(i + 1).
eval(x, t0 + dt);
489 Real Hi_i =
Hz(i_i).
eval(x, t0 + dt);
491 Real Hi =
Hy(i).
eval(x, t0 + dt);
494 res -=
integral(x,
P(
ryl(i, j, 0),
ay(i),
LC(Hi, -1.0,
Hy(i)),
al(j)), t0, t0 + dt);
511 Real Hi_i =
Hz(i_i).
eval(x, t0 + dt);
513 Real Hi =
Hy(i).
eval(x, t0 + dt);
515 res =
integral(x,
P(
rzl(i_i, j),
az(i_i),
LC(Hi_i, -1.0,
Hz(i_i)),
Hl(j),
al(j)), t0, t0 + dt);
516 res -=
integral(x,
P(
ryl(i, j, 0),
ay(i),
LC(Hi, -1.0,
Hy(i)),
Hl(j),
al(j)), t0, t0 + dt);
525 Real Hi_b =
Hz(i).
eval(x, t0 + dt);
534 const Size& j_lgm = j + 1;
535 Real Hi_b =
Hz(i).
eval(x, t0 + dt);
536 Real Hj_b =
Hz(j_lgm).
eval(x, t0 + dt);
537 Real H0_b =
Hz(0).
eval(x, t0 + dt);
543 res -= Hi_b * Hj_b *
integral(x,
P(
rzz(j_lgm, i),
az(j_lgm),
az(i)), t0, t0 + dt);
544 res += Hi_b *
integral(x,
P(
Hz(j_lgm),
rzz(j_lgm, i),
az(j_lgm),
az(i)), t0, t0 + dt);
562 Real Hk =
Hz(k).
eval(x, t0 + dt);
572 Real Hk =
Hz(k).
eval(x, t0 + dt);
584 Real Hi_i =
Hz(i_i).
eval(x, t0 + dt);
586 Real Hi =
Hy(i).
eval(x, t0 + dt);
588 res =
integral(x,
P(
rzz(i_i, k),
az(i_i),
LC(Hi_i, -1.0,
Hz(i_i)),
az(k),
LC(Hk, -1.0,
Hz(k))), t0, t0 + dt);
590 res -=
integral(x,
P(
rzy(k, i, 0),
ay(i),
LC(Hi, -1.0,
Hy(i)),
az(k),
LC(Hk, -1.0,
Hz(k))), t0, t0 + dt);
591 res -=
integral(x,
P(
rys(i, j, 0),
ay(i),
LC(Hi, -1.0,
Hy(i)),
ss(j)), t0, t0 + dt);
592 res +=
integral(x,
P(
rzy(k, i, 1),
sy(i),
az(k),
LC(Hk, -1.0,
Hz(k))), t0, t0 + dt);
601 Real Hk_b =
Hz(k).
eval(x, t0 + dt);
610 Real Hk_b =
Hz(k).
eval(x, t0 + dt);
620 Real Hi_b =
Hz(i).
eval(x, t0 + dt);
621 Real Hj_b =
Hz(j).
eval(x, t0 + dt);
656 auto cmk = QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzModel>(x.
comModel(k));
657 auto cml = QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzModel>(x.
comModel(l));
658 QL_REQUIRE(cmk && cml,
"CommoditySchwartzModel expected in com-com covariance calculation");
659 QL_REQUIRE(cmk->parametrization()->driftFreeState() == cml->parametrization()->driftFreeState(),
660 "commodity state types do not match");
661 if (!cmk->parametrization()->driftFreeState()) {
662 Real kk = cmk->parametrization()->kappaParameter();
663 Real kl = cml->parametrization()->kappaParameter();
664 Real sk = cmk->parametrization()->sigmaParameter();
665 Real sl = cml->parametrization()->sigmaParameter();
667 if (fabs((kk + kl) * dt) < QL_EPSILON)
668 res = rho * sk * sl * dt;
670 res = rho * sk * sl / (kk + kl) * (1.0 - std::exp(-(kk + kl) * dt));
678 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero IR-COM correlation not implemented yet");
685 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero FX-COM correlation not implemented yet");
692 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero INF-COM correlation not implemented yet");
699 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero INF-COM correlation not implemented yet");
706 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero CR-COM correlation not implemented yet");
713 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero CR-COM correlation not implemented yet");
720 QL_REQUIRE(
close_enough(corr, 0.0),
"non-zero EQ-COM correlation not implemented yet");
const QuantLib::ext::shared_ptr< IrLgm1fParametrization > irlgm1f(const Size ccy) const
const QuantLib::ext::shared_ptr< EqBsParametrization > eqbs(const Size ccy) const
const QuantLib::ext::shared_ptr< InfJyParameterization > infjy(const Size i) const
Inflation JY component.
Size ccyIndex(const Currency &ccy) const
ModelType modelType(const AssetType t, const Size i) const
const QuantLib::ext::shared_ptr< CommodityModel > comModel(const Size com) const
const Matrix & correlation() const
IrModel::Measure measure() const
analytics for the cross asset model
Real ir_expectation_2(const CrossAssetModel &, const Size, const Real zi_0)
Real com_com_covariance(const CrossAssetModel &x, const Size k, const Size l, const Time t0, const Time dt)
Real fx_fx_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_fx_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real fx_infy_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real infy_infy_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real cry_eq_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real ir_cry_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_infy_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real fx_cry_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_eq_covariance(const CrossAssetModel &x, const Size j, const Size k, const Time t0, const Time dt)
Real infz_infy_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real fx_infz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real infy_crz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_expectation_1(const CrossAssetModel &x, const Size i, const Time t0, const Real dt)
const LC1_< E1 > LC(QuantLib::Real c, QuantLib::Real c1, const E1 &e1)
Real ir_crz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real infz_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real eq_expectation_1(const CrossAssetModel &x, const Size k, const Time t0, const Real dt)
Real fx_crz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real crz_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real aux_fx_covariance(const CrossAssetModel &x, const Size j, const Time t0, const Time dt)
Real eq_expectation_2(const CrossAssetModel &x, const Size k, const Time t0, const Real sk_0, const Real zi_0, const Real dt)
Real infz_infz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real cry_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real infz_eq_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real infy_cry_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real crz_cry_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real eq_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real fx_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real infz_crz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real fx_expectation_2(const CrossAssetModel &x, const Size i, const Time t0, const Real xi_0, const Real zi_0, const Real z0_0, const Real dt)
Real infy_com_covariance(const CrossAssetModel &model, const Size i, const Size j, const Time t0, const Time dt)
Real ir_ir_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_infz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real aux_ir_covariance(const CrossAssetModel &x, const Size j, const Time t0, const Time dt)
Real aux_aux_covariance(const CrossAssetModel &x, const Time t0, const Time dt)
Real crstate_crstate_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real fx_eq_covariance(const CrossAssetModel &x, const Size j, const Size k, const Time t0, const Time dt)
Real cry_cry_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real integral(const CrossAssetModel &model, const E &e, const Real a, const Real b)
Real crz_eq_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real ir_crstate_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
const P2_< E1, E2 > P(const E1 &e1, const E2 &e2)
Real fx_crstate_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real infz_cry_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real infy_eq_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real crz_crz_covariance(const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
Real eq_eq_covariance(const CrossAssetModel &x, const Size k, const Size l, const Time t0, const Time dt)
Real fx_expectation_1(const CrossAssetModel &x, const Size i, const Time t0, const Real dt)
some inflation related utilities.
pair< Real, Real > inf_jy_expectation_1(const CrossAssetModel &x, Size i, Time t0, Real dt)
pair< Real, Real > inf_jy_expectation_2(const CrossAssetModel &x, Size i, Time t0, const pair< Real, Real > &state_0, Real zi_i_0, Real dt)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
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.
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.
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
JY INF index variance component.
QuantLib::Real eval(const CrossAssetModel &x, const QuantLib::Real t) const
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