LastFlowDates.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>LastFlowDates</i> holds the Last Client/Dealer Margin Flow and Trade Flow Dates using the
  77.  * Parameterization laid out in Andersen, Pykhtin, and Sokol (2017). 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 LastFlowDates
  115. {
  116.     private org.drip.analytics.date.JulianDate _spot = null;
  117.     private org.drip.analytics.date.JulianDate _valuation = null;
  118.     private org.drip.analytics.date.JulianDate _clientTradePayment = null;
  119.     private org.drip.analytics.date.JulianDate _dealerTradePayment = null;
  120.     private org.drip.analytics.date.JulianDate _variationMarginPeriodEnd = null;
  121.     private org.drip.analytics.date.JulianDate _variationMarginPeriodStart = null;
  122.     private org.drip.analytics.date.JulianDate _clientVariationMarginPosting = null;
  123.     private org.drip.analytics.date.JulianDate _dealerVariationMarginPosting = null;

  124.     /**
  125.      * Generate a LastFlowDates Instance from the Spot Date and the AndersenPykhtinSokolLag
  126.      *
  127.      * @param spot The Spot Date
  128.      * @param andersenPykhtinSokolLag AndersenPykhtinSokolLag Instance
  129.      * @param calendarSet The Business Day Calendar Set
  130.      *
  131.      * @return The LastFlowDates Instance
  132.      */

  133.     public static final LastFlowDates SpotStandard (
  134.         final org.drip.analytics.date.JulianDate spot,
  135.         final org.drip.exposure.csatimeline.AndersenPykhtinSokolLag andersenPykhtinSokolLag,
  136.         final java.lang.String calendarSet)
  137.     {
  138.         if (null == spot || null == andersenPykhtinSokolLag)
  139.         {
  140.             return null;
  141.         }

  142.         org.drip.analytics.date.JulianDate clientVariationMarginPostingDate = spot.subtractBusDays (
  143.             andersenPykhtinSokolLag.clientVariationMarginPostingDelay(),
  144.             calendarSet
  145.         );

  146.         org.drip.analytics.date.JulianDate dealerVariationMarginPostingDate = spot.subtractBusDays (
  147.             andersenPykhtinSokolLag.dealerVariationMarginPostingDelay(),
  148.             calendarSet
  149.         );

  150.         if (null == clientVariationMarginPostingDate || null == dealerVariationMarginPostingDate)
  151.         {
  152.             return null;
  153.         }

  154.         try
  155.         {
  156.             return new LastFlowDates (
  157.                 clientVariationMarginPostingDate.subtractBusDays (
  158.                     1,
  159.                     calendarSet
  160.                 ),
  161.                 clientVariationMarginPostingDate,
  162.                 dealerVariationMarginPostingDate,
  163.                 spot.subtractBusDays (
  164.                     andersenPykhtinSokolLag.clientTradePaymentDelay(),
  165.                     calendarSet
  166.                 ),
  167.                 spot.subtractBusDays (
  168.                     andersenPykhtinSokolLag.dealerTradePaymentDelay(),
  169.                     calendarSet
  170.                 ),
  171.                 spot,
  172.                 clientVariationMarginPostingDate.julian() < dealerVariationMarginPostingDate.julian() ?
  173.                     clientVariationMarginPostingDate : dealerVariationMarginPostingDate,
  174.                 spot
  175.             );
  176.         }
  177.         catch (java.lang.Exception e)
  178.         {
  179.             e.printStackTrace();
  180.         }

  181.         return null;
  182.     }

  183.     /**
  184.      * LastFlowDates Constructor
  185.      *
  186.      * @param valuation The Margin Collateral Valuation Date
  187.      * @param clientVariationMarginPosting The Last Client Variation Margin Posting (Observation) Date
  188.      * @param dealerVariationMarginPosting The Last Dealer Variation Margin Posting (Observation) Date
  189.      * @param clientTradePayment The Last Client Trade Payment (Settlement) Date
  190.      * @param dealerTradePayment The Last Dealer Trade Payment (Settlement) Date
  191.      * @param spot The Spot Date
  192.      * @param variationMarginPeriodStart The Variation Margin Period Start Date
  193.      * @param variationMarginPeriodEnd The Variation Margin Period End Date
  194.      *
  195.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  196.      */

  197.     public LastFlowDates (
  198.         final org.drip.analytics.date.JulianDate valuation,
  199.         final org.drip.analytics.date.JulianDate clientVariationMarginPosting,
  200.         final org.drip.analytics.date.JulianDate dealerVariationMarginPosting,
  201.         final org.drip.analytics.date.JulianDate clientTradePayment,
  202.         final org.drip.analytics.date.JulianDate dealerTradePayment,
  203.         final org.drip.analytics.date.JulianDate spot,
  204.         final org.drip.analytics.date.JulianDate variationMarginPeriodStart,
  205.         final org.drip.analytics.date.JulianDate variationMarginPeriodEnd)
  206.         throws java.lang.Exception
  207.     {
  208.         if (null == (_valuation = valuation) ||
  209.             null == (_clientVariationMarginPosting = clientVariationMarginPosting) ||
  210.             null == (_dealerVariationMarginPosting = dealerVariationMarginPosting) ||
  211.             null == (_clientTradePayment = clientTradePayment) ||
  212.             null == (_dealerTradePayment = dealerTradePayment) ||
  213.             null == (_spot = spot) ||
  214.             null == (_variationMarginPeriodStart = variationMarginPeriodStart) ||
  215.             null == (_variationMarginPeriodEnd = variationMarginPeriodEnd))
  216.         {
  217.             throw new java.lang.Exception ("LastFlowDates Constructor => Invalid Inputs");
  218.         }
  219.     }

  220.     /**
  221.      * Retrieve the Valuation Date
  222.      *
  223.      * @return The Valuation Date
  224.      */

  225.     public org.drip.analytics.date.JulianDate valuation()
  226.     {
  227.         return _valuation;
  228.     }

  229.     /**
  230.      * Retrieve the Last Client Variation Margin Posting (Observation) Date
  231.      *
  232.      * @return The Last Client Variation Margin Posting (Observation) Date
  233.      */

  234.     public org.drip.analytics.date.JulianDate clientVariationMarginPosting()
  235.     {
  236.         return _clientVariationMarginPosting;
  237.     }

  238.     /**
  239.      * Retrieve the Last Dealer Variation Margin Posting (Observation) Date
  240.      *
  241.      * @return The Last Dealer Variation Margin Posting (Observation) Date
  242.      */

  243.     public org.drip.analytics.date.JulianDate dealerVariationMarginPosting()
  244.     {
  245.         return _dealerVariationMarginPosting;
  246.     }

  247.     /**
  248.      * Retrieve the Last Client Trade Payment (Settlement) Date
  249.      *
  250.      * @return The Last Client Trade Payment (Settlement) Date
  251.      */

  252.     public org.drip.analytics.date.JulianDate clientTradePayment()
  253.     {
  254.         return _clientTradePayment;
  255.     }

  256.     /**
  257.      * Retrieve the Last Dealer Trade Payment (Settlement) Date
  258.      *
  259.      * @return The Last Dealer Trade Payment (Settlement) Date
  260.      */

  261.     public org.drip.analytics.date.JulianDate dealerTradePayment()
  262.     {
  263.         return _dealerTradePayment;
  264.     }

  265.     /**
  266.      * Retrieve the Spot Date
  267.      *
  268.      * @return The Spot Date
  269.      */

  270.     public org.drip.analytics.date.JulianDate spot()
  271.     {
  272.         return _spot;
  273.     }

  274.     /**
  275.      * Retrieve the ETD
  276.      *
  277.      * @return The ETD
  278.      */

  279.     public org.drip.analytics.date.JulianDate etd()
  280.     {
  281.         return _spot;
  282.     }

  283.     /**
  284.      * Retrieve the Variation Margin Period Start Date
  285.      *
  286.      * @return The Variation Margin Period Start Date
  287.      */

  288.     public org.drip.analytics.date.JulianDate variationMarginPeriodStart()
  289.     {
  290.         return _variationMarginPeriodStart;
  291.     }

  292.     /**
  293.      * Retrieve the Variation Margin Period End Date
  294.      *
  295.      * @return The Variation Margin Period End Date
  296.      */

  297.     public org.drip.analytics.date.JulianDate variationMarginPeriodEnd()
  298.     {
  299.         return _variationMarginPeriodEnd;
  300.     }
  301. }