@@ -103,12 +103,15 @@ public double unilateralCreditAdjustment()
103
103
104
104
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
105
105
{
106
- unilateralCreditAdjustment -=
107
- 0.5 * (creditExposure [vertexIndex - 1 ] + creditExposure [vertexIndex ]) *
108
- 0.5 * (marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () +
109
- marketVertexArray [vertexIndex ].client ().seniorRecoveryRate ()) *
110
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
111
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
106
+ double periodIntegrandStart = creditExposure [vertexIndex - 1 ] *
107
+ marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () *
108
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
109
+
110
+ double periodIntegrandEnd = creditExposure [vertexIndex ] *
111
+ marketVertexArray [vertexIndex ].client ().seniorRecoveryRate () *
112
+ marketVertexArray [vertexIndex ].overnightReplicator ();
113
+
114
+ unilateralCreditAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
112
115
(marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () -
113
116
marketVertexArray [vertexIndex ].client ().survivalProbability ());
114
117
}
@@ -136,14 +139,17 @@ public double bilateralCreditAdjustment()
136
139
137
140
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
138
141
{
139
- bilateralCreditAdjustment -=
140
- 0.5 * (creditExposure [vertexIndex - 1 ] + creditExposure [vertexIndex ]) *
141
- 0.5 * (marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () +
142
- marketVertexArray [vertexIndex ].client ().seniorRecoveryRate ()) *
143
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
144
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
145
- 0.5 * (marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () +
146
- marketVertexArray [vertexIndex ].dealer ().survivalProbability ()) *
142
+ double periodIntegrandStart = creditExposure [vertexIndex - 1 ] *
143
+ marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () *
144
+ marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () *
145
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
146
+
147
+ double periodIntegrandEnd = creditExposure [vertexIndex ] *
148
+ marketVertexArray [vertexIndex ].client ().seniorRecoveryRate () *
149
+ marketVertexArray [vertexIndex ].dealer ().survivalProbability () *
150
+ marketVertexArray [vertexIndex ].overnightReplicator ();
151
+
152
+ bilateralCreditAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
147
153
(marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () -
148
154
marketVertexArray [vertexIndex ].client ().survivalProbability ());
149
155
}
@@ -182,12 +188,15 @@ public double unilateralDebtAdjustment()
182
188
183
189
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
184
190
{
185
- unilateralDebtAdjustment -=
186
- 0.5 * (debtExposure [vertexIndex - 1 ] + debtExposure [vertexIndex ]) *
187
- 0.5 * (marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () +
188
- marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate ()) *
189
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
190
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
191
+ double periodIntegrandStart = debtExposure [vertexIndex - 1 ] *
192
+ marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () *
193
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
194
+
195
+ double periodIntegrandEnd = debtExposure [vertexIndex ] *
196
+ marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate () *
197
+ marketVertexArray [vertexIndex ].overnightReplicator ();
198
+
199
+ unilateralDebtAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
191
200
(marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () -
192
201
marketVertexArray [vertexIndex ].dealer ().survivalProbability ());
193
202
}
@@ -215,14 +224,17 @@ public double bilateralDebtAdjustment()
215
224
216
225
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
217
226
{
218
- bilateralDebtAdjustment -=
219
- 0.5 * (debtExposure [vertexIndex - 1 ] + debtExposure [vertexIndex ]) *
220
- 0.5 * (marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () +
221
- marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate ()) *
222
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
223
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
224
- 0.5 * (marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () +
225
- marketVertexArray [vertexIndex ].client ().survivalProbability ()) *
227
+ double periodIntegrandStart = debtExposure [vertexIndex - 1 ] *
228
+ marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () *
229
+ marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () *
230
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
231
+
232
+ double periodIntegrandEnd = debtExposure [vertexIndex ] *
233
+ marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate () *
234
+ marketVertexArray [vertexIndex ].client ().survivalProbability () *
235
+ marketVertexArray [vertexIndex ].overnightReplicator ();
236
+
237
+ bilateralDebtAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
226
238
(marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () -
227
239
marketVertexArray [vertexIndex ].dealer ().survivalProbability ());
228
240
}
@@ -243,28 +255,19 @@ public double bilateralCollateralAdjustment()
243
255
{
244
256
org .drip .xva .universe .MarketVertex [] marketVertexArray = marketPath ().vertexes ();
245
257
246
- double [] collateralBalance = collateralBalance ();
258
+ double [] periodCollateralValueAdjustment = periodCollateralValueAdjustment ();
247
259
248
260
double bilateralCollateralValueAdjustment = 0. ;
249
- int vertexCount = collateralBalance .length ;
261
+ int vertexCount = periodCollateralValueAdjustment .length ;
250
262
251
- for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
263
+ for (int vertexIndex = 0 ; vertexIndex < vertexCount ; ++vertexIndex )
252
264
{
253
- double periodIntegrandStart = collateralBalance [vertexIndex - 1 ] *
254
- marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () *
255
- marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () *
256
- marketVertexArray [vertexIndex - 1 ].csaSpread () *
257
- marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
258
-
259
- double periodIntegrandEnd = collateralBalance [vertexIndex ] *
265
+ bilateralCollateralValueAdjustment += 0.5 * periodCollateralValueAdjustment [vertexIndex ] * (
260
266
marketVertexArray [vertexIndex ].dealer ().survivalProbability () *
261
- marketVertexArray [vertexIndex ].client ().survivalProbability () *
262
- marketVertexArray [vertexIndex ].csaSpread () *
263
- marketVertexArray [vertexIndex ].overnightReplicator ();
264
-
265
- bilateralCollateralValueAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
266
- (marketVertexArray [vertexIndex ].anchorDate ().julian () -
267
- marketVertexArray [vertexIndex - 1 ].anchorDate ().julian ()) / 365.25 ;
267
+ marketVertexArray [vertexIndex ].client ().survivalProbability () +
268
+ marketVertexArray [vertexIndex + 1 ].dealer ().survivalProbability () *
269
+ marketVertexArray [vertexIndex + 1 ].client ().survivalProbability ()
270
+ );
268
271
}
269
272
270
273
return bilateralCollateralValueAdjustment ;
@@ -278,7 +281,7 @@ public double bilateralCollateralAdjustment()
278
281
* @throws java.lang.Exception Thrown if the Inputs are Invalid
279
282
*/
280
283
281
- public double collateralAdjustment ()
284
+ public double collateralValueAdjustment ()
282
285
throws java .lang .Exception
283
286
{
284
287
return bilateralCollateralAdjustment ();
@@ -297,19 +300,22 @@ public double[] periodUnilateralCreditAdjustment()
297
300
double [] creditExposure = creditExposure ();
298
301
299
302
int vertexCount = creditExposure .length ;
300
- double [] periodUnilateralCreditAdjustment = new double [vertexCount ];
301
- periodUnilateralCreditAdjustment [0 ] = 0. ;
303
+ double [] periodUnilateralCreditAdjustment = new double [vertexCount - 1 ];
302
304
303
305
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
304
306
{
305
- periodUnilateralCreditAdjustment [vertexIndex ] =
306
- -0.5 * (creditExposure [vertexIndex - 1 ] + creditExposure [vertexIndex ]) *
307
- 0.5 * (marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () +
308
- marketVertexArray [vertexIndex ].client ().seniorRecoveryRate ()) *
309
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
310
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
307
+ double periodIntegrandStart = creditExposure [vertexIndex - 1 ] *
308
+ marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () *
309
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
310
+
311
+ double periodIntegrandEnd = creditExposure [vertexIndex ] *
312
+ marketVertexArray [vertexIndex ].client ().seniorRecoveryRate () *
313
+ marketVertexArray [vertexIndex ].overnightReplicator ();
314
+
315
+ periodUnilateralCreditAdjustment [vertexIndex - 1 ] =
316
+ -0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
311
317
(marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () -
312
- marketVertexArray [vertexIndex ].client ().survivalProbability ());
318
+ marketVertexArray [vertexIndex ].client ().survivalProbability ());
313
319
}
314
320
315
321
return periodUnilateralCreditAdjustment ;
@@ -328,21 +334,24 @@ public double[] periodBilateralCreditAdjustment()
328
334
double [] creditExposure = creditExposure ();
329
335
330
336
int vertexCount = creditExposure .length ;
331
- double [] periodBilateralCreditAdjustment = new double [vertexCount ];
332
- periodBilateralCreditAdjustment [0 ] = 0. ;
337
+ double [] periodBilateralCreditAdjustment = new double [vertexCount - 1 ];
333
338
334
339
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
335
340
{
336
- periodBilateralCreditAdjustment [vertexIndex ] =
337
- -0.5 * (creditExposure [vertexIndex - 1 ] + creditExposure [vertexIndex ]) *
338
- 0.5 * (marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () +
339
- marketVertexArray [vertexIndex ].client ().seniorRecoveryRate ()) *
340
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
341
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
342
- 0.5 * (marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () +
343
- marketVertexArray [vertexIndex ].dealer ().survivalProbability ()) *
341
+ double periodIntegrandStart = creditExposure [vertexIndex - 1 ] *
342
+ marketVertexArray [vertexIndex - 1 ].client ().seniorRecoveryRate () *
343
+ marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () *
344
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
345
+
346
+ double periodIntegrandEnd = creditExposure [vertexIndex ] *
347
+ marketVertexArray [vertexIndex ].client ().seniorRecoveryRate () *
348
+ marketVertexArray [vertexIndex ].dealer ().survivalProbability () *
349
+ marketVertexArray [vertexIndex ].overnightReplicator ();
350
+
351
+ periodBilateralCreditAdjustment [vertexIndex - 1 ] =
352
+ -0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
344
353
(marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () -
345
- marketVertexArray [vertexIndex ].client ().survivalProbability ());
354
+ marketVertexArray [vertexIndex ].client ().survivalProbability ());
346
355
}
347
356
348
357
return periodBilateralCreditAdjustment ;
@@ -366,7 +375,8 @@ public double[] periodContraLiabilityCreditAdjustment()
366
375
for (int vertexIndex = 0 ; vertexIndex < vertexCount ; ++vertexIndex )
367
376
{
368
377
periodContraLiabilityCreditAdjustment [vertexIndex ] =
369
- periodUnilateralCreditAdjustment [vertexIndex ] - periodBilateralCreditAdjustment [vertexIndex ];
378
+ periodUnilateralCreditAdjustment [vertexIndex ] -
379
+ periodBilateralCreditAdjustment [vertexIndex ];
370
380
}
371
381
372
382
return periodContraLiabilityCreditAdjustment ;
@@ -385,19 +395,22 @@ public double[] periodUnilateralDebtAdjustment()
385
395
double [] debtExposure = debtExposure ();
386
396
387
397
int vertexCount = debtExposure .length ;
388
- double [] periodUnilateralDebtAdjustment = new double [vertexCount ];
389
- periodUnilateralDebtAdjustment [0 ] = 0. ;
398
+ double [] periodUnilateralDebtAdjustment = new double [vertexCount - 1 ];
390
399
391
400
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
392
401
{
393
- periodUnilateralDebtAdjustment [vertexCount ] =
394
- -0.5 * (debtExposure [vertexIndex - 1 ] + debtExposure [vertexIndex ]) *
395
- 0.5 * (marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () +
396
- marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate ()) *
397
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
398
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
402
+ double periodIntegrandStart = debtExposure [vertexIndex - 1 ] *
403
+ marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () *
404
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
405
+
406
+ double periodIntegrandEnd = debtExposure [vertexIndex ] *
407
+ marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate () *
408
+ marketVertexArray [vertexIndex ].overnightReplicator ();
409
+
410
+ periodUnilateralDebtAdjustment [vertexIndex - 1 ] =
411
+ -0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
399
412
(marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () -
400
- marketVertexArray [vertexIndex ].dealer ().survivalProbability ());
413
+ marketVertexArray [vertexIndex ].dealer ().survivalProbability ());
401
414
}
402
415
403
416
return periodUnilateralDebtAdjustment ;
@@ -416,21 +429,24 @@ public double[] periodBilateralDebtAdjustment()
416
429
double [] debtExposure = debtExposure ();
417
430
418
431
int vertexCount = debtExposure .length ;
419
- double [] periodBilateralDebtAdjustment = new double [vertexCount ];
420
- periodBilateralDebtAdjustment [0 ] = 0. ;
432
+ double [] periodBilateralDebtAdjustment = new double [vertexCount - 1 ];
421
433
422
434
for (int vertexIndex = 1 ; vertexIndex < vertexCount ; ++vertexIndex )
423
435
{
424
- periodBilateralDebtAdjustment [vertexIndex ] =
425
- -0.5 * (debtExposure [vertexIndex - 1 ] + debtExposure [vertexIndex ]) *
426
- 0.5 * (marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () +
427
- marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate ()) *
428
- 0.5 * (marketVertexArray [vertexIndex - 1 ].overnightReplicator () +
429
- marketVertexArray [vertexIndex ].overnightReplicator ()) *
430
- 0.5 * (marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () +
431
- marketVertexArray [vertexIndex ].client ().survivalProbability ()) *
436
+ double periodIntegrandStart = debtExposure [vertexIndex - 1 ] *
437
+ marketVertexArray [vertexIndex - 1 ].dealer ().seniorRecoveryRate () *
438
+ marketVertexArray [vertexIndex - 1 ].client ().survivalProbability () *
439
+ marketVertexArray [vertexIndex - 1 ].overnightReplicator ();
440
+
441
+ double periodIntegrandEnd = debtExposure [vertexIndex ] *
442
+ marketVertexArray [vertexIndex ].dealer ().seniorRecoveryRate () *
443
+ marketVertexArray [vertexIndex ].client ().survivalProbability () *
444
+ marketVertexArray [vertexIndex ].overnightReplicator ();
445
+
446
+ periodBilateralDebtAdjustment [vertexIndex - 1 ] =
447
+ -0.5 * (periodIntegrandStart + periodIntegrandEnd ) *
432
448
(marketVertexArray [vertexIndex - 1 ].dealer ().survivalProbability () -
433
- marketVertexArray [vertexIndex ].dealer ().survivalProbability ());
449
+ marketVertexArray [vertexIndex ].dealer ().survivalProbability ());
434
450
}
435
451
436
452
return periodBilateralDebtAdjustment ;
0 commit comments