OptimalTrajectoryTradeAnalysis.java

  1. package org.drip.sample.athl;

  2. import org.drip.execution.athl.DynamicsParameters;
  3. import org.drip.execution.dynamics.LinearPermanentExpectationParameters;
  4. import org.drip.execution.nonadaptive.ContinuousPowerImpact;
  5. import org.drip.execution.optimum.PowerImpactContinuous;
  6. import org.drip.execution.parameters.AssetFlowSettings;
  7. import org.drip.function.definition.R1ToR1;
  8. import org.drip.numerical.common.FormatUtil;
  9. import org.drip.service.env.EnvManager;

  10. /*
  11.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  12.  */

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

  85. /**
  86.  * <i>OptimalTrajectoryTradeAnalysis</i> analyzes the Impact of Input Parameters on the Trade Scheduling
  87.  * using the Equity Market Impact Functions determined empirically by Almgren, Thum, Hauptmann, and Li
  88.  * (2005), using the Parameterization of Almgren (2003) for IBM. The References are:
  89.  *  
  90.  * <br><br>
  91.  *  <ul>
  92.  *      <li>
  93.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  94.  *      </li>
  95.  *      <li>
  96.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  97.  *              Risk</i> <b>3 (2)</b> 5-39
  98.  *      </li>
  99.  *      <li>
  100.  *          Almgren, R. (2003): Optimal Execution with Nonlinear Impact Functions and Trading-Enhanced Risk
  101.  *              <i>Applied Mathematical Finance</i> <b>10 (1)</b> 1-18
  102.  *      </li>
  103.  *      <li>
  104.  *          Almgren, R., and N. Chriss (2003): Bidding Principles <i>Risk</i> 97-102
  105.  *      </li>
  106.  *      <li>
  107.  *          Almgren, R., C. Thum, E. Hauptmann, and H. Li (2005): Equity Market Impact <i>Risk</i> <b>18
  108.  *              (7)</b> 57-62
  109.  *      </li>
  110.  *  </ul>
  111.  *  
  112.  * <br><br>
  113.  *  <ul>
  114.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  115.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  116.  *      <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>
  117.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/athl/README.md">Almgren, Thum, Hauptmann, and Li (2005) Calibration</a></li>
  118.  *  </ul>
  119.  * <br><br>
  120.  *
  121.  * @author Lakshmi Krishnamurthy
  122.  */

  123. public class OptimalTrajectoryTradeAnalysis {

  124.     private static final void TradeSizeSensitivity (
  125.         final double dblADVRatio,
  126.         final double dblTradeSize,
  127.         final LinearPermanentExpectationParameters lpep)
  128.         throws Exception
  129.     {
  130.         double dblTradeTime = 0.5;
  131.         int iNumInterval = 10;

  132.         double dblRiskAversion = 1.e-02;

  133.         ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  134.             dblTradeSize,
  135.             dblTradeTime,
  136.             lpep,
  137.             dblRiskAversion
  138.         );

  139.         PowerImpactContinuous pic = (PowerImpactContinuous) cpi.generate();

  140.         R1ToR1 r1ToR1Holdings = pic.holdings();

  141.         double[] adblHoldings = new double[iNumInterval];
  142.         double[] adblExecutionTime = new double[iNumInterval];

  143.         for (int i = 1; i <= iNumInterval; ++i) {
  144.             adblExecutionTime[i - 1] = dblTradeTime * i / iNumInterval;

  145.             adblHoldings[i - 1] = r1ToR1Holdings.evaluate (adblExecutionTime[i - 1]);
  146.         }

  147.         String strDump = "";

  148.         for (int i = 0; i < adblHoldings.length; ++i)
  149.             strDump = strDump + FormatUtil.FormatDouble (adblHoldings[i] / dblTradeSize, 2, 2, 100.) + "% | ";

  150.         System.out.println (
  151.             "\t| " +
  152.             FormatUtil.FormatDouble (dblADVRatio, 2, 0, 100.) + "% | " + strDump +
  153.             FormatUtil.FormatDouble (pic.characteristicTime(), 1, 3, 1.) + " ||"
  154.         );
  155.     }

  156.     public static final void main (
  157.         final String[] astrArgs)
  158.         throws Exception
  159.     {
  160.         EnvManager.InitEnv (
  161.             "",
  162.             true
  163.         );

  164.         String strAssetName = "IBM";
  165.         double dblAverageDailyVolume = 6561000.;
  166.         double dblSharesOutstanding = 1728000000.;
  167.         double dblBaseDailyVolatility = 1.57;

  168.         double[] adblADVRatio = new double[] {
  169.             0.01,
  170.             0.02,
  171.             0.03,
  172.             0.04,
  173.             0.06,
  174.             0.08,
  175.             0.10,
  176.             0.15,
  177.             0.20,
  178.             0.25,
  179.             0.30
  180.         };

  181.         LinearPermanentExpectationParameters lpep = new DynamicsParameters (
  182.             new AssetFlowSettings (
  183.                 strAssetName,
  184.                 dblAverageDailyVolume,
  185.                 dblSharesOutstanding,
  186.                 dblBaseDailyVolatility
  187.             )
  188.         ).almgren2003();

  189.         System.out.println();

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

  191.         System.out.println ("\t|                                        Trade Size Dependence on the Execution Schedule                                       ||");

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

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

  194.         System.out.println ("\t|                                                        Trade Size as a Fraction of ADV                                       ||");

  195.         System.out.println ("\t|                                                        Execution Time Nodes                                                  ||");

  196.         System.out.println ("\t|                                                        Characteristic Time                                                   ||");

  197.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  198.         for (double dblADVRatio : adblADVRatio)
  199.             TradeSizeSensitivity (
  200.                 dblADVRatio,
  201.                 dblADVRatio * dblAverageDailyVolume,
  202.                 lpep
  203.             );

  204.         System.out.println ("\t|------------------------------------------------------------------------------------------------------------------------------||");

  205.         EnvManager.TerminateEnv();
  206.     }
  207. }