131 {
132 Array res(
model_->dimension(), 0.0);
135 Real H0 =
model_->irlgm1f(0)->H(t);
136 Real Hprime0 =
model_->irlgm1f(0)->Hprime(t);
137 Real alpha0 =
model_->irlgm1f(0)->alpha(t);
138 Real zeta0 =
model_->irlgm1f(0)->zeta(t);
140
141 for (Size i = 0; i < n; ++i) {
142 Real Hi =
model_->irlgm1f(i)->H(t);
143 Real alphai =
model_->irlgm1f(i)->alpha(t);
145
147
149 }
150 if (i > 0) {
151 Real sigmai =
model_->fxbs(i - 1)->sigma(t);
152
153 Real rhozz0i =
155
156 Real rhozx0i =
158 Real rhozxii =
160
162 -Hi * alphai * alphai + H0 * alpha0 * alphai * rhozz0i - sigmai * alphai * rhozxii;
163
165 H0 * alpha0 * sigmai * rhozx0i +
166 model_->irlgm1f(0)->termStructure()->forwardRate(t, t, Continuous) -
167 model_->irlgm1f(i)->termStructure()->forwardRate(t, t, Continuous) - 0.5 * sigmai * sigmai;
169
172 }
173 }
174 }
175
176 for (Size k = 0; k < n_eq; ++k) {
178
179 Real eps_ccy = (i == 0) ? 0.0 : 1.0;
180
181
182
183 Real sigmask =
model_->eqbs(k)->sigma(t);
184
185 Real sigmaxi = (i == 0) ? 0.0 :
model_->fxbs(i - 1)->sigma(t);
186
187
188 Real rhozs0k =
190
191 Real rhoxsik =
192 (i == 0) ? 0.0 :
194
195 Real fr_i =
model_->eqbs(k)->equityIrCurveToday()->forwardRate(t, t, Continuous);
196
197 Real fq_k =
model_->eqbs(k)->equityDivYieldCurveToday()->forwardRate(t, t, Continuous);
199 (eps_ccy * rhoxsik * sigmaxi * sigmask) -
200 (0.5 * sigmask * sigmask);
201 }
202
203
205
207
208 auto p =
model_->infjy(j);
209 Size i_j =
model_->ccyIndex(p->currency());
210
211
212 Real H_y_j = p->realRate()->H(t);
213 Real Hp_y_j = p->realRate()->Hprime(t);
214 Real zeta_y_j = p->realRate()->zeta(t);
215 Real alpha_y_j = p->realRate()->alpha(t);
216 Real sigma_c_j = p->index()->sigma(t);
217
218
219 Real H_i_j =
model_->irlgm1f(i_j)->H(t);
220 Real Hp_i_j =
model_->irlgm1f(i_j)->Hprime(t);
221 Real zeta_i_j =
model_->irlgm1f(i_j)->zeta(t);
222
223
224 Real rho_zy_0j =
226 Real rho_yc_ij =
228 Real rho_zc_0j =
230
231
232 auto rrDrift = -alpha_y_j * alpha_y_j * H_y_j + rho_zy_0j * alpha0 * alpha_y_j * H_y_j -
233 rho_yc_ij * alpha_y_j * sigma_c_j;
234
235 if (i_j > 0) {
236 Real sigma_x_i_j =
model_->fxbs(i_j - 1)->sigma(t);
239 rrDrift -= rho_yx_j_i_j * alpha_y_j * sigma_x_i_j;
240 }
241
243
244
245 auto indexDrift = rho_zc_0j * alpha0 * sigma_c_j * H0 - 0.5 * sigma_c_j * sigma_c_j +
246 zeta_i_j * Hp_i_j * H_i_j - zeta_y_j * Hp_y_j * H_y_j;
247
248
249
250 auto ts = p->realRate()->termStructure();
251 Time dt = 0.0001;
252 Time t1 = std::max(t - dt / 2.0, 0.0);
253 Time t2 = t1 + dt;
254 auto z_t = ts->zeroRate(t);
255 auto z_t1 = ts->zeroRate(t1);
256 auto z_t2 = ts->zeroRate(t2);
257 indexDrift += std::log(1 + z_t) + (t / (1 + z_t)) * ((z_t2 - z_t1) / dt);
258
259 if (i_j > 0) {
260 Real sigma_x_i_j =
model_->fxbs(i_j - 1)->sigma(t);
263 indexDrift -= rho_cx_j_i_j * sigma_c_j * sigma_x_i_j;
264 }
265
267 }
268 }
269
274 }
275 } else {
279 }
280
281 for (Size i = 1; i < n; ++i) {
282
283 Real Hi =
model_->irlgm1f(i)->H(t);
284 Real Hprimei =
model_->irlgm1f(i)->Hprime(t);
285 Real zetai =
model_->irlgm1f(i)->zeta(t);
289 }
290 for (Size k = 0; k < n_eq; ++k) {
291
292
294
295 Real Hi =
model_->irlgm1f(i)->H(t);
296 Real Hprimei =
model_->irlgm1f(i)->Hprime(t);
297 Real zetai =
model_->irlgm1f(i)->zeta(t);
300 }
301
302
305
306 auto p =
model_->infjy(j);
307 Size i_j =
model_->ccyIndex(p->currency());
308
309
310 Real Hp_y_j = p->realRate()->Hprime(t);
311
312
313 Real Hp_i_j =
model_->irlgm1f(i_j)->Hprime(t);
314
318 }
319 }
320
321
323 for (Size k = 0; k < n_com; ++k) {
324 auto cm = QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzModel>(
model_->comModel(k));
325 QL_REQUIRE(cm, "CommoditySchwartzModel not set");
326 if (!cm->parametrization()->driftFreeState()) {
327
328 Real kap = cm->parametrization()->kappaParameter();
331 } else {
332
333 }
334 }
335
336
337 return res;
338}
std::vector< Array > cache_m_