AndersenPykhtinSokolDates.java

  1. package org.drip.sample.csaevents;

  2. import org.drip.analytics.date.DateUtil;
  3. import org.drip.analytics.date.JulianDate;
  4. import org.drip.exposure.csatimeline.AndersenPykhtinSokolLag;
  5. import org.drip.exposure.csatimeline.LastFlowDates;
  6. import org.drip.service.env.EnvManager;

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

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

  80. /**
  81.  * <i>AndersenPykhtinSokolDates</i> generates the Intra-Period Dates inside a Margin. Flow Dates are
  82.  * generated for the Classical+, Classical-, "Aggressive", and "Conservative" Timeline Schemes. The
  83.  * References are:
  84.  *  
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Re-thinking Margin Period of Risk
  89.  *              https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2902737 <b>eSSRN</b>
  90.  *      </li>
  91.  *      <li>
  92.  *          Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial
  93.  *              Margin https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156 <b>eSSRN</b>
  94.  *      </li>
  95.  *      <li>
  96.  *          Anfuso, F., D. Aziz, P. Giltinan, and K Loukopoulus (2017): A Sound Modeling and Back-testing
  97.  *              Framework for Forecasting Initial Margin Requirements
  98.  *              https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2716279 <b>eSSRN</b>
  99.  *      </li>
  100.  *      <li>
  101.  *          BCBS (2015): Margin Requirements for Non-centrally Cleared Derivatives
  102.  *              https://www.bis.org/bcbs/publ/d317.pdf
  103.  *      </li>
  104.  *      <li>
  105.  *          Pykhtin, M. (2009): Modeling Credit Exposure for Collateralized Counter-parties <i>Journal of
  106.  *              Credit Risk</i> <b>5 (4)</b> 3-27
  107.  *      </li>
  108.  *  </ul>
  109.  *  
  110.  * <br><br>
  111.  *  <ul>
  112.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  113.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ExposureAnalyticsLibrary.md">Exposure Analytics</a></li>
  114.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  115.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/csaevents/README.md">Time-line of IMA/CSA Event Sequences</a></li>
  116.  *  </ul>
  117.  * <br><br>
  118.  *
  119.  * @author Lakshmi Krishnamurthy
  120.  */

  121. public class AndersenPykhtinSokolDates
  122. {

  123.     public static final void main (
  124.         final String[] args)
  125.         throws Exception
  126.     {
  127.         EnvManager.InitEnv ("");

  128.         JulianDate spot = DateUtil.CreateFromYMD (
  129.             2018,
  130.             DateUtil.APRIL,
  131.             16
  132.         );

  133.         String calendar = "USD";

  134.         LastFlowDates csaFlowDatesClassicalPlus = LastFlowDates.SpotStandard (
  135.             spot,
  136.             AndersenPykhtinSokolLag.ClassicalPlus(),
  137.             calendar
  138.         );

  139.         LastFlowDates csaFlowDatesClassicalMinus = LastFlowDates.SpotStandard (
  140.             spot,
  141.             AndersenPykhtinSokolLag.ClassicalMinus(),
  142.             calendar
  143.         );

  144.         LastFlowDates csaFlowDatesAggressive = LastFlowDates.SpotStandard (
  145.             spot,
  146.             AndersenPykhtinSokolLag.Aggressive(),
  147.             calendar
  148.         );

  149.         LastFlowDates csaFlowDatesConservative = LastFlowDates.SpotStandard (
  150.             spot,
  151.             AndersenPykhtinSokolLag.Conservative(),
  152.             calendar
  153.         );

  154.         System.out.println (
  155.             "\t|------------------------------------------------------------------------------------------------||"
  156.         );

  157.         System.out.println (
  158.             "\t|      INTRA-MARGIN CSA EVENT DATE GENERATION USING ANDERSEN PYKHTIN SOKOL PARAMETRIZATION       ||"
  159.         );

  160.         System.out.println (
  161.             "\t|------------------------------------------------------------------------------------------------||"
  162.         );

  163.         System.out.println (
  164.             "\t|                                                                                                ||"
  165.         );

  166.         System.out.println (
  167.             "\t|    L -> R:                                                                                     ||"
  168.         );

  169.         System.out.println (
  170.             "\t|                                                                                                ||"
  171.         );

  172.         System.out.println (
  173.             "\t|        - CSA Event Date                                                                        ||"
  174.         );

  175.         System.out.println (
  176.             "\t|        - CSA Event Type                                                                        ||"
  177.         );

  178.         System.out.println (
  179.             "\t|        - Classical- Scheme                                                                     ||"
  180.         );

  181.         System.out.println (
  182.             "\t|        - Classical+ Scheme                                                                     ||"
  183.         );

  184.         System.out.println (
  185.             "\t|        - Aggressive Scheme                                                                     ||"
  186.         );

  187.         System.out.println (
  188.             "\t|        - Conservative Scheme                                                                   ||"
  189.         );

  190.         System.out.println (
  191.             "\t|                                                                                                ||"
  192.         );

  193.         System.out.println (
  194.             "\t|------------------------------------------------------------------------------------------------||"
  195.         );

  196.         System.out.println (
  197.             "\t| Margin Valuation Date   => SETTLEMENT  | " +
  198.             csaFlowDatesClassicalPlus.valuation() + " | " +
  199.             csaFlowDatesClassicalMinus.valuation() + " | " +
  200.             csaFlowDatesAggressive.valuation() + " | " +
  201.             csaFlowDatesConservative.valuation() + " ||"
  202.         );

  203.         System.out.println (
  204.             "\t| Client Margin Flow Date => OBSERVATION | " +
  205.             csaFlowDatesClassicalPlus.clientVariationMarginPosting() + " | " +
  206.             csaFlowDatesClassicalMinus.clientVariationMarginPosting() + " | " +
  207.             csaFlowDatesAggressive.clientVariationMarginPosting() + " | " +
  208.             csaFlowDatesConservative.clientVariationMarginPosting() + " ||"
  209.         );

  210.         System.out.println (
  211.             "\t| Dealer Margin Flow Date => OBSERVATION | " +
  212.             csaFlowDatesClassicalPlus.dealerVariationMarginPosting() + " | " +
  213.             csaFlowDatesClassicalMinus.dealerVariationMarginPosting() + " | " +
  214.             csaFlowDatesAggressive.dealerVariationMarginPosting() + " | " +
  215.             csaFlowDatesConservative.dealerVariationMarginPosting() + " ||"
  216.         );

  217.         System.out.println (
  218.             "\t| Client Trade Flow Date  => SETTLEMENT  | " +
  219.             csaFlowDatesClassicalPlus.clientTradePayment() + " | " +
  220.             csaFlowDatesClassicalMinus.clientTradePayment() + " | " +
  221.             csaFlowDatesAggressive.clientTradePayment() + " | " +
  222.             csaFlowDatesConservative.clientTradePayment() + " ||"
  223.         );

  224.         System.out.println (
  225.             "\t| Dealer Trade Flow Date  => SETTLEMENT  | " +
  226.             csaFlowDatesClassicalPlus.dealerTradePayment() + " | " +
  227.             csaFlowDatesClassicalMinus.dealerTradePayment() + " | " +
  228.             csaFlowDatesAggressive.dealerTradePayment() + " | " +
  229.             csaFlowDatesConservative.dealerTradePayment() + " ||"
  230.         );

  231.         System.out.println (
  232.             "\t| Early Termination Date  => OBSERVATION | " +
  233.             csaFlowDatesClassicalPlus.spot() + " | " +
  234.             csaFlowDatesClassicalMinus.spot() + " | " +
  235.             csaFlowDatesAggressive.spot() + " | " +
  236.             csaFlowDatesConservative.spot() + " ||"
  237.         );

  238.         System.out.println (
  239.             "\t| Spot Date               => OBSERVATION | " +
  240.             csaFlowDatesClassicalPlus.spot() + " | " +
  241.             csaFlowDatesClassicalMinus.spot() + " | " +
  242.             csaFlowDatesAggressive.spot() + " | " +
  243.             csaFlowDatesConservative.spot() + " ||"
  244.         );

  245.         System.out.println (
  246.             "\t|------------------------------------------------------------------------------------------------||"
  247.         );

  248.         EnvManager.TerminateEnv();
  249.     }
  250. }