Skip to content

Commit d378c1f

Browse files
committed
Features:
- Position Group Collateralized Positive Exposure (1, 2) - Collateral Group Collateralized Positive Exposure (3, 4) - Position Group Collateralized Negative Exposure (5, 6) - Collateral Group Collateralized Negative Exposure (7, 8) - Position Group Path Exposure Trim (9) - Collateral Group Collateralized Positive Exposure (10) - Collateral Group Collateralized Negative Exposure (11) - Revamp of Uncollateralized Positive Exposure (12, 13) - Revamp of Uncollateralized Negative Exposure (14, 15) - Position Group Collateral Value Adjustment (16) - Collateral Group Collateral Value Adjustment (17, 18) Bug Fixes/Clean-up: Samples:
1 parent 7f69e5d commit d378c1f

File tree

3 files changed

+107
-193
lines changed

3 files changed

+107
-193
lines changed

ReleaseNotes/04_05_2018.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
Features:
3+
4+
- Position Group Collateralized Positive Exposure (1, 2)
5+
- Collateral Group Collateralized Positive Exposure (3, 4)
6+
- Position Group Collateralized Negative Exposure (5, 6)
7+
- Collateral Group Collateralized Negative Exposure (7, 8)
8+
- Position Group Path Exposure Trim (9)
9+
- Collateral Group Collateralized Positive Exposure (10)
10+
- Collateral Group Collateralized Negative Exposure (11)
11+
- Revamp of Uncollateralized Positive Exposure (12, 13)
12+
- Revamp of Uncollateralized Negative Exposure (14, 15)
13+
- Position Group Collateral Value Adjustment (16)
14+
- Collateral Group Collateral Value Adjustment (17, 18)
15+
16+
17+
Bug Fixes/Clean-up:
18+
19+
Samples:

src/main/java/org/drip/xva/netting/CollateralGroupPath.java

Lines changed: 56 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -214,30 +214,14 @@ public double[] collateralizedExposurePV()
214214

215215
public double[] collateralizedPositiveExposure()
216216
{
217-
int vertexCount = anchorDates().length;
218-
219-
int positionGroupCount = _positionGroupPathArray.length;
220-
double[] collateralizedPositiveExposure = new double[vertexCount];
217+
double[] collateralizedPositiveExposure = collateralizedExposure();
221218

222-
for (int j = 0; j < vertexCount; ++j)
223-
{
224-
collateralizedPositiveExposure[j] = 0.;
225-
}
219+
int vertexCount = collateralizedPositiveExposure.length;
226220

227-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
221+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
228222
{
229-
double[] positionGroupCollateralizedExposure =
230-
_positionGroupPathArray[positionGroupIndex].collateralizedExposure();
231-
232-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
233-
{
234-
double collateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
235-
236-
if (0. < collateralizedExposure)
237-
{
238-
collateralizedPositiveExposure[vertexIndex] += collateralizedExposure;
239-
}
240-
}
223+
if (0. > collateralizedPositiveExposure[vertexIndex])
224+
collateralizedPositiveExposure[vertexIndex] = 0.;
241225
}
242226

243227
return collateralizedPositiveExposure;
@@ -251,33 +235,14 @@ public double[] collateralizedPositiveExposure()
251235

252236
public double[] collateralizedPositiveExposurePV()
253237
{
254-
int vertexCount = anchorDates().length;
238+
double[] collateralizedPositiveExposurePV = collateralizedExposurePV();
255239

256-
int positionGroupCount = _positionGroupPathArray.length;
257-
double[] collateralizedPositiveExposurePV = new double[vertexCount];
240+
int vertexCount = collateralizedPositiveExposurePV.length;
258241

259-
for (int j = 0; j < vertexCount; ++j)
242+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
260243
{
261-
collateralizedPositiveExposurePV[j] = 0.;
262-
}
263-
264-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
265-
{
266-
double[] positionGroupCollateralizedExposure =
267-
_positionGroupPathArray[positionGroupIndex].collateralizedExposure();
268-
269-
org.drip.xva.universe.MarketVertex[] marketVertexArray = _marketPath.vertexes();
270-
271-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
272-
{
273-
double collateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
274-
275-
if (0. < collateralizedExposure)
276-
{
277-
collateralizedPositiveExposurePV[vertexIndex] += collateralizedExposure *
278-
marketVertexArray[vertexIndex].overnightReplicator();
279-
}
280-
}
244+
if (0. > collateralizedPositiveExposurePV[vertexIndex])
245+
collateralizedPositiveExposurePV[vertexIndex] = 0.;
281246
}
282247

283248
return collateralizedPositiveExposurePV;
@@ -291,30 +256,14 @@ public double[] collateralizedPositiveExposurePV()
291256

292257
public double[] collateralizedNegativeExposure()
293258
{
294-
int vertexCount = anchorDates().length;
259+
double[] collateralizedNegativeExposure = collateralizedExposure();
295260

296-
int positionGroupCount = _positionGroupPathArray.length;
297-
double[] collateralizedNegativeExposure = new double[vertexCount];
261+
int vertexCount = collateralizedNegativeExposure.length;
298262

299-
for (int j = 0; j < vertexCount; ++j)
263+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
300264
{
301-
collateralizedNegativeExposure[j] = 0.;
302-
}
303-
304-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
305-
{
306-
double[] positionGroupCollateralizedExposure =
307-
_positionGroupPathArray[positionGroupIndex].collateralizedExposure();
308-
309-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
310-
{
311-
double collateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
312-
313-
if (0. > collateralizedExposure)
314-
{
315-
collateralizedNegativeExposure[vertexIndex] += collateralizedExposure;
316-
}
317-
}
265+
if (0. < collateralizedNegativeExposure[vertexIndex])
266+
collateralizedNegativeExposure[vertexIndex] = 0.;
318267
}
319268

320269
return collateralizedNegativeExposure;
@@ -328,33 +277,14 @@ public double[] collateralizedNegativeExposure()
328277

329278
public double[] collateralizedNegativeExposurePV()
330279
{
331-
int vertexCount = anchorDates().length;
332-
333-
int positionGroupCount = _positionGroupPathArray.length;
334-
double[] collateralizedNegativeExposurePV = new double[vertexCount];
280+
double[] collateralizedNegativeExposurePV = collateralizedExposurePV();
335281

336-
for (int j = 0; j < vertexCount; ++j)
337-
{
338-
collateralizedNegativeExposurePV[j] = 0.;
339-
}
282+
int vertexCount = collateralizedNegativeExposurePV.length;
340283

341-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
284+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
342285
{
343-
double[] positionGroupCollateralizedExposure =
344-
_positionGroupPathArray[positionGroupIndex].collateralizedExposure();
345-
346-
org.drip.xva.universe.MarketVertex[] marketVertexArray = _marketPath.vertexes();
347-
348-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
349-
{
350-
double collateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
351-
352-
if (0. > collateralizedExposure)
353-
{
354-
collateralizedNegativeExposurePV[vertexIndex] += collateralizedExposure *
355-
marketVertexArray[vertexIndex].overnightReplicator();
356-
}
357-
}
286+
if (0. < collateralizedNegativeExposurePV[vertexIndex])
287+
collateralizedNegativeExposurePV[vertexIndex] = 0.;
358288
}
359289

360290
return collateralizedNegativeExposurePV;
@@ -433,29 +363,14 @@ public double[] uncollateralizedExposurePV()
433363

434364
public double[] uncollateralizedPositiveExposure()
435365
{
436-
int vertexCount = anchorDates().length;
437-
438-
int positionGroupCount = _positionGroupPathArray.length;
439-
double[] uncollateralizedPositiveExposure = new double[vertexCount];
366+
double[] uncollateralizedPositiveExposure = uncollateralizedExposure();
440367

441-
for (int j = 0; j < vertexCount; ++j)
442-
{
443-
uncollateralizedPositiveExposure[j] = 0.;
444-
}
368+
int vertexCount = uncollateralizedPositiveExposure.length;
445369

446-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
370+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
447371
{
448-
double[] positionGroupCollateralizedExposure =
449-
_positionGroupPathArray[positionGroupIndex].uncollateralizedExposure();
450-
451-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) {
452-
double uncollateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
453-
454-
if (0. < uncollateralizedExposure)
455-
{
456-
uncollateralizedPositiveExposure[vertexIndex] += uncollateralizedExposure;
457-
}
458-
}
372+
if (0. > uncollateralizedPositiveExposure[vertexIndex])
373+
uncollateralizedPositiveExposure[vertexIndex] = 0.;
459374
}
460375

461376
return uncollateralizedPositiveExposure;
@@ -469,33 +384,14 @@ public double[] uncollateralizedPositiveExposure()
469384

470385
public double[] uncollateralizedPositiveExposurePV()
471386
{
472-
int vertexCount = anchorDates().length;
387+
double[] uncollateralizedPositiveExposurePV = uncollateralizedExposurePV();
473388

474-
int positionGroupCount = _positionGroupPathArray.length;
475-
double[] uncollateralizedPositiveExposurePV = new double[vertexCount];
389+
int vertexCount = uncollateralizedPositiveExposurePV.length;
476390

477-
for (int j = 0; j < vertexCount; ++j)
391+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
478392
{
479-
uncollateralizedPositiveExposurePV[j] = 0.;
480-
}
481-
482-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
483-
{
484-
double[] positionGroupCollateralizedExposure =
485-
_positionGroupPathArray[positionGroupIndex].uncollateralizedExposure();
486-
487-
org.drip.xva.universe.MarketVertex[] marketVertexArray = _marketPath.vertexes();
488-
489-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
490-
{
491-
double uncollateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
492-
493-
if (0. < uncollateralizedExposure)
494-
{
495-
uncollateralizedPositiveExposurePV[vertexIndex] += uncollateralizedExposure *
496-
marketVertexArray[vertexIndex].overnightReplicator();
497-
}
498-
}
393+
if (0. > uncollateralizedPositiveExposurePV[vertexIndex])
394+
uncollateralizedPositiveExposurePV[vertexIndex] = 0.;
499395
}
500396

501397
return uncollateralizedPositiveExposurePV;
@@ -509,30 +405,14 @@ public double[] uncollateralizedPositiveExposurePV()
509405

510406
public double[] uncollateralizedNegativeExposure()
511407
{
512-
int vertexCount = anchorDates().length;
408+
double[] uncollateralizedNegativeExposure = uncollateralizedExposure();
513409

514-
int positionGroupCount = _positionGroupPathArray.length;
515-
double[] uncollateralizedNegativeExposure = new double[vertexCount];
410+
int vertexCount = uncollateralizedNegativeExposure.length;
516411

517-
for (int j = 0; j < vertexCount; ++j)
412+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
518413
{
519-
uncollateralizedNegativeExposure[j] = 0.;
520-
}
521-
522-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
523-
{
524-
double[] positionGroupUncollateralizedExposure =
525-
_positionGroupPathArray[positionGroupIndex].uncollateralizedExposure();
526-
527-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
528-
{
529-
double uncollateralizedExposure = positionGroupUncollateralizedExposure[vertexIndex];
530-
531-
if (0. > uncollateralizedExposure)
532-
{
533-
uncollateralizedNegativeExposure[vertexIndex] += uncollateralizedExposure;
534-
}
535-
}
414+
if (0. > uncollateralizedNegativeExposure[vertexIndex])
415+
uncollateralizedNegativeExposure[vertexIndex] = 0.;
536416
}
537417

538418
return uncollateralizedNegativeExposure;
@@ -546,33 +426,14 @@ public double[] uncollateralizedNegativeExposure()
546426

547427
public double[] uncollateralizedNegativeExposurePV()
548428
{
549-
int vertexCount = anchorDates().length;
429+
double[] uncollateralizedNegativeExposurePV = uncollateralizedExposurePV();
550430

551-
int positionGroupCount = _positionGroupPathArray.length;
552-
double[] uncollateralizedNegativeExposurePV = new double[vertexCount];
431+
int vertexCount = uncollateralizedNegativeExposurePV.length;
553432

554-
for (int j = 0; j < vertexCount; ++j)
433+
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
555434
{
556-
uncollateralizedNegativeExposurePV[j] = 0.;
557-
}
558-
559-
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
560-
{
561-
double[] positionGroupCollateralizedExposure =
562-
_positionGroupPathArray[positionGroupIndex].uncollateralizedExposure();
563-
564-
org.drip.xva.universe.MarketVertex[] marketVertexArray = _marketPath.vertexes();
565-
566-
for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
567-
{
568-
double uncollateralizedExposure = positionGroupCollateralizedExposure[vertexIndex];
569-
570-
if (0. > uncollateralizedExposure)
571-
{
572-
uncollateralizedNegativeExposurePV[vertexIndex] += uncollateralizedExposure *
573-
marketVertexArray[vertexIndex].overnightReplicator();
574-
}
575-
}
435+
if (0. > uncollateralizedNegativeExposurePV[vertexIndex])
436+
uncollateralizedNegativeExposurePV[vertexIndex] = 0.;
576437
}
577438

578439
return uncollateralizedNegativeExposurePV;
@@ -841,25 +702,27 @@ public double[] collateralBalancePV()
841702

842703
public double[] periodCollateralValueAdjustment()
843704
{
844-
org.drip.xva.universe.MarketVertex[] marketVertexArray = _marketPath.vertexes();
845-
846-
double[] collateralBalancePV = collateralBalancePV();
705+
int vertexCount = anchorDates().length;
847706

848-
int vertexCount = collateralBalancePV.length;
849-
double[] periodCollateralValueAdjustment = new double[vertexCount - 1];
707+
int periodCount = vertexCount - 1;
708+
int positionGroupCount = _positionGroupPathArray.length;
709+
double[] periodCollateralValueAdjustment = new double[periodCount];
850710

851-
for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
711+
for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
852712
{
853-
double periodIntegrandStart = collateralBalancePV[vertexIndex - 1] *
854-
marketVertexArray[vertexIndex - 1].csaSpread();
713+
periodCollateralValueAdjustment[periodIndex] = 0.;
714+
}
855715

856-
double periodIntegrandEnd = collateralBalancePV[vertexIndex] *
857-
marketVertexArray[vertexIndex].csaSpread();
716+
for (int positionGroupIndex = 0; positionGroupIndex < positionGroupCount; ++positionGroupIndex)
717+
{
718+
double[] positionPeriodCollateralValueAdjustment =
719+
_positionGroupPathArray[positionGroupIndex].periodCollateralValueAdjustment();
858720

859-
periodCollateralValueAdjustment[vertexIndex - 1] =
860-
-0.5 * (periodIntegrandStart + periodIntegrandEnd)
861-
* (marketVertexArray[vertexIndex].anchorDate().julian() -
862-
marketVertexArray[vertexIndex - 1].anchorDate().julian()) / 365.25;
721+
for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
722+
{
723+
periodCollateralValueAdjustment[periodIndex] +=
724+
positionPeriodCollateralValueAdjustment[periodIndex];
725+
}
863726
}
864727

865728
return periodCollateralValueAdjustment;

src/main/java/org/drip/xva/netting/PositionGroupPath.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,36 @@ public double[] collateralBalancePV()
403403

404404
return collateralizedBalancePV;
405405
}
406+
407+
/**
408+
* Compute Period-wise Path Collateral Value Adjustment
409+
*
410+
* @return The Period-wise Path Collateral Value Adjustment
411+
*/
412+
413+
public double[] periodCollateralValueAdjustment()
414+
{
415+
org.drip.xva.universe.MarketVertex[] marketVertexArray = _marketPath.vertexes();
416+
417+
double[] collateralBalancePV = collateralBalancePV();
418+
419+
int vertexCount = collateralBalancePV.length;
420+
double[] periodCollateralValueAdjustment = new double[vertexCount - 1];
421+
422+
for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
423+
{
424+
double periodIntegrandStart = collateralBalancePV[vertexIndex - 1] *
425+
marketVertexArray[vertexIndex - 1].csaSpread();
426+
427+
double periodIntegrandEnd = collateralBalancePV[vertexIndex] *
428+
marketVertexArray[vertexIndex].csaSpread();
429+
430+
periodCollateralValueAdjustment[vertexIndex - 1] =
431+
-0.5 * (periodIntegrandStart + periodIntegrandEnd)
432+
* (marketVertexArray[vertexIndex].anchorDate().julian() -
433+
marketVertexArray[vertexIndex - 1].anchorDate().julian()) / 365.25;
434+
}
435+
436+
return periodCollateralValueAdjustment;
437+
}
406438
}

0 commit comments

Comments
 (0)