Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetanalytics.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/models/crossassetanalytics.hpp
20 \brief analytics for the cross asset model
21 \ingroup crossassetmodel
22*/
23
24#ifndef quantext_crossasset_analytics_hpp
25#define quantext_crossasset_analytics_hpp
26
29
30namespace QuantExt {
31using namespace QuantLib;
32
33namespace CrossAssetAnalytics {
34
35/*! \addtogroup crossassetmodel
36 @{
37*/
38
39/*! IR state expectation
40
41 This function evaluates part of the expectation \f$ \mathbb{E}_{t_0}[z_i(t_0+dt)]\f$.
42
43 Using the results above for factor moves \f$\Delta z\f$ over time interval \f$(s,t)\f$,
44 we have
45
46 \f{eqnarray}{
47 \mathbb{E}_{t_0}[z_i(t_0+\Delta t)] &=& z_i(t_0) + \mathbb{E}_{t_0}[\Delta z_i],
48 \qquad\mbox{with}\quad \Delta z_i = z_i(t_0+\Delta t) - z_i(t_0) \\
49 &=& z_i(t_0) -\int_{t_0}^{t_0+\Delta t} H^z_i\,(\alpha^z_i)^2\,du + \rho^{zz}_{0i} \int_{t_0}^{t_0+\Delta t}
50 H^z_0\,\alpha^z_0\,\alpha^z_i\,du
51 - \epsilon_i \rho^{zx}_{ii}\int_{t_0}^{t_0+\Delta t} \sigma_i^x\,\alpha^z_i\,du
52 \f}
53
54 This function covers the latter three integrals, the state-independent part.
55
56*/
57Real ir_expectation_1(const CrossAssetModel& model, const Size i, const Time t0, const Real dt);
58
59/*! IR state expectation
60 This function evaluates the state-dependent part of the expectation
61
62 \f{eqnarray}{
63 \mathbb{E}_{t_0}[z_i(t_0+\Delta t)]
64 &=& z_i(t_0) -\int_{t_0}^{t_0+\Delta t} H^z_i\,(\alpha^z_i)^2\,du + \rho^{zz}_{0i} \int_{t_0}^{t_0+\Delta t}
65 H^z_0\,\alpha^z_0\,\alpha^z_i\,du
66 - \epsilon_i \rho^{zx}_{ii}\int_{t_0}^{t_0+\Delta t} \sigma_i^x\,\alpha^z_i\,du
67 \f}
68
69 i.e. simply the first contribution \f$ z_i(t_0) \f$.
70
71*/
72Real ir_expectation_2(const CrossAssetModel& model, const Size i, const Real zi_0);
73
74/*! State independent portion of the JY inflation drift. The first element of the pair relates to the real rate
75 process and the second element of the pair relates to the inflation index process.
76*/
77std::pair<QuantLib::Real, QuantLib::Real> inf_jy_expectation_1(const CrossAssetModel& model, QuantLib::Size i,
78 QuantLib::Time t0, QuantLib::Real dt);
79
80/*! State dependent portion of the JY inflation drift. The first element of the pair relates to the real rate
81 process and the second element of the pair relates to the inflation index process.
82*/
83std::pair<QuantLib::Real, QuantLib::Real> inf_jy_expectation_2(const CrossAssetModel& model, QuantLib::Size i,
84 QuantLib::Time t0,
85 const std::pair<QuantLib::Real, QuantLib::Real>& state_0,
86 QuantLib::Real zi_i_0, QuantLib::Real dt);
87
88/*! FX state expectation
89
90 This function evaluates part of the expectation \f$ \mathbb{E}_{t_0}[\ln x_i(t_0+dt)]\f$.
91
92 Using the results above for factor moves \f$\Delta \ln x\f$ over time interval \f$(s,t)\f$,
93 we have
94
95 \f{eqnarray}{
96 \mathbb{E}_{t_0}[\ln x_i(t_0+\Delta t)] &=& \ln x_i(t_0) + \mathbb{E}_{t_0}[\Delta \ln x_i],
97 \qquad\mbox{with}\quad \Delta \ln x_i = \ln x_i(t_0+\Delta t) - \ln x_i(t_0) \\
98 &=& \ln x_i(t_0) + \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)\\
99 &&+ \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) \\
100 && - \frac12 \int_s^t (\sigma^x_i)^2\,du \\
101 &&+\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
102 (\alpha^z_0)^2\,du\right)\\
103 &&-\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
104 \right)\\
105 && + \rho^{zx}_{0i} \int_s^t H^z_0\, \alpha^z_0\, \sigma^x_i\,du \\
106 && - \int_s^t \left(H^z_i(t)-H^z_i\right)\gamma_i \,du, \qquad\mbox{with}\quad s = t_0, \quad t = t_0+\Delta t
107 \f}
108
109 where we rearranged terms so that the state-dependent terms are listed on the first line
110 (containing \f$\ln x_i(t_0), z_i(t_0), z_0(t_0) \f$)
111 and all following terms are state-independent (deterministic, just dependent on initial market data and model
112 parameters).
113
114 The last integral above contains \f$\gamma_i\f$ which is (see documentation of the CrossAssetModel)
115 \f[
116 \gamma_i = -H^z_i\,(\alpha^z_i)^2 + H^z_0\,\alpha^z_0\,\alpha^z_i\,\rho^{zz}_{0i} - \sigma_i^x\,\alpha^z_i\,
117 \rho^{zx}_{ii}.
118 \f]
119 The very last last integral above is therefore broken up into six terms which we do not list
120 here, but which show up in this function's implementation.
121
122 This function covers the latter state-independent part of the FX expectation.
123*/
124Real fx_expectation_1(const CrossAssetModel& model, const Size i, const Time t0, const Real dt);
125
126/*! FX state expectation.
127
128 This function covers the state-dependent part of the FX expectation.
129*/
130Real fx_expectation_2(const CrossAssetModel& model, const Size i, const Time t0, const Real xi_0, const Real zi_0,
131 const Real z0_0, const Real dt);
132
133/*! EQ state expectation
134
135 This function covers part of the EQ expectation.
136 The overall expectation formula (taken from the book "Modern Derivatives Pricing and Credit Exposure Analysis"
137 by Lichters, Stamm and Gallagher) is as follows:
138
139 \f{eqnarray}{
140 \mathbb{E} \left[\Delta ln[s_k]\right] &=& ln \left[ \frac{P_{\phi(k)}(0,s)}{P_{\phi(k)}(0,t)} \right] -
141 \int_{s}^{t} q_k(u) du - \frac{1}{2} \int_{s}^{t}\sigma_{s_k}^2(u) du\\
142 &&
143 +\rho_{z_0,s_k}\int_{s}^{t}\alpha_0(u) H_0(u) \sigma_{s_k}(u) du
144 - \epsilon_{\phi(k)} \rho_{s_k,x_{\phi(k)}} \int_{s}^{t} \sigma_{s_k}(u)\sigma_{x_{\phi(k)}}(u) du\\
145 &&+\frac{1}{2} \left( H_{\phi(k)}^2(t) \zeta_{\phi(k)}(t) - H_{\phi(k)}^2(s) \zeta_{\phi(k)}(s)
146 - \int_{s}^{t} H_{\phi(k)}^2(u) \alpha_{\phi(k)}^2(u) du \right)\\
147 && + (H_{\phi(k)}(t) - H_{\phi(k)}(s)) z_{\phi(k)}(s)
148 +\epsilon_{\phi(k)} \int_{s}^{t} \gamma_{\phi(k)} (u) (H_{\phi(k)}(t) - H_{\phi(k)}(u)) du,\\
149 && \qquad\mbox{with}\quad s = t_0, \quad t = t_0+\Delta t, \quad \phi(k) = \qquad\mbox{ interest rate for currency
150 of equity k}
151 \f}
152
153 This function covers the state-independent part of the EQ expectation
154*/
155Real eq_expectation_1(const CrossAssetModel& model, const Size i, const Time t0, const Real dt);
156
157/*! EQ state expectation
158
159This function covers the state-dependent part of the EQ expectation (see overall expression above).
160*/
161Real eq_expectation_2(const CrossAssetModel& model, const Size k, const Time t0, const Real si_0, const Real zi_0,
162 const Real dt);
163
164/*! IR-IR Covariance
165
166 This function evaluates the covariance term
167
168 \f{eqnarray*}{
169 \mathrm{Cov}[\Delta z_a, \Delta z_b] &=& \rho^{zz}_{ab} \int_s^t \alpha^z_a\,\alpha^z_b\,du
170 \f}
171
172 on the time interval from \f$ s= t_0\f$ to \f$ t=t_0+\Delta t\f$.
173*/
174Real ir_ir_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
175
176/*! IR-FX Covariance
177
178 This function evaluates the covariance term
179
180 \f{eqnarray}{
181 \mathrm{Cov} [\Delta z_a, \Delta \ln x_b]) &=& \rho^{zz}_{0a}\int_s^t \left(H^z_0(t)-H^z_0\right)
182 \alpha^z_0\,\alpha^z_a\,du \nonumber\\
183 &&- \rho^{zz}_{ab}\int_s^t \alpha^z_a \left(H^z_b(t)-H^z_b\right) \alpha^z_b \,du \nonumber\\
184 &&+\rho^{zx}_{ab}\int_s^t \alpha^z_a \, \sigma^x_b \,du.
185 \f}
186
187 on the time interval from \f$ s= t_0\f$ to \f$ t=t_0+\Delta t\f$.
188
189*/
190Real ir_fx_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
191
192/*! FX-FX covariance
193
194 This function evaluates the covariance term
195
196 \f{eqnarray}{
197 \mathrm{Cov}[\Delta \ln x_a, \Delta \ln x_b] &=&
198 \int_s^t \left(H^z_0(t)-H^z_0\right)^2 (\alpha_0^z)^2\,du \nonumber\\
199 && -\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
200 \nonumber\\
201 &&- \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
202 \nonumber\\
203 &&+ \rho^{zx}_{0b}\int_s^t \left(H^z_0(t)-H^z_0\right)\alpha_0^z \sigma^x_b\,du \nonumber\\
204 &&+ \rho^{zx}_{0a}\int_s^t \left(H^z_0(t)-H^z_0\right)\alpha_0^z\,\sigma^x_a\,du \nonumber\\
205 &&- \rho^{zx}_{ab}\int_s^t \left(H^z_a(t)-H^z_a\right)\alpha_a^z \sigma^x_b,du\nonumber\\
206 &&- \rho^{zx}_{ba}\int_s^t \left(H^z_b(t)-H^z_b\right)\alpha_b^z\,\sigma^x_a\, du \nonumber\\
207 &&+ \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
208 \nonumber\\
209 &&+ \rho^{xx}_{ab}\int_s^t\sigma^x_a\,\sigma^x_b \,du
210 \f}
211
212 on the time interval from \f$ s= t_0\f$ to \f$ t=t_0+\Delta t\f$.
213
214 The implementation of this FX-FX covariance in this function further decomposes all terms
215 in order to separate simple and more complex integrations and to allow for tailored
216 efficient numerical integration schemes. Line by line, the covariance above can be written:
217
218 \f{eqnarray}{
219 \mathrm{Cov}[\Delta \ln x_a, \Delta \ln x_b]
220 &=&
221 (H^z_0)^2(t)\int_s^t (\alpha_0^z)^2\,du
222 - 2 \,H^z_0(t)\int_s^t H^z_0 (\alpha_0^z)^2\,du
223 + \int_s^t (H^z_0\,\alpha_0^z)^2\,du \\
224 &&
225 - \rho^{zz}_{0a} H^z_0(t) \,H^z_a(t)\int_s^t \alpha_0^z\,\alpha_a^z\,du
226 + \rho^{zz}_{0a} H^z_a(t) \int_s^t H^z_0\,\alpha_0^z\,\alpha_a^z\,du
227 + \rho^{zz}_{0a} H^z_0(t) \int_s^t H^z_a\,\alpha_0^z\,\alpha_a^z\,du
228 - \rho^{zz}_{0a}\int_s^t H^z_0\,H^z_a\,\alpha_0^z\,\alpha_a^z\,du \\
229 &&
230 - \rho^{zz}_{0b} H^z_0(t) \,H^z_b(t)\int_s^t \alpha_0^z\,\alpha_b^z\,du
231 + \rho^{zz}_{0b} H^z_b(t) \int_s^t H^z_0\,\alpha_0^z\,\alpha_b^z\,du
232 + \rho^{zz}_{0b} H^z_0(t) \int_s^t H^z_b\,\alpha_0^z\,\alpha_b^z\,du
233 - \rho^{zz}_{0b}\int_s^t H^z_0\,H^z_b\,\alpha_0^z\,\alpha_b^z\,du \\
234 &&
235 + \rho^{zx}_{0b} H^z_0(t) \int_s^t \alpha_0^z \,\sigma^x_b\,du
236 - \rho^{zx}_{0b} \int_s^t H^z_0 \,\alpha_0^z \,\sigma^x_b\,du \\
237 &&
238 + \rho^{zx}_{0a} H^z_0(t) \int_s^t \alpha_0^z \,\sigma^x_a\,du
239 - \rho^{zx}_{0a} \int_s^t H^z_0 \,\alpha_0^z \,\sigma^x_a\,du \\
240 &&
241 - \rho^{zx}_{ab} H^z_a(t) \int_s^t \alpha_a^z \sigma^x_b,du
242 + \rho^{zx}_{ab} \int_s^t H^z_a\,\alpha_a^z \sigma^x_b,du \\
243 &&
244 - \rho^{zx}_{ba} H^z_b(t) \int_s^t \alpha_b^z \sigma^x_a,du
245 + \rho^{zx}_{ba} \int_s^t H^z_b\,\alpha_b^z \sigma^x_a,du \\
246 &&
247 + \rho^{zz}_{ab} H^z_a(t) H^z_b(t) \int_s^t \alpha_a^z \alpha_b^z \,du
248 - \rho^{zz}_{ab} H^z_b(t) \int_s^t H^z_a \alpha_a^z \alpha_b^z \,du
249 - \rho^{zz}_{ab} H^z_a(t) \int_s^t H^z_b \alpha_a^z \alpha_b^z \,du
250 + \rho^{zz}_{ab} \int_s^t H^z_a H^z_b \alpha_a^z \alpha_b^z \,du \\
251 &&
252 + \rho^{xx}_{ab} \int_s^t\sigma^x_a\,\sigma^x_b \,du
253 \f}
254
255 When comparing with the code, also note that the integral on line one can be
256 simplified to
257 \f[
258 \int_s^t (\alpha_0^z)^2\,du = \zeta_0(t) - \zeta_0(s)
259 \f]
260
261*/
262Real fx_fx_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
263
264/*! infz-infz covariance */
265Real infz_infz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
266
267/*! infz-infy covariance */
268Real infz_infy_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
269
270/*! infy-infy covariance */
271Real infy_infy_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
272
273/*! ir-infz covariance */
274Real ir_infz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
275
276/*! ir-infy covariance */
277Real ir_infy_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
278
279/*! fx-infz covariance */
280Real fx_infz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
281
282/*! fx-infy covariance */
283Real fx_infy_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
284
285/*! crz-crz covariance */
286Real crz_crz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
287
288/*! crz-cry covariance */
289Real crz_cry_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
290
291/*! cry-cry covariance */
292Real cry_cry_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
293
294/*! ir-crz covariance */
295Real ir_crz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
296
297/*! ir-cry covariance */
298Real ir_cry_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
299
300/*! fx-crz covariance */
301Real fx_crz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
302
303/*! fx-cry covariance */
304Real fx_cry_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
305
306/*! infz-crz covariance */
307Real infz_crz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
308
309/*! infz-cry covariance */
310Real infz_cry_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
311
312/*! infy-crz covariance */
313Real infy_crz_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
314
315/*! infy-cry covariance */
316Real infy_cry_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
317
318/*! IR-EQ Covariance
319 \f{eqnarray}{
320 Cov \left[\Delta ln[s_i], \Delta z_j \right] &=&
321 \rho_{z_{\phi(i)},z_j} \int_{s}^{t} (H_{\phi(i)} (t) - H_{\phi(i)} (u)) \alpha_{\phi(i)} (u) \alpha_j (u) du\\
322 &&+ \rho_{s_i,z_j} \int_{s}^{t} \sigma_{s_i} (u) \alpha_j (u) du\\
323 \f}
324*/
325Real ir_eq_covariance(const CrossAssetModel& model, const Size irIdx, const Size eqIdx, const Time t0, const Time dt);
326
327/*! FX-EQ Covariance
328
329\f{eqnarray}{
330Cov \left[\Delta ln[s_i], \Delta ln[x_j] \right] &=&
331\rho_{z_{\phi(i)},z_0} \int_{s}^{t} (H_{\phi(i)} (t) - H_{\phi(i)} (u)) (H_0 (t) - H_0 (u)) \alpha_{\phi(i)}(u)
332\alpha_0(u) du\\
333&& - \rho_{z_{\phi(i)},z_j} \int_{s}^{t} (H_{\phi(i)} (t) - H_{\phi(i)} (u)) (H_j (t) - H_j (u)) \alpha_{\phi(i)}
334(u)\alpha_j(u) du\\
335&& + \rho_{z_{\phi(i)},x_j} \int_{s}^{t} (H_{\phi(i)} (t) - H_{\phi(i)} (u)) \alpha_{\phi(i)} (u) \sigma_{x_j}(u) du\\
336&&+ \rho_{s_i,z_0} \int_{s}^{t} (H_0 (t) - H_0 (u)) \alpha_0 (u) \sigma_{s_i}(u) du\\
337&&- \rho_{s_i,z_j} \int_{s}^{t} (H_j (t) - H_j (u)) \alpha_j (u) \sigma_{s_i}(u) du\\
338&&+ \rho_{s_i,x_j} \int_{s}^{t} \sigma_{s_i}(u) \sigma_{x_j}(u) du\\
339\f}
340*/
341Real fx_eq_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
342
343/*! infz-eq covariance */
344Real infz_eq_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
345
346/*! infy-eq covariance */
347Real infy_eq_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
348
349/*! crz-eq covariance */
350Real crz_eq_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
351
352/*! cry-eq covariance */
353Real cry_eq_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
354
355/*! EQ-EQ Covariance
356\f{eqnarray}{
357Cov \left[\Delta ln[s_i], \Delta ln[s_j] \right] &=&
358\rho_{z_{\phi(i)},z_{\phi(j)}} \int_{s}^{t} (H_{\phi(i)} (t) - H_{\phi(i)} (u)) (H_{\phi(j)} (t)\\
359&& - H_{\phi(j)} (u)) \alpha_{\phi(i)}(u) \alpha_{\phi(j)}(u) du\\
360&&+ \rho_{z_{\phi(i)},s_j} \int_{s}^{t} (H_{\phi(i)} (t) - H_{\phi(i)} (u)) \alpha_{\phi(i)}(u) \sigma_{s_j}(u) du\\
361&&+ \rho_{z_{\phi(j)},s_i} \int_{s}^{t} (H_{\phi(j)} (t) - H_{\phi(j)} (u)) \alpha_{\phi(j)}(u) \sigma_{s_i}(u) du\\
362&&+ \rho_{s_i,s_j} \int_{s}^{t} \sigma_{s_i}(u) \sigma_{s_j}(u) du\\
363\f}
364*/
365Real eq_eq_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
366
367/*! AUX-AUX Covariance
368
369 This function evaluates the covariance term for the domestic auxiliary state variable in the bank account measure
370
371 \f{eqnarray*}{
372 \mathrm{Cov}[\Delta y_0, \Delta y_0] &=& \int_s^t (\alpha^z_0)^2 \,(H^z_0)^2\,du
373 \f}
374
375 on the time interval from \f$ s= t_0\f$ to \f$ t=t_0+\Delta t\f$.
376*/
377Real aux_aux_covariance(const CrossAssetModel& model, const Time t0, const Time dt);
378
379/*! AUX-IR Covariance
380
381 This function evaluates the covariance term for the domestic auxiliary state variable in the bank account measure
382 with any other LGM state variable
383
384 \f{eqnarray*}{
385 \mathrm{Cov}[\Delta y_0, \Delta z_b] &=& \rho^{zz}_{0b} \int_s^t H^z_0\,\alpha^z_0\,\alpha^z_b\,du
386 \f}
387
388 on the time interval from \f$ s= t_0\f$ to \f$ t=t_0+\Delta t\f$.
389*/
390Real aux_ir_covariance(const CrossAssetModel& model, const Size j, const Time t0, const Time dt);
391
392/*! AUX-FX Covariance
393
394 This function evaluates the covariance term
395
396 \f{eqnarray}{
397 \mathrm{Cov} [\Delta y_0, \Delta \ln x_b]) &=& \int_s^t \left(H^z_0(t)-H^z_0\right)
398 (\alpha^z_0)^2\,H^z_0\,du \nonumber\\
399 &&- \rho^{zz}_{0b}\int_s^t \alpha^z_0\,H^z_0 \left(H^z_b(t)-H^z_b\right) \alpha^z_b \,du \nonumber\\
400 &&+\rho^{zx}_{0b}\int_s^t \alpha^z_0\,H^z_0 \, \sigma^x_b \,du.
401 \f}
402
403 on the time interval from \f$ s= t_0\f$ to \f$ t=t_0+\Delta t\f$.
404
405*/
406Real aux_fx_covariance(const CrossAssetModel& model, const Size j, const Time t0, const Time dt);
407
408/*! COM-COM state variable covariance, mean-reverting single-factor case
409\f{eqnarray}{
410Cov \left[\Delta Y_i, \Delta Y_j] \right] &=&
411 \rho_{Y_i,Y_j} \int_{s}^{t} \sigma_{Y_i}(u) \exp(\kappa_i u) \sigma_{Y_j}(u) \exp(\kappa_j u) du\\
412\f}
413*/
414Real com_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
415
416/*! TODO: COM covariance with all other risk factors */
417Real ir_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
418Real fx_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
419Real infz_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
420Real infy_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
421Real cry_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
422Real crz_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
423Real eq_com_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
424
425/*! IR_CrState Covariance */
426Real ir_crstate_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
427
428/*! FX_CrState Covariance */
429Real fx_crstate_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
430
431#/*! CrState_CrState Covariance */
432Real crstate_crstate_covariance(const CrossAssetModel& model, const Size i, const Size j, const Time t0, const Time dt);
433
434/*! IR H component */
435struct Hz {
436 Hz(const Size i) : i_(i) {}
437 Real eval(const CrossAssetModel& x, const Real t) const { return x.irlgm1f(i_)->H(t); }
438 const Size i_;
439};
440
441/*! IR alpha component */
442struct az {
443 az(const Size i) : i_(i) {}
444 Real eval(const CrossAssetModel& x, const Real t) const { return x.irlgm1f(i_)->alpha(t); }
445 const Size i_;
446};
447
448/*! IR zeta component */
449struct zetaz {
450 zetaz(const Size i) : i_(i) {}
451 Real eval(const CrossAssetModel& x, const Real t) const { return x.irlgm1f(i_)->zeta(t); }
452 const Size i_;
453};
454
455/*! FX sigma component */
456struct sx {
457 sx(const Size i) : i_(i) {}
458 Real eval(const CrossAssetModel& x, const Real t) const { return x.fxbs(i_)->sigma(t); }
459 const Size i_;
460};
461
462/*! FX variance component */
463struct vx {
464 vx(const Size i) : i_(i) {}
465 Real eval(const CrossAssetModel& x, const Real t) const { return x.fxbs(i_)->variance(t); }
466 const Size i_;
467};
468
469//! INF H component. May relate to real rate portion of JY model or z component of DK model.
470struct Hy {
471 Hy(QuantLib::Size i) : i_(i) {}
472
473 QuantLib::Real eval(const CrossAssetModel& x, const QuantLib::Real t) const {
475 return x.infdk(i_)->H(t);
477 return x.infjy(i_)->realRate()->H(t);
478 else
479 QL_FAIL("Expected inflation model to be JY or DK");
480 }
481
482 QuantLib::Size i_;
483};
484
485//! INF alpha component. May relate to real rate portion of JY model or z component of DK model.
486struct ay {
487 ay(QuantLib::Size i) : i_(i) {}
488
489 QuantLib::Real eval(const CrossAssetModel& x, const QuantLib::Real t) const {
491 return x.infdk(i_)->alpha(t);
493 return x.infjy(i_)->realRate()->alpha(t);
494 else
495 QL_FAIL("Expected inflation model to be JY or DK");
496 }
497
498 QuantLib::Size i_;
499};
500
501//! INF zeta component. May relate to real rate portion of JY model or z component of DK model.
502struct zetay {
503 zetay(const Size i) : i_(i) {}
504
505 Real eval(const CrossAssetModel& x, const Real t) const {
507 return x.infdk(i_)->zeta(t);
509 return x.infjy(i_)->realRate()->zeta(t);
510 else
511 QL_FAIL("Expected inflation model to be JY or DK");
512 }
513
514 const Size i_;
515};
516
517//! JY INF index sigma component
518struct sy {
519 sy(QuantLib::Size i) : i_(i) {}
520
521 QuantLib::Real eval(const CrossAssetModel& x, const QuantLib::Real t) const {
523 return x.infjy(i_)->index()->sigma(t);
524 else
525 QL_FAIL("Inflation index sigma only valid for JY model.");
526 }
527
528 QuantLib::Size i_;
529};
530
531//! JY INF index variance component
532struct vy {
533 vy(QuantLib::Size i) : i_(i) {}
534
535 QuantLib::Real eval(const CrossAssetModel& x, const QuantLib::Real t) const {
537 return x.infjy(i_)->index()->variance(t);
538 else
539 QL_FAIL("Inflation index variance only valid for JY model.");
540 }
541
542 QuantLib::Size i_;
543};
544
545/*! CR H component */
546struct Hl {
547 Hl(const Size i) : i_(i) {}
548 Real eval(const CrossAssetModel& x, const Real t) const { return x.crlgm1f(i_)->H(t); }
549 const Size i_;
550};
551
552/*! CR alpha component */
553struct al {
554 al(const Size i) : i_(i) {}
555 Real eval(const CrossAssetModel& x, const Real t) const { return x.crlgm1f(i_)->alpha(t); }
556 const Size i_;
557};
558
559/*! CR zeta component */
560struct zetal {
561 zetal(const Size i) : i_(i) {}
562 Real eval(const CrossAssetModel& x, const Real t) const { return x.crlgm1f(i_)->zeta(t); }
563 const Size i_;
564};
565
566/*! EQ sigma component */
567struct ss {
568 ss(const Size i) : i_(i) {}
569 Real eval(const CrossAssetModel& x, const Real t) const { return x.eqbs(i_)->sigma(t); }
570 const Size i_;
571};
572
573/*! EQ variance component */
574struct vs {
575 vs(const Size i) : i_(i) {}
576 Real eval(const CrossAssetModel& x, const Real t) const { return x.eqbs(i_)->variance(t); }
577 const Size i_;
578};
579
580/*! COM sigma component, non mean-reverting single-factor case */
581struct coms {
582 coms(const Size i) : i_(i) {}
583 Real eval(const CrossAssetModel& x, const Real t) const { return x.combs(i_)->sigma(t); }
584 const Size i_;
585};
586
587/*! IR-IR correlation component */
588struct rzz {
589 rzz(const Size i, const Size j) : i_(i), j_(j) {}
590 Real eval(const CrossAssetModel& x, const Real) const {
592 }
593 const Size i_, j_;
594};
595
596/*! IR-FX correlation component */
597struct rzx {
598 rzx(const Size i, const Size j) : i_(i), j_(j) {}
599 Real eval(const CrossAssetModel& x, const Real) const {
601 }
602 const Size i_, j_;
603};
604
605/*! FX-FX correlation component */
606struct rxx {
607 rxx(const Size i, const Size j) : i_(i), j_(j) {}
608 Real eval(const CrossAssetModel& x, const Real) const {
610 }
611 const Size i_, j_;
612};
613
614/*! INF-INF correlation component.
615
616 The possible inflation models are DK and JY. The i-th and j-th inflation models are not necessarily of the same
617 type. The offset is needed here in particular for the JY model where a value of 0 indicates the Brownian motion
618 associated with the real rate component and a value of 1 indicates the Brownian motion associated with the CPI
619 index component.
620*/
621struct ryy {
622 ryy(QuantLib::Size i, QuantLib::Size j, QuantLib::Size iOffset = 0, QuantLib::Size jOffset = 0)
623 : i_(i), j_(j), iOffset_(iOffset), jOffset_(jOffset) {}
624
625 QuantLib::Real eval(const CrossAssetModel& x, const QuantLib::Real) const {
627 jOffset_);
628 }
629
630 QuantLib::Size i_;
631 QuantLib::Size j_;
632 QuantLib::Size iOffset_;
633 QuantLib::Size jOffset_;
634};
635
636/*! IR-INF correlation component */
637struct rzy {
638 rzy(const Size i, const Size j, QuantLib::Size jOffset = 0) : i_(i), j_(j), jOffset_(jOffset) {}
639
640 Real eval(const CrossAssetModel& x, const Real) const {
642 }
643
644 const Size i_, j_;
645 QuantLib::Size jOffset_;
646};
647
648/*! FX-INF correlation component */
649struct rxy {
650 rxy(const Size i, const Size j, QuantLib::Size jOffset = 0) : i_(i), j_(j), jOffset_(jOffset) {}
651
652 Real eval(const CrossAssetModel& x, const Real) const {
654 }
655
656 const Size i_, j_;
657 QuantLib::Size jOffset_;
658};
659
660/*! CR-CR correlation component */
661struct rll {
662 rll(const Size i, const Size j) : i_(i), j_(j) {}
663 Real eval(const CrossAssetModel& x, const Real) const {
665 }
666 const Size i_, j_;
667};
668
669/*! IR-CR correlation component */
670struct rzl {
671 rzl(const Size i, const Size j) : i_(i), j_(j) {}
672 Real eval(const CrossAssetModel& x, const Real) const {
674 }
675 const Size i_, j_;
676};
677
678/*! FX-CR correlation component */
679struct rxl {
680 rxl(const Size i, const Size j) : i_(i), j_(j) {}
681 Real eval(const CrossAssetModel& x, const Real) const {
683 }
684 const Size i_, j_;
685};
686
687/*! INF-CR correlation component */
688struct ryl {
689 ryl(const Size i, const Size j, QuantLib::Size iOffset = 0) : i_(i), j_(j), iOffset_(iOffset) {}
690
691 Real eval(const CrossAssetModel& x, const Real) const {
693 }
694
695 const Size i_, j_;
696 QuantLib::Size iOffset_;
697};
698
699/*! EQ-EQ correlation component */
700struct rss {
701 rss(const Size i, const Size j) : i_(i), j_(j) {}
702 Real eval(const CrossAssetModel& x, const Real) const {
704 }
705 const Size i_, j_;
706};
707
708/*! IR-EQ correlation component */
709struct rzs {
710 rzs(const Size i, const Size j) : i_(i), j_(j) {}
711 Real eval(const CrossAssetModel& x, const Real) const {
713 }
714 const Size i_, j_;
715};
716
717/*! FX-EQ correlation component */
718struct rxs {
719 rxs(const Size i, const Size j) : i_(i), j_(j) {}
720 Real eval(const CrossAssetModel& x, const Real) const {
722 }
723 const Size i_, j_;
724};
725
726/*! INF-EQ correlation component */
727struct rys {
728 rys(const Size i, const Size j, QuantLib::Size iOffset = 0) : i_(i), j_(j), iOffset_(iOffset) {}
729
730 Real eval(const CrossAssetModel& x, const Real) const {
732 }
733
734 const Size i_, j_;
735 QuantLib::Size iOffset_;
736};
737
738/*! CR-EQ correlation component */
739struct rls {
740 rls(const Size i, const Size j) : i_(i), j_(j) {}
741 Real eval(const CrossAssetModel& x, const Real) const {
743 }
744 const Size i_, j_;
745};
746
747/*! COM-COM correlation component, single-factor case */
748struct rcc {
749 rcc(const Size i, const Size j) : i_(i), j_(j) {}
750 Real eval(const CrossAssetModel& x, const Real) const {
752 }
753 const Size i_, j_;
754};
755
756/*! H(t+T)-H(t) component (needed for analytical covariances of zero rates) */
757struct HTtz {
758 HTtz(const Size i, const Real T) : i_(i), T_(T) {}
759 Real eval(const CrossAssetModel& x, const Real t) const { return x.irlgm1f(i_)->H(T_ + t) - x.irlgm1f(i_)->H(t); }
760 const Size i_;
761 const Real T_;
762};
763
764/*! IR-CrState correlation component */
765struct rzcrs {
766 rzcrs(const Size i, const Size j) : i_(i), j_(j) {}
767 Real eval(const CrossAssetModel& x, const Real) const {
769 }
770 const Size i_, j_;
771};
772
773/*! FX-CrState correlation component */
774struct rxcrs {
775 rxcrs(const Size i, const Size j) : i_(i), j_(j) {}
776 Real eval(const CrossAssetModel& x, const Real) const {
778 }
779 const Size i_, j_;
780};
781
782/*! CrState-CrState correlation component */
783struct rccrs {
784 rccrs(const Size i, const Size j) : i_(i), j_(j) {}
785 Real eval(const CrossAssetModel& x, const Real) const {
787 }
788 const Size i_, j_;
789};
790/*! @} */
791
792} // namespace CrossAssetAnalytics
793
794} // namespace QuantExt
795
796#endif
const QuantLib::ext::shared_ptr< InfDkParametrization > infdk(const Size i) const
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.
const QuantLib::ext::shared_ptr< CrLgm1fParametrization > crlgm1f(const Size i) const
const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > combs(const Size ccy) const
ModelType modelType(const AssetType t, const Size i) const
const QuantLib::ext::shared_ptr< FxBsParametrization > fxbs(const Size ccy) const
const Matrix & correlation() const
basic functions for analytics in the cross asset model
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)
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 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)
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)
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 eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
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
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.
QuantLib::Real eval(const CrossAssetModel &x, const QuantLib::Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
rxy(const Size i, const Size j, QuantLib::Size jOffset=0)
Real eval(const CrossAssetModel &x, const Real) const
ryl(const Size i, const Size j, QuantLib::Size iOffset=0)
Real eval(const CrossAssetModel &x, const Real) const
rys(const Size i, const Size j, QuantLib::Size iOffset=0)
QuantLib::Real eval(const CrossAssetModel &x, const QuantLib::Real) const
ryy(QuantLib::Size i, QuantLib::Size j, QuantLib::Size iOffset=0, QuantLib::Size jOffset=0)
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real) const
rzy(const Size i, const Size j, QuantLib::Size jOffset=0)
Real eval(const CrossAssetModel &x, const Real) const
Real eval(const CrossAssetModel &x, const Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
JY INF index sigma component.
QuantLib::Real eval(const CrossAssetModel &x, const QuantLib::Real t) const
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
Real eval(const CrossAssetModel &x, const 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