Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
	- CSA Enforced Stream Path Exposures (1)
	- Client To Dealer Trade Payment (7, 8)
	- Float Coupon Stream Shell Skeleton (29, 30)
	- Float Coupon Stream VM Trade (31, 32)


Bug Fixes/Clean-up:

	- MPoR To Calibration To Timeline (41, 42)
	- Float Coupon Stream Fix #1 (49, 50)
	- Float Coupon Stream Fix #2 (51, 52)


Samples:

	- Fixed Coupon Classical Plus MPoR (2)
	- Classical+ Positive Exposure #1 (3, 4)
	- Classical+ Positive Exposure #2 (5, 6)
	- Classical+ Collateralized Exposure #1 (9, 10)
	- Classical+ Collateralized Exposure #2 (11, 12)
	- Classical+ Collateralized Positive Exposure #1 (13, 14)
	- Classical+ Collateralized Positive Exposure #2 (15, 16)
	- Variation Margin Gap #1 (17, 18)
	- Variation Margin Gap #2 (19, 20)
	- Classical+ Positive Exposure #3 (21)
	- Fixed Coupon Classical Minus MPoR (22, 23)
	- Long/Short Stream APS2017 MPoR (24)
	- Long Fixed Aggressive MPoR (25, 26)
	- Long Fixed Conservative MPoR (27, 28)
	- Short Fixed Classical+ MPoR (33, 34)
	- Short Fixed Classical- MPoR (35, 36)
	- Short Fixed Aggressive MPoR (37, 38)
	- Short Fixed Conservative MPoR (39, 40)
	- Long Float Classical Plus Time #1 (43, 44)
	- Long Float Classical Plus Time #2 (45, 46)
	- Long Float Classical Plus Time #3 (47, 48)
	- Long Float Classical Plus Time #4 (53, 54)
	- Long Float Classical Plus Time #5 (55, 56)
	- Long Float Classical Plus Time #6 (57, 58)
	- Long Float Classical Plus Time #7 (59, 60)
  • Loading branch information
lakshmiDRIP committed Apr 24, 2018
1 parent 3e3378f commit e9a9b46
Show file tree
Hide file tree
Showing 17 changed files with 5,211 additions and 64 deletions.
Binary file added Docs/External/XVA/Pykhtin_2009.pdf
Binary file not shown.
Binary file added Docs/External/XVA/Pykhtin_2010.pdf
Binary file not shown.
43 changes: 43 additions & 0 deletions ReleaseNotes/05_07_2018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Features:

- CSA Enforced Stream Path Exposures (1)
- Client To Dealer Trade Payment (7, 8)
- Float Coupon Stream Shell Skeleton (29, 30)
- Float Coupon Stream VM Trade (31, 32)


Bug Fixes/Clean-up:

- MPoR To Calibration To Timeline (41, 42)
- Float Coupon Stream Fix #1 (49, 50)
- Float Coupon Stream Fix #2 (51, 52)


Samples:

- Fixed Coupon Classical Plus MPoR (2)
- Classical+ Positive Exposure #1 (3, 4)
- Classical+ Positive Exposure #2 (5, 6)
- Classical+ Collateralized Exposure #1 (9, 10)
- Classical+ Collateralized Exposure #2 (11, 12)
- Classical+ Collateralized Positive Exposure #1 (13, 14)
- Classical+ Collateralized Positive Exposure #2 (15, 16)
- Variation Margin Gap #1 (17, 18)
- Variation Margin Gap #2 (19, 20)
- Classical+ Positive Exposure #3 (21)
- Fixed Coupon Classical Minus MPoR (22, 23)
- Long/Short Stream APS2017 MPoR (24)
- Long Fixed Aggressive MPoR (25, 26)
- Long Fixed Conservative MPoR (27, 28)
- Short Fixed Classical+ MPoR (33, 34)
- Short Fixed Classical- MPoR (35, 36)
- Short Fixed Aggressive MPoR (37, 38)
- Short Fixed Conservative MPoR (39, 40)
- Long Float Classical Plus Time #1 (43, 44)
- Long Float Classical Plus Time #2 (45, 46)
- Long Float Classical Plus Time #3 (47, 48)
- Long Float Classical Plus Time #4 (53, 54)
- Long Float Classical Plus Time #5 (55, 56)
- Long Float Classical Plus Time #6 (57, 58)
- Long Float Classical Plus Time #7 (59, 60)
7 changes: 6 additions & 1 deletion src/main/java/org/drip/exposure/mpor/FixedCouponStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class FixedCouponStream implements org.drip.exposure.mpor.MarginTradeVert
private org.drip.product.rates.Stream _stream = null;

/**
* FixedCoupon Constructor
* FixedCouponStream Constructor
*
* @param stream The Fixed Coupon Stream Instance
* @param notional The Fixed Coupon Stream Notional
Expand Down Expand Up @@ -104,6 +104,11 @@ public FixedCouponStream (
throw new java.lang.Exception ("FixedCouponStream::variationMarginEstimate => Invalid Inputs");
}

if (forwardDate <= _stream.effective().julian() || forwardDate >= _stream.maturity().julian())
{
return 0.;
}

double variationMarginEstimate = 0.;

double overnightReplicatorForward = marketPath.marketVertex (forwardDate).overnightReplicator();
Expand Down
190 changes: 190 additions & 0 deletions src/main/java/org/drip/exposure/mpor/FloatCouponStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@

package org.drip.exposure.mpor;

/*
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*/

/*!
* Copyright (C) 2018 Lakshmi Krishnamurthy
*
* This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
* libraries targeting analysts and developers
* https://lakshmidrip.github.io/DRIP/
*
* DRIP is composed of four main libraries:
*
* - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
* - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
* - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
* - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
*
* - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
* Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
* Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
* Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
* Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
*
* - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
* Incorporator, Holdings Constraint, and Transaction Costs.
*
* - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
*
* - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* FloatCouponStream estimates the Variation Margin and the Trade Payments for the given Float Coupon Stream
* off of the Realized Market Path. The References are:
*
* - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Re-thinking Margin Period of Risk,
* https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2902737, eSSRN.
*
* - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial Margin,
* https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156, eSSRN.
*
* - Albanese, C., and L. Andersen (2014): Accounting for OTC Derivatives: Funding Adjustments and the
* Re-Hypothecation Option, eSSRN, https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2482955.
*
* - Burgard, C., and M. Kjaer (2017): Derivatives Funding, Netting, and Accounting, eSSRN,
* https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2534011.
*
* - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
* 21 (2) 97-102.
*
* @author Lakshmi Krishnamurthy
*/

public class FloatCouponStream implements org.drip.exposure.mpor.MarginTradeVertex
{
private double _notional = java.lang.Double.NaN;
private org.drip.product.rates.Stream _stream = null;

/**
* FloatCouponStream Constructor
*
* @param stream The Fixed Coupon Stream Instance
* @param notional The Fixed Coupon Stream Notional
*
* @throws java.lang.Exception Thrown if the Inputs are Invalid
*/

public FloatCouponStream (
final org.drip.product.rates.Stream stream,
final double notional)
throws java.lang.Exception
{
if (null == (_stream = stream) ||
!org.drip.quant.common.NumberUtil.IsValid (_notional = notional))
{
throw new java.lang.Exception ("FloatCouponStream Constructor => Invalid Inputs");
}
}

@Override public double variationMarginEstimate (
final int forwardDate,
final org.drip.exposure.universe.MarketPath marketPath)
throws java.lang.Exception
{
if (null == marketPath)
{
throw new java.lang.Exception ("FloatCouponStream::variationMarginEstimate => Invalid Inputs");
}

if (forwardDate <= _stream.effective().julian() || forwardDate >= _stream.maturity().julian())
{
return 0.;
}

double variationMarginEstimate = 0.;

double overnightReplicatorForward = marketPath.marketVertex (forwardDate).overnightReplicator();

for (org.drip.analytics.cashflow.CompositePeriod period : _stream.periods())
{
int periodEndDate = period.endDate();

if (periodEndDate < forwardDate)
{
continue;
}

org.drip.analytics.cashflow.ComposableUnitFloatingPeriod composableUnitFloatingPeriod =
(org.drip.analytics.cashflow.ComposableUnitFloatingPeriod) period.periods().get (0);

variationMarginEstimate += period.couponDCF() *
period.notional (periodEndDate) *
marketPath.marketVertex
(composableUnitFloatingPeriod.referenceIndexPeriod().fixingDate()).positionManifestValue() *
period.couponFactor (periodEndDate) *
overnightReplicatorForward /
marketPath.marketVertex (period.payDate()).overnightReplicator();
}

return variationMarginEstimate * _notional;
}

@Override public org.drip.exposure.mpor.TradePayment tradePayment (
final int forwardDate,
final org.drip.exposure.universe.MarketPath marketPath)
{
if (null == marketPath)
{
return null;
}

if (forwardDate < _stream.effective().julian() || forwardDate > _stream.maturity().julian())
{
return org.drip.exposure.mpor.TradePayment.Standard (0.);
}

double overnightReplicatorForward = marketPath.marketVertex (forwardDate).overnightReplicator();

for (org.drip.analytics.cashflow.CompositePeriod period : _stream.periods())
{
int periodPayDate = period.payDate();

if (periodPayDate == forwardDate)
{
int periodEndDate = period.endDate();

org.drip.analytics.cashflow.ComposableUnitFloatingPeriod composableUnitFloatingPeriod =
(org.drip.analytics.cashflow.ComposableUnitFloatingPeriod) period.periods().get (0);

try
{
return org.drip.exposure.mpor.TradePayment.Standard (
_notional * period.couponDCF() *
period.notional (periodEndDate) *
marketPath.marketVertex
(composableUnitFloatingPeriod.referenceIndexPeriod().fixingDate()).positionManifestValue() *
period.couponFactor (periodEndDate) *
overnightReplicatorForward /
marketPath.marketVertex (period.payDate()).overnightReplicator()
);
}
catch (java.lang.Exception e)
{
e.printStackTrace();

return null;
}
}
}

return org.drip.exposure.mpor.TradePayment.Standard (0.);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@

public class MarginTradeVertexExposure
{
private double _netTradePaymentGap = java.lang.Double.NaN;
private double _clientTradePaymentGap = java.lang.Double.NaN;
private double _variationMarginPosting = java.lang.Double.NaN;
private double _variationMarginEstimate = java.lang.Double.NaN;
private double _clientDealerTradePaymentGap = java.lang.Double.NaN;
private org.drip.exposure.csatimeline.LastFlowDates _lastFlowDates = null;

/**
Expand All @@ -83,7 +83,7 @@ public class MarginTradeVertexExposure
* @param variationMarginPosting The Actual Variation Margin Posted from Collateral Rules and Operational
* Delays
* @param clientTradePaymentGap The Client Trade Payment Gap
* @param netTradePaymentGap The Net Trade Payment Gap
* @param clientDealerTradePaymentGap The Client-to-Dealer Net Trade Payment Gap
* @param lastFlowDates The Last Flow Dates
*
* @throws java.lang.Exception Thrown if the Inputs are Invalid
Expand All @@ -93,14 +93,15 @@ public MarginTradeVertexExposure (
final double variationMarginEstimate,
final double variationMarginPosting,
final double clientTradePaymentGap,
final double netTradePaymentGap,
final double clientDealerTradePaymentGap,
final org.drip.exposure.csatimeline.LastFlowDates lastFlowDates)
throws java.lang.Exception
{
if (!org.drip.quant.common.NumberUtil.IsValid (_variationMarginEstimate = variationMarginEstimate) ||
!org.drip.quant.common.NumberUtil.IsValid (_variationMarginPosting = variationMarginPosting) ||
!org.drip.quant.common.NumberUtil.IsValid (_clientTradePaymentGap = clientTradePaymentGap) ||
!org.drip.quant.common.NumberUtil.IsValid (_netTradePaymentGap = netTradePaymentGap) ||
!org.drip.quant.common.NumberUtil.IsValid (_clientDealerTradePaymentGap =
clientDealerTradePaymentGap) ||
null == (_lastFlowDates = lastFlowDates))
{
throw new java.lang.Exception ("MarginTradeVertexExposure Constructor => Invalid Inputs");
Expand Down Expand Up @@ -129,6 +130,17 @@ public double variationMarginPosting()
return _variationMarginPosting;
}

/**
* Retrieve the Variation Margin Gap
*
* @return The Variation Margin Gap
*/

public double variationMarginGap()
{
return _variationMarginEstimate - _variationMarginPosting;
}

/**
* Retrieve the Client Trade Payment Gap
*
Expand All @@ -141,14 +153,14 @@ public double clientTradePaymentGap()
}

/**
* Retrieve the Net Trade Payment Gap
* Retrieve the Client-to-Dealer Net Trade Payment Gap
*
* @return The Net Trade Payment Gap
* @return The Client-to-Dealer Net Trade Payment Gap
*/

public double netTradePaymentGap()
public double clientDealerTradePaymentGap()
{
return _netTradePaymentGap;
return _clientDealerTradePaymentGap;
}

/**
Expand All @@ -159,7 +171,32 @@ public double netTradePaymentGap()

public double tradePaymentGap()
{
return _clientTradePaymentGap + _netTradePaymentGap;
return _clientTradePaymentGap + _clientDealerTradePaymentGap;
}

/**
* Retrieve the Collateralized Exposure
*
* @return The Collateralized Exposure
*/

public double collateralizedExposure()
{
return _variationMarginEstimate + _clientTradePaymentGap + _clientDealerTradePaymentGap -
_variationMarginPosting;
}

/**
* Retrieve the Collateralized Positive Exposure
*
* @return The Collateralized Positive Exposure
*/

public double collateralizedPositiveExposure()
{
double collateralizedExposure = collateralizedExposure();

return collateralizedExposure > 0. ? collateralizedExposure : 0.;
}

/**
Expand Down

This file was deleted.

Loading

0 comments on commit e9a9b46

Please sign in to comment.