Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Classes | Functions
QuantExt::CrossAssetAnalytics Namespace Reference

Classes

struct  al
 
struct  ay
 INF alpha component. May relate to real rate portion of JY model or z component of DK model. More...
 
struct  az
 
struct  coms
 
struct  Hl
 
struct  HTtz
 
struct  Hy
 INF H component. May relate to real rate portion of JY model or z component of DK model. More...
 
struct  Hz
 
struct  LC1_
 
struct  LC2_
 
struct  LC3_
 
struct  LC4_
 
struct  P2_
 
struct  P3_
 
struct  P4_
 
struct  P5_
 
struct  rcc
 
struct  rccrs
 
struct  rll
 
struct  rls
 
struct  rss
 
struct  rxcrs
 
struct  rxl
 
struct  rxs
 
struct  rxx
 
struct  rxy
 
struct  ryl
 
struct  rys
 
struct  ryy
 
struct  rzcrs
 
struct  rzl
 
struct  rzs
 
struct  rzx
 
struct  rzy
 
struct  rzz
 
struct  ss
 
struct  sx
 
struct  sy
 JY INF index sigma component. More...
 
struct  vs
 
struct  vx
 
struct  vy
 JY INF index variance component. More...
 
struct  zetal
 
struct  zetay
 INF zeta component. May relate to real rate portion of JY model or z component of DK model. More...
 
struct  zetaz
 

Functions

Real ir_expectation_1 (const CrossAssetModel &x, const Size i, const Time t0, const Real dt)
 
Real ir_expectation_2 (const CrossAssetModel &, const Size, const Real zi_0)
 
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)
 
Real fx_expectation_1 (const CrossAssetModel &x, const Size i, const Time t0, const Real 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 eq_expectation_1 (const CrossAssetModel &x, const Size k, const Time t0, const Real 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 ir_ir_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_fx_covariance (const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
 
Real infz_infz_covariance (const CrossAssetModel &x, const Size i, const Size j, 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 infy_infy_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 ir_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 fx_infy_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 crz_cry_covariance (const CrossAssetModel &x, const Size i, const Size j, 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 ir_crz_covariance (const CrossAssetModel &x, 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 fx_crz_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 infz_crz_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_crz_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 ir_eq_covariance (const CrossAssetModel &x, const Size j, const Size k, 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 infz_eq_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_eq_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 eq_eq_covariance (const CrossAssetModel &x, const Size k, const Size l, const Time t0, const Time dt)
 
Real aux_aux_covariance (const CrossAssetModel &x, const Time t0, const Time dt)
 
Real aux_ir_covariance (const CrossAssetModel &x, 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 com_com_covariance (const CrossAssetModel &x, const Size k, const Size l, 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 fx_com_covariance (const CrossAssetModel &model, 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 infy_com_covariance (const CrossAssetModel &model, 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 crz_com_covariance (const CrossAssetModel &model, 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 ir_crstate_covariance (const CrossAssetModel &x, const Size i, const Size j, const Time t0, const Time dt)
 
Real fx_crstate_covariance (const CrossAssetModel &x, const Size i, const Size j, 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)
 
std::pair< QuantLib::Real, QuantLib::Real > inf_jy_expectation_1 (const CrossAssetModel &model, QuantLib::Size i, QuantLib::Time t0, QuantLib::Real dt)
 
std::pair< QuantLib::Real, QuantLib::Real > inf_jy_expectation_2 (const CrossAssetModel &model, QuantLib::Size i, QuantLib::Time t0, const std::pair< QuantLib::Real, QuantLib::Real > &state_0, QuantLib::Real zi_i_0, QuantLib::Real dt)
 
template<class E >
Real integral_helper (const CrossAssetModel &x, const E &e, const Real t)
 
template<typename E >
Real integral (const CrossAssetModel &model, const E &e, const Real a, const Real b)
 
template<class E1 , class E2 >
const P2_< E1, E2 > P (const E1 &e1, const E2 &e2)
 
template<class E1 , class E2 , class E3 >
const P3_< E1, E2, E3 > P (const E1 &e1, const E2 &e2, const E3 &e3)
 
template<class E1 , class E2 , class E3 , class E4 >
const P4_< E1, E2, E3, E4 > P (const E1 &e1, const E2 &e2, const E3 &e3, const E4 &e4)
 
template<class E1 , class E2 , class E3 , class E4 , class E5 >
const P5_< E1, E2, E3, E4, E5 > P (const E1 &e1, const E2 &e2, const E3 &e3, const E4 &e4, const E5 &e5)
 
template<class E1 >
const LC1_< E1 > LC (QuantLib::Real c, QuantLib::Real c1, const E1 &e1)
 
template<class E1 , class E2 >
const LC2_< E1, E2 > LC (QuantLib::Real c, QuantLib::Real c1, const E1 &e1, QuantLib::Real c2, const E2 &e2)
 
template<class E1 , class E2 , class E3 >
const LC3_< E1, E2, E3 > LC (QuantLib::Real c, QuantLib::Real c1, const E1 &e1, QuantLib::Real c2, const E2 &e2, QuantLib::Real c3, const E3 &e3)
 
template<class E1 , class E2 , class E3 , class E4 >
const LC4_< E1, E2, E3, E4 > LC (QuantLib::Real c, QuantLib::Real c1, const E1 &e1, QuantLib::Real c2, const E2 &e2, QuantLib::Real c3, const E3 &e3, QuantLib::Real c4, const E4 &e4)
 

Detailed Description

CrossAssetAnalytics

This namesace provides a number of functions which compute analytical moments (expectations and covariances) of cross asset model factors. These are used in the exact propagation of cross asset model paths (i.e. without time discretisation error).

Reference: Lichters, Stamm, Gallagher: Modern Derivatives Pricing and Credit Exposure Analysis, Palgrave Macmillan, 2015

See also the documentation in class CrossAssetModel.

Section 16.1 in the reference above lists the analytical expectations and covariances implemented in this namespace. In the following we consider time intervals \((s,t)\). We aim at computing conditional expectations of factors at time \(t\) given their state at time \(s\), likewise covariances of factor moves \(\Delta z\) and \(\Delta x\) over time interval \((s,t)\).

Starting with the interest rate processes

\begin{eqnarray*} dz_i &=& \epsilon_i\,\gamma_i\,dt + \alpha^z_i\,dW^z_i, \qquad \epsilon_i = \left\{ \begin{array}{ll} 0 & i = 0 \\ 1 & i > 0 \end{array}\right. \end{eqnarray*}

we get the factor move by integration

\begin{eqnarray*} \Delta z_i &=& -\int_s^t H^z_i\,(\alpha^z_i)^2\,du + \rho^{zz}_{0i} \int_s^t H^z_0\,\alpha^z_0\,\alpha^z_i\,du\\ && - \epsilon_i \rho^{zx}_{ii}\int_s^t \sigma_i^x\,\alpha^z_i\,du + \int_s^t \alpha^z_i\,dW^z_i. \\ \end{eqnarray*}

Thus, conditional expectation and covariances are

\begin{eqnarray*} \mathbb{E}[\Delta z_i] &=& -\int_s^t H^z_i\,(\alpha^z_i)^2\,du + \rho^{zz}_{0i} \int_s^t H^z_0\,\alpha^z_0\,\alpha^z_i\,du - \epsilon_i \rho^{zx}_{ii}\int_s^t \sigma_i^x\,\alpha^z_i\,du \\ \mathrm{Cov}[\Delta z_a, \Delta z_b] &=& \rho^{zz}_{ab} \int_s^t \alpha^z_a\,\alpha^z_b\,du \end{eqnarray*}

Proceeding similarly with the foreign exchange rate processes

\[ dx_i / x_i = \mu^x_i \, dt +\sigma_i^x\,dW^x_i, \]

we get the following log-moves by integration

\begin{eqnarray*} \Delta \ln x_i &=& \ln \left( \frac{P^n_0(0,s)}{P^n_0(0,t)} \frac{P^n_i(0,t)}{P^n_i(0,s)}\right) - \frac12 \int_s^t (\sigma^x_i)^2\,du + \rho^{zx}_{0i}\int_s^t H^z_0\, \alpha^z_0\, \sigma^x_i \,du\nonumber\\ &&+\int_s^t \zeta^z_0\,H^z_0\, (H^z_0)^{\prime}\,du-\int_s^t \zeta^z_i\,H^z_i\, (H^z_i)^{\prime}\,du\nonumber\\ &&+ \int_s^t \left(H^z_0(t)-H^z_0\right)\alpha_0^z\,dW^z_0+ \left(H^z_0(t)-H^z_0(s)\right) z_0(s) \nonumber\\ &&- \int_s^t \left(H^z_i(t)-H^z_i\right)\alpha_i^z\,dW^z_i -\left(H^z_i(t)-H^z_i(s)\right)z_i(s) \nonumber\\ &&- \int_s^t \left(H^z_i(t)-H^z_i\right)\gamma_i\,du + \int_s^t\sigma^x_i dW^x_i \nonumber \end{eqnarray*}

Integration by parts yields

\begin{eqnarray*} && \int_s^t \zeta^z_0\,H^z_0\, (H^z_0)^{\prime}\,du-\int_s^t \zeta^z_i\,H^z_i\, (H^z_i)^{\prime}\,du\\ && = \frac12 \left((H^z_0(t))^2 \zeta^z_0(t) - (H^z_0(s))^2 \zeta^z_0(s)- \int_s^t (H^z_0)^2 (\alpha^z_0)^2\,du\right)\nonumber\\ &&\qquad {}- \frac12 \left((H^z_i(t))^2 \zeta^z_i(t) - (H^z_i(s))^2 \zeta^z_i(s)-\int_s^t (H^z_i)^2 (\alpha^z_i)^2\,du \right) \end{eqnarray*}

so that the expectation is

\begin{eqnarray} \mathbb{E}[\Delta \ln x_i] &=& \ln \left( \frac{P^n_0(0,s)}{P^n_0(0,t)} \frac{P^n_i(0,t)}{P^n_i(0,s)}\right) - \frac12 \int_s^t (\sigma^x_i)^2\,du + \rho^{zx}_{0i} \int_s^t H^z_0\, \alpha^z_0\, \sigma^x_i\,du\nonumber\\ &&+\frac12 \left((H^z_0(t))^2 \zeta^z_0(t) - (H^z_0(s))^2 \zeta^z_0(s)- \int_s^t (H^z_0)^2 (\alpha^z_0)^2\,du\right)\nonumber\\ &&-\frac12 \left((H^z_i(t))^2 \zeta^z_i(t) - (H^z_i(s))^2 \zeta^z_i(s)-\int_s^t (H^z_i)^2 (\alpha^z_i)^2\,du \right)\nonumber\\ &&+ \left(H^z_0(t)-H^z_0(s)\right) z_0(s) -\left(H^z_i(t)-H^z_i(s)\right)z_i(s)\nonumber\\ && - \int_s^t \left(H^z_i(t)-H^z_i\right)\gamma_i \,du, \label{eq:meanX} \end{eqnarray}

and IR-FX and FX-FX covariances are

\begin{eqnarray} \mathrm{Cov}[\Delta \ln x_a, \Delta \ln x_b] &=& \int_s^t \left(H^z_0(t)-H^z_0\right)^2 (\alpha_0^z)^2\,du \nonumber\\ &&- \rho^{zz}_{0b}\int_s^t \left(H^z_0(t)-H^z_0\right)\alpha_0^z \left(H^z_b(t)-H^z_b\right)\alpha_b^z\,du \nonumber\\ &&+ \rho^{zx}_{0b}\int_s^t \left(H^z_0(t)-H^z_0\right)\alpha_0^z \sigma^x_b\,du \nonumber\\ && -\rho^{zz}_{0a} \int_s^t \left(H^z_a(t)-H^z_a\right) \alpha_a^z\left(H^z_0(t)-H^z_0\right) \alpha_0^z\,du \nonumber\\ &&+ \rho^{zz}_{ab}\int_s^t \left(H^z_a(t)-H^z_a\right)\alpha_a^z \left(H^z_b(t)-H^z_b\right)\alpha_b^z\,du \nonumber\\ &&- \rho^{zx}_{ab}\int_s^t \left(H^z_a(t)-H^z_a\right)\alpha_a^z \sigma^x_b,du\nonumber\\ &&+ \rho^{zx}_{0a}\int_s^t \left(H^z_0(t)-H^z_0\right)\alpha_0^z\,\sigma^x_a\,du \nonumber\\ &&- \rho^{zx}_{ba}\int_s^t \left(H^z_b(t)-H^z_b\right)\alpha_b^z\,\sigma^x_a\, du \nonumber\\ &&+ \rho^{xx}_{ab}\int_s^t\sigma^x_a\,\sigma^x_b \,du \label{eq:covXX}\\ &&\nonumber\\ \mathrm{Cov} [\Delta z_a, \Delta \ln x_b]) &=& \rho^{zz}_{0a}\int_s^t \left(H^z_0(t)-H^z_0\right) \alpha^z_0\,\alpha^z_a\,du \nonumber\\ &&- \rho^{zz}_{ab}\int_s^t \alpha^z_a \left(H^z_b(t)-H^z_b\right) \alpha^z_b \,du \nonumber\\ &&+\rho^{zx}_{ab}\int_s^t \alpha^z_a \, \sigma^x_b \,du. \label{eq:covZX} \end{eqnarray}

Based on these expectations of factor moves and log-moves, respectively, we can work out the conditonal expectations of the factor levels at time \(t\). These expectations have state-dependent parts (levels at time \(s\)) and state-independent parts which we separate in the implementation, see functions ending with "_1" and "_2", respectively. Moreover, the implementation splits up the integrals further in order to separate simple and more complex integrations and to allow for tailored efficient numerical integration schemes.

In the following we rearrange the expectations and covariances above such that the expressions correspond 1:1 to their implementations below.

Function Documentation

◆ inf_jy_expectation_1()

pair< Real, Real > inf_jy_expectation_1 ( const CrossAssetModel x,
Size  i,
Time  t0,
Real  dt 
)

Definition at line 45 of file crossassetanalytics.cpp.

45 {
46
47 QL_REQUIRE(x.modelType(CrossAssetModel::AssetType::INF, i) == CrossAssetModel::ModelType::JY,
48 "inf_jy_expectation_1: should only be used for JY CAM inflation component.");
49
50 auto res = make_pair(0.0, 0.0);
51
52 // 1) Real rate process drift
53 res.first = -integral(x, P(Hy(i), ay(i), ay(i)), t0, t0 + dt) +
54 integral(x, P(rzy(0, i), Hz(0), az(0), ay(i)), t0, t0 + dt) -
55 integral(x, P(ryy(i, i, 0, 1), ay(i), sy(i)), t0, t0 + dt);
56
57 // i_i - index of i-th inflation component's currency.
58 Size i_i = x.ccyIndex(x.infjy(i)->currency());
59 if (i_i > 0) {
60 res.first -= integral(x, P(rxy(i_i - 1, i, 0), ay(i), sx(i_i - 1)), t0, t0 + dt);
61 }
62
63 // 2) Inflation index process drift
64 const auto& zts = x.infjy(i)->realRate()->termStructure();
65 bool indexIsInterpolated = true; // FIXME, see also crossassetmodel.cpp line 706ff
66 res.second =
67 std::log(inflationGrowth(zts, t0 + dt, indexIsInterpolated) / inflationGrowth(zts, t0, indexIsInterpolated));
68
69 res.second -= 0.5 * (vy(i).eval(x, t0 + dt) - vy(i).eval(x, t0));
70
71 // Final _s means start of period i.e. t_0 and _e means end of period i.e. t_0 + dt
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);
76 Real zetai_i_s = zetaz(i_i).eval(x, t0);
77 Real zetai_s = zetay(i).eval(x, t0);
78 Real zetai_i_e = zetaz(i_i).eval(x, t0 + dt);
79 Real zetai_e = zetay(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);
83 res.second += 0.5 * integral(x, P(Hy(i), Hy(i), ay(i), ay(i)), t0, t0 + dt);
84
85 res.second += integral(x, P(rzy(0, i, 1), Hz(0), az(0), sy(i)), t0, t0 + dt);
86
87 res.second -=
88 integral(x,
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)))),
91 t0, t0 + dt);
92
93 if (i_i > 0) {
94 res.second += integral(x,
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)))),
98 t0, t0 + dt);
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);
101 }
102
103 return res;
104}
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 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)
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.
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inf_jy_expectation_2()

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 
)

Definition at line 106 of file crossassetanalytics.cpp.

107 {
108
109 QL_REQUIRE(x.modelType(CrossAssetModel::AssetType::INF, i) == CrossAssetModel::ModelType::JY,
110 "inf_jy_expectation_2: should only be used for JY CAM inflation component.");
111
112 // i_i - index of i-th inflation component's currency.
113 Size i_i = x.ccyIndex(x.infjy(i)->currency());
114
115 // Real rate portion of the result i.e. first element in pair is not state dependent so nothing needed.
116 // The inflation index portion of the result i.e. second element needs to be updated.
117 auto res = state_0;
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;
120
121 return res;
122}
+ Here is the call graph for this function:
+ Here is the caller graph for this function: