EventSequence.java

  1. package org.drip.exposure.csatimeline;

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

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  *
  10.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  11.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  12.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  13.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  14.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  15.  *      and computational support.
  16.  *  
  17.  *      https://lakshmidrip.github.io/DROP/
  18.  *  
  19.  *  DROP is composed of three modules:
  20.  *  
  21.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  22.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  23.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  24.  *
  25.  *  DROP Product Core implements libraries for the following:
  26.  *  - Fixed Income Analytics
  27.  *  - Loan Analytics
  28.  *  - Transaction Cost Analytics
  29.  *
  30.  *  DROP Portfolio Core implements libraries for the following:
  31.  *  - Asset Allocation Analytics
  32.  *  - Asset Liability Management Analytics
  33.  *  - Capital Estimation Analytics
  34.  *  - Exposure Analytics
  35.  *  - Margin Analytics
  36.  *  - XVA Analytics
  37.  *
  38.  *  DROP Computational Core implements libraries for the following:
  39.  *  - Algorithm Support
  40.  *  - Computation Support
  41.  *  - Function Analysis
  42.  *  - Model Validation
  43.  *  - Numerical Analysis
  44.  *  - Numerical Optimizer
  45.  *  - Spline Builder
  46.  *  - Statistical Learning
  47.  *
  48.  *  Documentation for DROP is Spread Over:
  49.  *
  50.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  51.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  52.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  53.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  54.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  55.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  56.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  57.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  58.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  59.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  60.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  61.  *
  62.  *  Licensed under the Apache License, Version 2.0 (the "License");
  63.  *      you may not use this file except in compliance with the License.
  64.  *  
  65.  *  You may obtain a copy of the License at
  66.  *      http://www.apache.org/licenses/LICENSE-2.0
  67.  *  
  68.  *  Unless required by applicable law or agreed to in writing, software
  69.  *      distributed under the License is distributed on an "AS IS" BASIS,
  70.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  71.  *  
  72.  *  See the License for the specific language governing permissions and
  73.  *      limitations under the License.
  74.  */

  75. /**
  76.  * <i>EventSequence</i> holds the BCBS/IOSCO prescribed Events Time-line occurring Margin Period. The
  77.  * References are:
  78.  *  
  79.  * <br><br>
  80.  *      <ul>
  81.  *          <li>
  82.  *              Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Re-thinking Margin Period of Risk
  83.  *                  https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2902737 <b>eSSRN</b>
  84.  *          </li>
  85.  *          <li>
  86.  *              Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of
  87.  *                  Initial Margin https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156 <b>eSSRN</b>
  88.  *          </li>
  89.  *          <li>
  90.  *              Anfuso, F., D. Aziz, P. Giltinan, and K Loukopoulus (2017): A Sound Modeling and Back-testing
  91.  *                  Framework for Forecasting Initial Margin Requirements
  92.  *                  https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2716279 <b>eSSRN</b>
  93.  *          </li>
  94.  *          <li>
  95.  *              BCBS (2015): Margin Requirements for Non-centrally Cleared Derivatives
  96.  *                  https://www.bis.org/bcbs/publ/d317.pdf
  97.  *          </li>
  98.  *          <li>
  99.  *              Pykhtin, M. (2009): Modeling Credit Exposure for Collateralized Counter-parties <i>Journal of
  100.  *                  Credit Risk</i> <b>5 (4)</b> 3-27
  101.  *          </li>
  102.  *      </ul>
  103.  *
  104.  *  <br><br>
  105.  *  <ul>
  106.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  107.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ExposureAnalyticsLibrary.md">Exposure Analytics</a></li>
  108.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/exposure/README.md">Exposure Group Level Collateralized/Uncollateralized Exposure</a></li>
  109.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/exposure/csatimeline/README.md">Time-line of IMA/CSA Event Dates</a></li>
  110.  *  </ul>
  111.  *
  112.  * @author Lakshmi Krishnamurthy
  113.  */

  114. public class EventSequence
  115. {
  116.     private int _curePeriod = -1;
  117.     private int _marginFrequency = -1;
  118.     private java.lang.String _calendarSet = "";
  119.     private org.drip.exposure.csatimeline.EventDate _ed = null;
  120.     private org.drip.exposure.csatimeline.EventDate _etd = null;
  121.     private org.drip.exposure.csatimeline.EventDate _ped = null;
  122.     private org.drip.exposure.csatimeline.EventDate _honored = null;
  123.     private org.drip.exposure.csatimeline.EventDate _valuation = null;
  124.     private org.drip.exposure.csatimeline.EventDate _nonHonored = null;
  125.     private org.drip.exposure.csatimeline.EventDate _etdDesignation = null;
  126.     private org.drip.exposure.csatimeline.EventDate _edCommunication = null;
  127.     private org.drip.exposure.csatimeline.EventDate _pedCommunication = null;
  128.     private org.drip.exposure.csatimeline.EventDate _collateralTransferInitiation = null;

  129.     /**
  130.      * Construct an Instance of Aggressive EventSequence
  131.      *
  132.      * @param valuationDate The Valuation Date
  133.      * @param calendarSet The Calendar Set
  134.      *
  135.      * @return Instance of Aggressive EventSequence
  136.      */

  137.     public static final EventSequence Aggressive (
  138.         final org.drip.analytics.date.JulianDate valuationDate,
  139.         final java.lang.String calendarSet)
  140.     {
  141.         if (null == valuationDate)
  142.         {
  143.             return null;
  144.         }

  145.         org.drip.exposure.csatimeline.EventDate valuation =
  146.             org.drip.exposure.csatimeline.EventDateBuilder.Valuation (valuationDate);

  147.         if (null == valuation)
  148.         {
  149.             return null;
  150.         }

  151.         org.drip.exposure.csatimeline.EventDate honored =
  152.             org.drip.exposure.csatimeline.EventDateBuilder.Honored (
  153.                 valuation,
  154.                 calendarSet
  155.             );

  156.         if (null == honored)
  157.         {
  158.             return null;
  159.         }

  160.         org.drip.exposure.csatimeline.EventDate nonHonored =
  161.             org.drip.exposure.csatimeline.EventDateBuilder.NonHonored (
  162.                 org.drip.exposure.csatimeline.EventDateBuilder.Valuation (
  163.                     valuation.date().addBusDays (
  164.                         org.drip.exposure.csatimeline.EventDateBuilder.MARGIN_FREQUENCY_DAILY,
  165.                         calendarSet
  166.                     )
  167.                 ),
  168.                 calendarSet
  169.             );

  170.         if (null == nonHonored)
  171.         {
  172.             return null;
  173.         }

  174.         org.drip.exposure.csatimeline.EventDate ped = org.drip.exposure.csatimeline.EventDateBuilder.PED (
  175.             nonHonored.date().addBusDays (
  176.                 org.drip.exposure.csatimeline.EventDateBuilder.PED_CALL_OUT_DELAY_AGGRESSIVE,
  177.                 calendarSet
  178.             )
  179.         );

  180.         if (null == ped)
  181.         {
  182.             return null;
  183.         }

  184.         org.drip.exposure.csatimeline.EventDate ed =
  185.             org.drip.exposure.csatimeline.EventDateBuilder.IMA2002ED (
  186.                 ped,
  187.                 calendarSet
  188.             );

  189.         if (null == ed)
  190.         {
  191.             return null;
  192.         }

  193.         org.drip.exposure.csatimeline.EventDate etdDesignation =
  194.             org.drip.exposure.csatimeline.EventDateBuilder.ETDDesignation (
  195.                 ped.date().addBusDays (
  196.                     org.drip.exposure.csatimeline.EventDateBuilder.ETD_DESIGNATION_DELAY_AGGRESSIVE,
  197.                     calendarSet
  198.                 )
  199.             );

  200.         if (null == etdDesignation)
  201.         {
  202.             return null;
  203.         }

  204.         try
  205.         {
  206.             return new EventSequence (
  207.                 valuation,
  208.                 honored,
  209.                 org.drip.exposure.csatimeline.EventDateBuilder.RegularCollateralTransferInitiation (
  210.                     honored,
  211.                     calendarSet
  212.                 ),
  213.                 nonHonored,
  214.                 ped,
  215.                 org.drip.exposure.csatimeline.EventDateBuilder.PEDCommunication (
  216.                     ped.date().addBusDays (
  217.                         org.drip.exposure.csatimeline.EventDateBuilder.PED_COMMUNICATION_DELAY_AGGRESSIVE,
  218.                         calendarSet
  219.                     )
  220.                 ),
  221.                 ed,
  222.                 org.drip.exposure.csatimeline.EventDateBuilder.EDCommunication (
  223.                     ed.date().addBusDays (
  224.                         org.drip.exposure.csatimeline.EventDateBuilder.ED_COMMUNICATION_DELAY_AGGRESSIVE,
  225.                         calendarSet
  226.                     )
  227.                 ),
  228.                 etdDesignation,
  229.                 org.drip.exposure.csatimeline.EventDateBuilder.ETD (
  230.                     etdDesignation.date().addBusDays (
  231.                         org.drip.exposure.csatimeline.EventDateBuilder.ETD_CALL_OUT_DELAY_AGGRESSIVE,
  232.                         calendarSet
  233.                     )
  234.                 ),
  235.                 org.drip.exposure.csatimeline.EventDateBuilder.MARGIN_FREQUENCY_DAILY,
  236.                 org.drip.exposure.csatimeline.EventDateBuilder.CURE_PERIOD_IMA_2002,
  237.                 calendarSet
  238.             );
  239.         }
  240.         catch (java.lang.Exception e)
  241.         {
  242.             e.printStackTrace();
  243.         }

  244.         return null;
  245.     }

  246.     /**
  247.      * Construct an Instance of Conservative EventSequence
  248.      *
  249.      * @param valuationDate The Valuation Date
  250.      * @param calendarSet The Calendar Set
  251.      *
  252.      * @return Instance of Conservative EventSequence
  253.      */

  254.     public static final EventSequence Conservative (
  255.         final org.drip.analytics.date.JulianDate valuationDate,
  256.         final java.lang.String calendarSet)
  257.     {
  258.         if (null == valuationDate)
  259.         {
  260.             return null;
  261.         }

  262.         org.drip.exposure.csatimeline.EventDate valuation =
  263.             org.drip.exposure.csatimeline.EventDateBuilder.Valuation (valuationDate);

  264.         if (null == valuation)
  265.         {
  266.             return null;
  267.         }

  268.         org.drip.exposure.csatimeline.EventDate honored =
  269.             org.drip.exposure.csatimeline.EventDateBuilder.Honored (
  270.                 valuation,
  271.                 calendarSet
  272.             );

  273.         if (null == honored)
  274.         {
  275.             return null;
  276.         }

  277.         org.drip.exposure.csatimeline.EventDate nonHonored =
  278.             org.drip.exposure.csatimeline.EventDateBuilder.NonHonored (
  279.                 org.drip.exposure.csatimeline.EventDateBuilder.Valuation (
  280.                     valuation.date().addBusDays (
  281.                         org.drip.exposure.csatimeline.EventDateBuilder.MARGIN_FREQUENCY_DAILY,
  282.                         calendarSet
  283.                     )
  284.                 ),
  285.                 calendarSet
  286.             );

  287.         if (null == nonHonored)
  288.         {
  289.             return null;
  290.         }

  291.         org.drip.exposure.csatimeline.EventDate ped = org.drip.exposure.csatimeline.EventDateBuilder.PED (
  292.             nonHonored.date().addBusDays (
  293.                 org.drip.exposure.csatimeline.EventDateBuilder.PED_CALL_OUT_DELAY_CONSERVATIVE,
  294.                 calendarSet
  295.             )
  296.         );

  297.         if (null == ped)
  298.         {
  299.             return null;
  300.         }

  301.         org.drip.exposure.csatimeline.EventDate ed =
  302.             org.drip.exposure.csatimeline.EventDateBuilder.IMA2002ED (
  303.                 ped,
  304.                 calendarSet
  305.             );

  306.         if (null == ed)
  307.         {
  308.             return null;
  309.         }

  310.         org.drip.exposure.csatimeline.EventDate etdDesignation =
  311.             org.drip.exposure.csatimeline.EventDateBuilder.ETDDesignation (
  312.                 ped.date().addBusDays (
  313.                     org.drip.exposure.csatimeline.EventDateBuilder.ETD_DESIGNATION_DELAY_CONSERVATIVE,
  314.                     calendarSet
  315.                 )
  316.             );

  317.         if (null == etdDesignation)
  318.         {
  319.             return null;
  320.         }

  321.         try
  322.         {
  323.             return new EventSequence (
  324.                 valuation,
  325.                 honored,
  326.                 org.drip.exposure.csatimeline.EventDateBuilder.RegularCollateralTransferInitiation (
  327.                     honored,
  328.                     calendarSet
  329.                 ),
  330.                 nonHonored,
  331.                 ped,
  332.                 org.drip.exposure.csatimeline.EventDateBuilder.PEDCommunication (
  333.                     ped.date().addBusDays (
  334.                         org.drip.exposure.csatimeline.EventDateBuilder.PED_COMMUNICATION_DELAY_CONSERVATIVE,
  335.                         calendarSet
  336.                     )
  337.                 ),
  338.                 ed,
  339.                 org.drip.exposure.csatimeline.EventDateBuilder.EDCommunication (
  340.                     ed.date().addBusDays (
  341.                         org.drip.exposure.csatimeline.EventDateBuilder.ED_COMMUNICATION_DELAY_CONSERVATIVE,
  342.                         calendarSet
  343.                     )
  344.                 ),
  345.                 etdDesignation,
  346.                 org.drip.exposure.csatimeline.EventDateBuilder.ETD (
  347.                     etdDesignation.date().addBusDays (
  348.                         org.drip.exposure.csatimeline.EventDateBuilder.ETD_CALL_OUT_DELAY_CONSERVATIVE,
  349.                         calendarSet
  350.                     )
  351.                 ),
  352.                 org.drip.exposure.csatimeline.EventDateBuilder.MARGIN_FREQUENCY_DAILY,
  353.                 org.drip.exposure.csatimeline.EventDateBuilder.CURE_PERIOD_IMA_2002,
  354.                 calendarSet
  355.             );
  356.         }
  357.         catch (java.lang.Exception e)
  358.         {
  359.             e.printStackTrace();
  360.         }

  361.         return null;
  362.     }

  363.     /**
  364.      * @param valuation The CSA Valuation Event Date
  365.      * @param honored The CSA Honored Event Date
  366.      * @param collateralTransferInitiation The CSA Collateral Transfer Initiation Event Date
  367.      * @param nonHonored The CSA Non-Honored Event Date
  368.      * @param ped The Potential Event of Default
  369.      * @param pedCommunication The Potential Event of Default Communication Date
  370.      * @param ed The Event of Default
  371.      * @param edCommunication The Event of Default Communication Date
  372.      * @param etdDesignation The Early Termination Designation Date
  373.      * @param etd The Early Termination Date
  374.      * @param marginFrequency The CSA Margin Frequency
  375.      * @param curePeriod The Client "Failure To Pay" Cure Period
  376.      * @param calendarSet The CSA Calendar Set
  377.      *
  378.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  379.      */

  380.     public EventSequence (
  381.         final org.drip.exposure.csatimeline.EventDate valuation,
  382.         final org.drip.exposure.csatimeline.EventDate honored,
  383.         final org.drip.exposure.csatimeline.EventDate collateralTransferInitiation,
  384.         final org.drip.exposure.csatimeline.EventDate nonHonored,
  385.         final org.drip.exposure.csatimeline.EventDate ped,
  386.         final org.drip.exposure.csatimeline.EventDate pedCommunication,
  387.         final org.drip.exposure.csatimeline.EventDate ed,
  388.         final org.drip.exposure.csatimeline.EventDate edCommunication,
  389.         final org.drip.exposure.csatimeline.EventDate etdDesignation,
  390.         final org.drip.exposure.csatimeline.EventDate etd,
  391.         final int marginFrequency,
  392.         final int curePeriod,
  393.         final java.lang.String calendarSet)
  394.         throws java.lang.Exception
  395.     {
  396.         if (null == (_valuation = valuation) ||
  397.             null == (_honored = honored) ||
  398.             null == (_collateralTransferInitiation = collateralTransferInitiation) ||
  399.             null == (_nonHonored = nonHonored) ||
  400.             null == (_ped = ped) ||
  401.             null == (_pedCommunication = pedCommunication) ||
  402.             null == (_ed = ed) ||
  403.             null == (_edCommunication = edCommunication) ||
  404.             null == (_etdDesignation = etdDesignation) ||
  405.             null == (_etd = etd) ||
  406.             0 >= (_marginFrequency = marginFrequency) ||
  407.             0 >= (_curePeriod = curePeriod))
  408.         {
  409.             throw new java.lang.Exception ("EventSequence Constructor => Invalid Inputs");
  410.         }

  411.         _calendarSet = calendarSet;
  412.     }

  413.     /**
  414.      * Retrieve the CSA Calendar Set
  415.      *
  416.      * @return The CSA Calendar Set
  417.      */

  418.     public java.lang.String calendarSet()
  419.     {
  420.         return _calendarSet;
  421.     }

  422.     /**
  423.      * Retrieve the CSA Margin Frequency
  424.      *
  425.      * @return The CSA Margin Frequency
  426.      */

  427.     public int marginFrequency()
  428.     {
  429.         return _marginFrequency;
  430.     }

  431.     /**
  432.      * Retrieve the Client Cure Period
  433.      *
  434.      * @return The Client Cure Period
  435.      */

  436.     public int curePeriod()
  437.     {
  438.         return _curePeriod;
  439.     }

  440.     /**
  441.      * Retrieve the Valuation Event Date
  442.      *
  443.      * @return The Valuation Event Date
  444.      */

  445.     public org.drip.exposure.csatimeline.EventDate valuation()
  446.     {
  447.         return _valuation;
  448.     }

  449.     /**
  450.      * Retrieve the Honored Event Date
  451.      *
  452.      * @return The Honored Event Date
  453.      */

  454.     public org.drip.exposure.csatimeline.EventDate honored()
  455.     {
  456.         return _honored;
  457.     }

  458.     /**
  459.      * Retrieve the Collateral Transfer Initiation Event Date
  460.      *
  461.      * @return The Collateral Transfer Initiation Event Date
  462.      */

  463.     public org.drip.exposure.csatimeline.EventDate collateralTransferInitiation()
  464.     {
  465.         return _collateralTransferInitiation;
  466.     }

  467.     /**
  468.      * Retrieve the Non Honored Event Date
  469.      *
  470.      * @return The Non Honored Event Date
  471.      */

  472.     public org.drip.exposure.csatimeline.EventDate nonHonored()
  473.     {
  474.         return _nonHonored;
  475.     }

  476.     /**
  477.      * Retrieve the PED Event Date
  478.      *
  479.      * @return The PED Event Date
  480.      */

  481.     public org.drip.exposure.csatimeline.EventDate ped()
  482.     {
  483.         return _ped;
  484.     }

  485.     /**
  486.      * Retrieve the PED Communication Event Date
  487.      *
  488.      * @return The PED Communication Event Date
  489.      */

  490.     public org.drip.exposure.csatimeline.EventDate pedCommunication()
  491.     {
  492.         return _pedCommunication;
  493.     }

  494.     /**
  495.      * Retrieve the ED Event Date
  496.      *
  497.      * @return The ED Event Date
  498.      */

  499.     public org.drip.exposure.csatimeline.EventDate ed()
  500.     {
  501.         return _ed;
  502.     }

  503.     /**
  504.      * Retrieve the ED Communication Event Date
  505.      *
  506.      * @return The ED Communication Event Date
  507.      */

  508.     public org.drip.exposure.csatimeline.EventDate edCommunication()
  509.     {
  510.         return _edCommunication;
  511.     }

  512.     /**
  513.      * Retrieve the ETD Designation Event Date
  514.      *
  515.      * @return The ETD Designation Event Date
  516.      */

  517.     public org.drip.exposure.csatimeline.EventDate etdDesignation()
  518.     {
  519.         return _etdDesignation;
  520.     }

  521.     /**
  522.      * Retrieve the ETD Event Date
  523.      *
  524.      * @return The ETD Event Date
  525.      */

  526.     public org.drip.exposure.csatimeline.EventDate etd()
  527.     {
  528.         return _etd;
  529.     }

  530.     /**
  531.      * Retrieve the Margin Period Start Date
  532.      *
  533.      * @return The Margin Period Start Date
  534.      */

  535.     public org.drip.analytics.date.JulianDate marginPeriodStart()
  536.     {
  537.         return _honored.date();
  538.     }

  539.     /**
  540.      * Retrieve the Margin Period End Date
  541.      *
  542.      * @return The Margin Period End Date
  543.      */

  544.     public org.drip.analytics.date.JulianDate marginPeriodEnd()
  545.     {
  546.         return _etd.date();
  547.     }

  548.     /**
  549.      * Retrieve the Margin Duration
  550.      *
  551.      * @return The Margin Duration
  552.      */

  553.     public int marginDuration()
  554.     {
  555.         return _etd.date().julian() - _honored.date().julian();
  556.     }
  557. }