TrajectoryShortfallRealization.java

  1. package org.drip.execution.capture;

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

  77. /**
  78.  * <i>TrajectoryShortfallRealization</i> holds Execution Cost Realization across each Interval in the Trade
  79.  * during a Single Simulation Run. The References are:
  80.  *
  81.  * <br><br>
  82.  *  <ul>
  83.  *      <li>
  84.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  85.  *      </li>
  86.  *      <li>
  87.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  88.  *              Risk</i> <b>3 (2)</b> 5-39
  89.  *      </li>
  90.  *      <li>
  91.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  92.  *              Markets</i> <b>1</b> 1-50
  93.  *      </li>
  94.  *      <li>
  95.  *          Chan, L. K. C., and J. Lakonishak (1995): The Behavior of Stock Prices around Institutional
  96.  *              Trades <i>Journal of Finance</i> <b>50</b> 1147-1174
  97.  *      </li>
  98.  *      <li>
  99.  *          Keim, D. B., and A. Madhavan (1997): Transaction Costs and Investment Style: An Inter-exchange
  100.  *              Analysis of Institutional Equity Trades <i>Journal of Financial Economics</i> <b>46</b>
  101.  *              265-292
  102.  *      </li>
  103.  *  </ul>
  104.  *
  105.  *  <br><br>
  106.  *  <ul>
  107.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  108.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  109.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/README.md">Optimal Impact/Capture Based Trading Trajectories - Deterministic, Stochastic, Static, and Dynamic</a></li>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/capture/README.md">Execution Trajectory Transaction Cost Capture</a></li>
  111.  *  </ul>
  112.  *
  113.  * @author Lakshmi Krishnamurthy
  114.  */

  115. public class TrajectoryShortfallRealization {
  116.     private java.util.List<org.drip.execution.discrete.ShortfallIncrement> _lsSI = null;

  117.     /**
  118.      * TrajectoryShortfallRealization Constructor
  119.      *
  120.      * @param lsSI List of the Composite Slice Short-fall Increments
  121.      *
  122.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  123.      */

  124.     public TrajectoryShortfallRealization (
  125.         final java.util.List<org.drip.execution.discrete.ShortfallIncrement> lsSI)
  126.         throws java.lang.Exception
  127.     {
  128.         if (null == (_lsSI = lsSI))
  129.             throw new java.lang.Exception ("TrajectoryShortfallRealization Constructor => Invalid Inputs");

  130.         int iNumSlice = _lsSI.size();

  131.         if (0 == iNumSlice)
  132.             throw new java.lang.Exception ("TrajectoryShortfallRealization Constructor => Invalid Inputs");

  133.         for (org.drip.execution.discrete.ShortfallIncrement si : _lsSI) {
  134.             if (null == si)
  135.                 throw new java.lang.Exception
  136.                     ("TrajectoryShortfallRealization Constructor => Invalid Inputs");
  137.         }
  138.     }

  139.     /**
  140.      * Retrieve the List of the Realized Composite Cost Increments
  141.      *
  142.      * @return The List of the Realized Composite Cost Increments
  143.      */

  144.     public java.util.List<org.drip.execution.discrete.ShortfallIncrement> list()
  145.     {
  146.         return _lsSI;
  147.     }

  148.     /**
  149.      * Generate the Array of Incremental Market Dynamic Cost Drift
  150.      *
  151.      * @return The Array of Incremental Market Dynamic Cost Drift
  152.      */

  153.     public double[] incrementalMarketDynamicDrift()
  154.     {
  155.         int iNumInterval = _lsSI.size();

  156.         double[] adblIncrementalMarketDynamicDrift = new double[iNumInterval];

  157.         for (int i = 0; i < iNumInterval; ++i)
  158.             adblIncrementalMarketDynamicDrift[i] = _lsSI.get (i).marketDynamicDrift();

  159.         return adblIncrementalMarketDynamicDrift;
  160.     }

  161.     /**
  162.      * Generate the Array of Cumulative Market Dynamic Cost Drift
  163.      *
  164.      * @return The Array of Cumulative Market Dynamic Cost Drift
  165.      */

  166.     public double[] cumulativeMarketDynamicDrift()
  167.     {
  168.         int iNumInterval = _lsSI.size();

  169.         double[] adblCumulativeMarketDynamicDrift = new double[iNumInterval];

  170.         for (int i = 0; i < iNumInterval; ++i)
  171.             adblCumulativeMarketDynamicDrift[i] = 0 == i ? _lsSI.get (i).marketDynamicDrift() : _lsSI.get
  172.                 (i).marketDynamicDrift() + adblCumulativeMarketDynamicDrift[i - 1];

  173.         return adblCumulativeMarketDynamicDrift;
  174.     }

  175.     /**
  176.      * Generate the Total Market Dynamic Cost Drift
  177.      *
  178.      * @return The Total Market Dynamic Cost Drift
  179.      */

  180.     public double totalMarketDynamicDrift()
  181.     {
  182.         int iNumInterval = _lsSI.size();

  183.         double dblTotalMarketDynamicDrift = 0.;

  184.         for (int i = 0; i < iNumInterval; ++i)
  185.             dblTotalMarketDynamicDrift = dblTotalMarketDynamicDrift + _lsSI.get (i).marketDynamicDrift();

  186.         return dblTotalMarketDynamicDrift;
  187.     }

  188.     /**
  189.      * Generate the Array of Incremental Market Dynamic Cost Wander
  190.      *
  191.      * @return The Array of Incremental Market Dynamic Cost Wander
  192.      */

  193.     public double[] incrementalMarketDynamicWander()
  194.     {
  195.         int iNumInterval = _lsSI.size();

  196.         double[] adblIncrementalMarketDynamicWander = new double[iNumInterval];

  197.         for (int i = 0; i < iNumInterval; ++i)
  198.             adblIncrementalMarketDynamicWander[i] = _lsSI.get (i).marketDynamicWander();

  199.         return adblIncrementalMarketDynamicWander;
  200.     }

  201.     /**
  202.      * Generate the Array of Cumulative Market Dynamic Cost Wander
  203.      *
  204.      * @return The Array of Cumulative Market Dynamic Cost Wander
  205.      */

  206.     public double[] cumulativeMarketDynamicWander()
  207.     {
  208.         int iNumInterval = _lsSI.size();

  209.         double[] adblCumulativeMarketDynamicWander = new double[iNumInterval];

  210.         for (int i = 0; i < iNumInterval; ++i)
  211.             adblCumulativeMarketDynamicWander[i] = 0 == i ? _lsSI.get (i).marketDynamicWander() : _lsSI.get
  212.                 (i).marketDynamicWander() + adblCumulativeMarketDynamicWander[i - 1];

  213.         return adblCumulativeMarketDynamicWander;
  214.     }

  215.     /**
  216.      * Generate the Total Market Dynamic Cost Wander
  217.      *
  218.      * @return The Total Market Dynamic Cost Wander
  219.      */

  220.     public double totalMarketDynamicWander()
  221.     {
  222.         int iNumInterval = _lsSI.size();

  223.         double dblTotalMarketDynamicWander = 0.;

  224.         for (int i = 0; i < iNumInterval; ++i)
  225.             dblTotalMarketDynamicWander = dblTotalMarketDynamicWander + _lsSI.get (i).marketDynamicWander();

  226.         return dblTotalMarketDynamicWander;
  227.     }

  228.     /**
  229.      * Generate the Array of Incremental Permanent Cost Drift
  230.      *
  231.      * @return The Array of Incremental Permanent Cost Drift
  232.      */

  233.     public double[] incrementalPermanentDrift()
  234.     {
  235.         int iNumInterval = _lsSI.size();

  236.         double[] adblIncrementalPermanentDrift = new double[iNumInterval];

  237.         for (int i = 0; i < iNumInterval; ++i)
  238.             adblIncrementalPermanentDrift[i] = _lsSI.get (i).permanentImpactDrift();

  239.         return adblIncrementalPermanentDrift;
  240.     }

  241.     /**
  242.      * Generate the Array of Cumulative Permanent Cost Drift
  243.      *
  244.      * @return The Array of Cumulative Permanent Cost Drift
  245.      */

  246.     public double[] cumulativePermanentDrift()
  247.     {
  248.         int iNumInterval = _lsSI.size();

  249.         double[] adblCumulativePermanentDrift = new double[iNumInterval];

  250.         for (int i = 0; i < iNumInterval; ++i)
  251.             adblCumulativePermanentDrift[i] = 0 == i ? _lsSI.get (i).permanentImpactDrift() : _lsSI.get
  252.                 (i).permanentImpactDrift() + adblCumulativePermanentDrift[i - 1];

  253.         return adblCumulativePermanentDrift;
  254.     }

  255.     /**
  256.      * Generate the Total Permanent Cost Drift
  257.      *
  258.      * @return The Total Permanent Cost Drift
  259.      */

  260.     public double totalPermanentDrift()
  261.     {
  262.         int iNumInterval = _lsSI.size();

  263.         double dblTotalPermanentDrift = 0.;

  264.         for (int i = 0; i < iNumInterval; ++i)
  265.             dblTotalPermanentDrift = dblTotalPermanentDrift + _lsSI.get (i).permanentImpactDrift();

  266.         return dblTotalPermanentDrift;
  267.     }

  268.     /**
  269.      * Generate the Array of Incremental Permanent Cost Wander
  270.      *
  271.      * @return The Array of Incremental Permanent Cost Wander
  272.      */

  273.     public double[] incrementalPermanentWander()
  274.     {
  275.         int iNumInterval = _lsSI.size();

  276.         double[] adblIncrementalPermanentWander = new double[iNumInterval];

  277.         for (int i = 0; i < iNumInterval; ++i)
  278.             adblIncrementalPermanentWander[i] = _lsSI.get (i).permanentImpactWander();

  279.         return adblIncrementalPermanentWander;
  280.     }

  281.     /**
  282.      * Generate the Array of Cumulative Permanent Cost Wander
  283.      *
  284.      * @return The Array of Cumulative Permanent Cost Wander
  285.      */

  286.     public double[] cumulativePermanentWander()
  287.     {
  288.         int iNumInterval = _lsSI.size();

  289.         double[] adblCumulativePermanentWander = new double[iNumInterval];

  290.         for (int i = 0; i < iNumInterval; ++i)
  291.             adblCumulativePermanentWander[i] = 0 == i ? _lsSI.get (i).permanentImpactWander() : _lsSI.get
  292.                 (i).permanentImpactWander() + adblCumulativePermanentWander[i - 1];

  293.         return adblCumulativePermanentWander;
  294.     }

  295.     /**
  296.      * Generate the Total Permanent Cost Wander
  297.      *
  298.      * @return The Total Permanent Cost Wander
  299.      */

  300.     public double totalPermanentWander()
  301.     {
  302.         int iNumInterval = _lsSI.size();

  303.         double dblTotalPermanentWander = 0.;

  304.         for (int i = 0; i < iNumInterval; ++i)
  305.             dblTotalPermanentWander = dblTotalPermanentWander + _lsSI.get (i).permanentImpactWander();

  306.         return dblTotalPermanentWander;
  307.     }

  308.     /**
  309.      * Generate the Array of Incremental Temporary Cost Drift
  310.      *
  311.      * @return The Array of Incremental Temporary Cost Drift
  312.      */

  313.     public double[] incrementalTemporaryDrift()
  314.     {
  315.         int iNumInterval = _lsSI.size();

  316.         double[] adblIncrementalTemporaryDrift = new double[iNumInterval];

  317.         for (int i = 0; i < iNumInterval; ++i)
  318.             adblIncrementalTemporaryDrift[i] = _lsSI.get (i).temporaryImpactDrift();

  319.         return adblIncrementalTemporaryDrift;
  320.     }

  321.     /**
  322.      * Generate the Array of Cumulative Temporary Cost Drift
  323.      *
  324.      * @return The Array of Cumulative Temporary Cost Drift
  325.      */

  326.     public double[] cumulativeTemporaryDrift()
  327.     {
  328.         int iNumInterval = _lsSI.size();

  329.         double[] adblCumulativeTemporaryDrift = new double[iNumInterval];

  330.         for (int i = 0; i < iNumInterval; ++i)
  331.             adblCumulativeTemporaryDrift[i] = 0 == i ? _lsSI.get (i).temporaryImpactDrift() : _lsSI.get
  332.                 (i).temporaryImpactDrift() + adblCumulativeTemporaryDrift[i - 1];

  333.         return adblCumulativeTemporaryDrift;
  334.     }

  335.     /**
  336.      * Generate the Total Temporary Cost Drift
  337.      *
  338.      * @return The Total Temporary Cost Drift
  339.      */

  340.     public double totalTemporaryDrift()
  341.     {
  342.         int iNumInterval = _lsSI.size();

  343.         double dblTotalTemporaryDrift = 0.;

  344.         for (int i = 0; i < iNumInterval; ++i)
  345.             dblTotalTemporaryDrift = dblTotalTemporaryDrift + _lsSI.get (i).temporaryImpactDrift();

  346.         return dblTotalTemporaryDrift;
  347.     }

  348.     /**
  349.      * Generate the Array of Incremental Temporary Cost Wander
  350.      *
  351.      * @return The Array of Incremental Temporary Cost Wander
  352.      */

  353.     public double[] incrementalTemporaryWander()
  354.     {
  355.         int iNumInterval = _lsSI.size();

  356.         double[] adblIncrementalTemporaryWander = new double[iNumInterval];

  357.         for (int i = 0; i < iNumInterval; ++i)
  358.             adblIncrementalTemporaryWander[i] = _lsSI.get (i).temporaryImpactWander();

  359.         return adblIncrementalTemporaryWander;
  360.     }

  361.     /**
  362.      * Generate the Array of Cumulative Temporary Cost Wander
  363.      *
  364.      * @return The Array of Cumulative Temporary Cost Wander
  365.      */

  366.     public double[] cumulativeTemporaryWander()
  367.     {
  368.         int iNumInterval = _lsSI.size();

  369.         double[] adblCumulativeTemporaryWander = new double[iNumInterval];

  370.         for (int i = 0; i < iNumInterval; ++i)
  371.             adblCumulativeTemporaryWander[i] = 0 == i ? _lsSI.get (i).temporaryImpactWander() : _lsSI.get
  372.                 (i).temporaryImpactWander() + adblCumulativeTemporaryWander[i - 1];

  373.         return adblCumulativeTemporaryWander;
  374.     }

  375.     /**
  376.      * Generate the Total Temporary Cost Wander
  377.      *
  378.      * @return The Total Temporary Cost Wander
  379.      */

  380.     public double totalTemporaryWander()
  381.     {
  382.         int iNumInterval = _lsSI.size();

  383.         double dblTotalTemporaryWander = 0.;

  384.         for (int i = 0; i < iNumInterval; ++i)
  385.             dblTotalTemporaryWander = dblTotalTemporaryWander + _lsSI.get (i).temporaryImpactWander();

  386.         return dblTotalTemporaryWander;
  387.     }
  388. }