EventDateBuilder.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>EventDateBuilder</i> builds the CSA BCBS/IOSCO Dates prescribed Events Time-line occurring Margin
  77.  * Period. The 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 EventDateBuilder
  115. {

  116.     /**
  117.      * 1992 ISDA IMA Cure Period of 3 Business Days
  118.      */

  119.     public static final int CURE_PERIOD_IMA_1992 = 3;

  120.     /**
  121.      * 2002 ISDA IMA Cure Period of 1 Business Day
  122.      */

  123.     public static final int CURE_PERIOD_IMA_2002 = 1;

  124.     /**
  125.      * Daily Margining Frequency
  126.      */

  127.     public static final int MARGIN_FREQUENCY_DAILY = 1;

  128.     /**
  129.      * PED Call Out Delay - Aggressive
  130.      */

  131.     public static final int PED_CALL_OUT_DELAY_AGGRESSIVE = 1;

  132.     /**
  133.      * PED Call Out Delay - Conservative
  134.      */

  135.     public static final int PED_CALL_OUT_DELAY_CONSERVATIVE = 3;

  136.     /**
  137.      * PED Communication Delay - Aggressive
  138.      */

  139.     public static final int PED_COMMUNICATION_DELAY_AGGRESSIVE = 1;

  140.     /**
  141.      * PED Communication Delay - Conservative
  142.      */

  143.     public static final int PED_COMMUNICATION_DELAY_CONSERVATIVE = 2;

  144.     /**
  145.      * ED Communication Delay - Aggressive
  146.      */

  147.     public static final int ED_COMMUNICATION_DELAY_AGGRESSIVE = 1;

  148.     /**
  149.      * ED Communication Delay - Conservative
  150.      */

  151.     public static final int ED_COMMUNICATION_DELAY_CONSERVATIVE = 2;

  152.     /**
  153.      * ETD Designation Delay - Aggressive
  154.      */

  155.     public static final int ETD_DESIGNATION_DELAY_AGGRESSIVE = 1;

  156.     /**
  157.      * ETD Designation Delay - Conservative
  158.      */

  159.     public static final int ETD_DESIGNATION_DELAY_CONSERVATIVE = 3;

  160.     /**
  161.      * ETD Call-out Delay - Aggressive
  162.      */

  163.     public static final int ETD_CALL_OUT_DELAY_AGGRESSIVE = 1;

  164.     /**
  165.      * ETD Call-out Delay - Conservative
  166.      */

  167.     public static final int ETD_CALL_OUT_DELAY_CONSERVATIVE = 12;

  168.     /**
  169.      * Construct the CSA Valuation Event Date
  170.      *
  171.      * @param date The Valuation Date
  172.      *
  173.      * @return The CSA Valuation Event Date
  174.      */

  175.     public static final EventDate Valuation (
  176.         final org.drip.analytics.date.JulianDate date)
  177.     {
  178.         try
  179.         {
  180.             return new EventDate (
  181.                 date,
  182.                 "Valuation Date",
  183.                 "T0"
  184.             );
  185.         }
  186.         catch (java.lang.Exception e)
  187.         {
  188.             e.printStackTrace();
  189.         }

  190.         return null;
  191.     }

  192.     /**
  193.      * Construct the Undisputed and Respected CSA Event Date
  194.      *
  195.      * @param date The CSA Honored Date
  196.      *
  197.      * @return The Undisputed and Respected CSA Event Date
  198.      */

  199.     public static final org.drip.exposure.csatimeline.EventDate Honored (
  200.         final org.drip.analytics.date.JulianDate date)
  201.     {
  202.         try
  203.         {
  204.             return new org.drip.exposure.csatimeline.EventDate (
  205.                 date,
  206.                 "Honored Date",
  207.                 "T1"
  208.             );
  209.         }
  210.         catch (java.lang.Exception e)
  211.         {
  212.             e.printStackTrace();
  213.         }

  214.         return null;
  215.     }

  216.     /**
  217.      * Construct the Undisputed and Respected CSA Event Date from the CSA Valuation Date
  218.      *
  219.      * @param valuation The CSA Valuation Event Date
  220.      * @param calendarSet The Calendar Set
  221.      *
  222.      * @return The Undisputed and Respected CSA Event Date from the CSA Valuation Date
  223.      */

  224.     public static final org.drip.exposure.csatimeline.EventDate Honored (
  225.         final org.drip.exposure.csatimeline.EventDate valuation,
  226.         final java.lang.String calendarSet)
  227.     {
  228.         return null == valuation ? null : Honored (
  229.             valuation.date().addBusDays (
  230.                 1,
  231.                 calendarSet
  232.             )
  233.         );
  234.     }

  235.     /**
  236.      * Construct the Collateral Transfer Initiation CSA Event Date
  237.      *
  238.      * @param date The Collateral Transfer Initiation Date
  239.      *
  240.      * @return The Collateral Transfer Initiation CSA Event Date
  241.      */

  242.     public static final EventDate CollateralTransferInitiation (
  243.         final org.drip.analytics.date.JulianDate date)
  244.     {
  245.         try
  246.         {
  247.             return new EventDate (
  248.                 date,
  249.                 "Collateral Transfer Initiation Date",
  250.                 "T2"
  251.             );
  252.         }
  253.         catch (java.lang.Exception e)
  254.         {
  255.             e.printStackTrace();
  256.         }

  257.         return null;
  258.     }

  259.     /**
  260.      * Construct the Regular Collateral Transfer Initiation CSA Event Date
  261.      *
  262.      * @param honored The CSA Last Honored Event Date
  263.      * @param calendarSet The Calendar Set
  264.      *
  265.      * @return The Regular Collateral Transfer Initiation CSA Event Date
  266.      */

  267.     public static final EventDate RegularCollateralTransferInitiation (
  268.         final org.drip.exposure.csatimeline.EventDate honored,
  269.         final java.lang.String calendarSet)
  270.     {
  271.         return null == honored ? null : CollateralTransferInitiation (
  272.             honored.date().addBusDays (
  273.                 1,
  274.                 calendarSet
  275.             )
  276.         );
  277.     }

  278.     /**
  279.      * Construct the Delayed Collateral Transfer Initiation CSA Event Date
  280.      *
  281.      * @param honored The CSA Last Honored Event Date
  282.      * @param calendarSet The Calendar Set
  283.      *
  284.      * @return The Delayed Collateral Transfer Initiation CSA Event Date
  285.      */

  286.     public static final EventDate DelayedCollateralTransferInitiation (
  287.         final org.drip.exposure.csatimeline.EventDate honored,
  288.         final java.lang.String calendarSet)
  289.     {
  290.         return null == honored ? null : CollateralTransferInitiation (
  291.             honored.date().addBusDays (
  292.                 2,
  293.                 calendarSet
  294.             )
  295.         );
  296.     }

  297.     /**
  298.      * Construct the Non-Honored CSA Event Date
  299.      *
  300.      * @param date The CSA Non-Honored Date
  301.      *
  302.      * @return The Non-Honored CSA Event Date
  303.      */

  304.     public static final EventDate NonHonored (
  305.         final org.drip.analytics.date.JulianDate date)
  306.     {
  307.         try
  308.         {
  309.             return new EventDate (
  310.                 date,
  311.                 "Non-Honored Date",
  312.                 "T3"
  313.             );
  314.         }
  315.         catch (java.lang.Exception e)
  316.         {
  317.             e.printStackTrace();
  318.         }

  319.         return null;
  320.     }

  321.     /**
  322.      * Construct the Non-Honored CSA Event Date
  323.      *
  324.      * @param valuation The CSA Valuation Event Date
  325.      * @param calendarSet The Calendar Set
  326.      *
  327.      * @return The Non-Honored CSA Event Date
  328.      */

  329.     public static final org.drip.exposure.csatimeline.EventDate NonHonored (
  330.         final org.drip.exposure.csatimeline.EventDate valuation,
  331.         final java.lang.String calendarSet)
  332.     {
  333.         return null == valuation ? null : NonHonored (
  334.             valuation.date().addBusDays (
  335.                 1,
  336.                 calendarSet
  337.             )
  338.         );
  339.     }

  340.     /**
  341.      * Construct the Potential Event of Default CSA Event Date
  342.      *
  343.      * @param date The Potential Event of Default Date
  344.      *
  345.      * @return The Potential Event of Default CSA Event Date
  346.      */

  347.     public static final EventDate PotentialEventOfDefault (
  348.         final org.drip.analytics.date.JulianDate date)
  349.     {
  350.         try
  351.         {
  352.             return new EventDate (
  353.                 date,
  354.                 "Potential Event of Default Date",
  355.                 "Tau"
  356.             );
  357.         }
  358.         catch (java.lang.Exception e)
  359.         {
  360.             e.printStackTrace();
  361.         }

  362.         return null;
  363.     }

  364.     /**
  365.      * Construct the Potential Event of Default CSA Event Date
  366.      *
  367.      * @param date The Potential Event of Default Date
  368.      *
  369.      * @return The Potential Event of Default CSA Event Date
  370.      */

  371.     public static final EventDate PED (
  372.         final org.drip.analytics.date.JulianDate date)
  373.     {
  374.         try
  375.         {
  376.             return new EventDate (
  377.                 date,
  378.                 "Potential Event of Default Date",
  379.                 "Tau"
  380.             );
  381.         }
  382.         catch (java.lang.Exception e)
  383.         {
  384.             e.printStackTrace();
  385.         }

  386.         return null;
  387.     }

  388.     /**
  389.      * Construct the PED Communication CSA Event Date
  390.      *
  391.      * @param date The PED Communication Date
  392.      *
  393.      * @return The PED Communication CSA Event Date
  394.      */

  395.     public static final EventDate PEDCommunication (
  396.         final org.drip.analytics.date.JulianDate date)
  397.     {
  398.         try
  399.         {
  400.             return new EventDate (
  401.                 date,
  402.                 "PED Communication Date",
  403.                 "T4"
  404.             );
  405.         }
  406.         catch (java.lang.Exception e)
  407.         {
  408.             e.printStackTrace();
  409.         }

  410.         return null;
  411.     }

  412.     /**
  413.      * Construct the Event of Default CSA Event Date
  414.      *
  415.      * @param date The Event of Default Date
  416.      *
  417.      * @return The Event of Default CSA Event Date
  418.      */

  419.     public static final EventDate EventOfDefault (
  420.         final org.drip.analytics.date.JulianDate date)
  421.     {
  422.         try
  423.         {
  424.             return new EventDate (
  425.                 date,
  426.                 "Event of Default Date",
  427.                 "T5"
  428.             );
  429.         }
  430.         catch (java.lang.Exception e)
  431.         {
  432.             e.printStackTrace();
  433.         }

  434.         return null;
  435.     }

  436.     /**
  437.      * Construct the Event of Default CSA Event Date
  438.      *
  439.      * @param date The Event of Default Date
  440.      *
  441.      * @return The Event of Default CSA Event Date
  442.      */

  443.     public static final EventDate ED (
  444.         final org.drip.analytics.date.JulianDate date)
  445.     {
  446.         try
  447.         {
  448.             return new EventDate (
  449.                 date,
  450.                 "Event of Default Date",
  451.                 "T5"
  452.             );
  453.         }
  454.         catch (java.lang.Exception e)
  455.         {
  456.             e.printStackTrace();
  457.         }

  458.         return null;
  459.     }

  460.     /**
  461.      * Construct the Cure Period Adjusted ED
  462.      *
  463.      * @param ped The PED CSA Event Date
  464.      * @param calendarSet The Calendar Set
  465.      * @param curePeriod The Cure Period
  466.      *
  467.      * @return The Cure Period Adjusted ED
  468.      */

  469.     public static final EventDate EventOfDefault (
  470.         final org.drip.exposure.csatimeline.EventDate ped,
  471.         final java.lang.String calendarSet,
  472.         final int curePeriod)
  473.     {
  474.         return null == ped ? null : EventOfDefault (
  475.             ped.date().addBusDays (
  476.                 curePeriod,
  477.                 calendarSet
  478.             )
  479.         );
  480.     }

  481.     /**
  482.      * Construct the IMA 1992 Cure Period Adjusted ED
  483.      *
  484.      * @param ped The PED CSA Event Date
  485.      * @param calendarSet The Calendar Set
  486.      *
  487.      * @return The IMA 1992 Cure Period Adjusted ED
  488.      */

  489.     public static final EventDate IMA1992ED (
  490.         final org.drip.exposure.csatimeline.EventDate ped,
  491.         final java.lang.String calendarSet)
  492.     {
  493.         return null == ped ? null : EventOfDefault (
  494.             ped.date().addBusDays (
  495.                 CURE_PERIOD_IMA_1992,
  496.                 calendarSet
  497.             )
  498.         );
  499.     }

  500.     /**
  501.      * Construct the IMA 2002 Cure Period Adjusted ED
  502.      *
  503.      * @param ped The PED CSA Event Date
  504.      * @param calendarSet The Calendar Set
  505.      *
  506.      * @return The IMA 2002 Cure Period Adjusted ED
  507.      */

  508.     public static final EventDate IMA2002ED (
  509.         final org.drip.exposure.csatimeline.EventDate ped,
  510.         final java.lang.String calendarSet)
  511.     {
  512.         return null == ped ? null : EventOfDefault (
  513.             ped.date().addBusDays (
  514.                 CURE_PERIOD_IMA_2002,
  515.                 calendarSet
  516.             )
  517.         );
  518.     }

  519.     /**
  520.      * Construct the ED Communication CSA Event Date
  521.      *
  522.      * @param date The ED Communication Date
  523.      *
  524.      * @return The ED Communication CSA Event Date
  525.      */

  526.     public static final EventDate EDCommunication (
  527.         final org.drip.analytics.date.JulianDate date)
  528.     {
  529.         try
  530.         {
  531.             return new EventDate (
  532.                 date,
  533.                 "ED Communication Date",
  534.                 "T6"
  535.             );
  536.         }
  537.         catch (java.lang.Exception e)
  538.         {
  539.             e.printStackTrace();
  540.         }

  541.         return null;
  542.     }

  543.     /**
  544.      * Construct the ETD Designation CSA Event Date
  545.      *
  546.      * @param date The ETD Designation Date
  547.      *
  548.      * @return The ETD Designation CSA Event Date
  549.      */

  550.     public static final EventDate ETDDesignation (
  551.         final org.drip.analytics.date.JulianDate date)
  552.     {
  553.         try
  554.         {
  555.             return new EventDate (
  556.                 date,
  557.                 "ETD Designation Date",
  558.                 "T7"
  559.             );
  560.         }
  561.         catch (java.lang.Exception e)
  562.         {
  563.             e.printStackTrace();
  564.         }

  565.         return null;
  566.     }

  567.     /**
  568.      * Construct the Early Termination Date (ETD) CSA Event Date
  569.      *
  570.      * @param date The Early Termination Date (ETD)
  571.      *
  572.      * @return The Early Termination Date (ETD) CSA Event Date
  573.      */

  574.     public static final EventDate ETD (
  575.         final org.drip.analytics.date.JulianDate date)
  576.     {
  577.         try
  578.         {
  579.             return new EventDate (
  580.                 date,
  581.                 "Early Termination Date",
  582.                 "T8"
  583.             );
  584.         }
  585.         catch (java.lang.Exception e)
  586.         {
  587.             e.printStackTrace();
  588.         }

  589.         return null;
  590.     }

  591.     /**
  592.      * Construct the Early Termination Date (ETD) CSA Event Date
  593.      *
  594.      * @param date The Early Termination Date (ETD)
  595.      *
  596.      * @return The Early Termination Date (ETD) CSA Event Date
  597.      */

  598.     public static final EventDate EarlyTerminationDate (
  599.         final org.drip.analytics.date.JulianDate date)
  600.     {
  601.         try
  602.         {
  603.             return new EventDate (
  604.                 date,
  605.                 "Early Termination Date",
  606.                 "T8"
  607.             );
  608.         }
  609.         catch (java.lang.Exception e)
  610.         {
  611.             e.printStackTrace();
  612.         }

  613.         return null;
  614.     }
  615. }