OptimalTrajectoryIBM.java

  1. package org.drip.sample.athl;

  2. import org.drip.execution.athl.DynamicsParameters;
  3. import org.drip.execution.nonadaptive.ContinuousPowerImpact;
  4. import org.drip.execution.optimum.PowerImpactContinuous;
  5. import org.drip.execution.parameters.AssetFlowSettings;
  6. import org.drip.execution.strategy.DiscreteTradingTrajectory;
  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>OptimalTrajectoryIBM</i> demonstrates the Trade Scheduling using the Equity Market Impact Functions
  87.  * determined empirically by Almgren, Thum, Hauptmann, and Li (2005), using the Parameterization of Almgren
  88.  * (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 OptimalTrajectoryIBM {

  124.     public static final void main (
  125.         final String[] astrArgs)
  126.         throws Exception
  127.     {
  128.         EnvManager.InitEnv (
  129.             "",
  130.             true
  131.         );

  132.         String strAssetName = "IBM";
  133.         double dblAverageDailyVolume = 6561000.;
  134.         double dblSharesOutstanding = 1728000000.;
  135.         double dblDailyVolatility = 1.57;

  136.         double dblTradeSize = 656100.;
  137.         double dblTradeTime = 1.;
  138.         int iNumInterval = 20;

  139.         double dblRiskAversion = 1.e-02;

  140.         ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  141.             dblTradeSize,
  142.             dblTradeTime,
  143.             new DynamicsParameters (
  144.                 new AssetFlowSettings (
  145.                     strAssetName,
  146.                     dblAverageDailyVolume,
  147.                     dblSharesOutstanding,
  148.                     dblDailyVolatility
  149.                 )
  150.             ).almgren2003(),
  151.             dblRiskAversion
  152.         );

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

  154.         R1ToR1 r1ToR1Holdings = pic.holdings();

  155.         double[] adblHoldings = new double[iNumInterval];
  156.         double[] adblExecutionTime = new double[iNumInterval];

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

  159.             adblHoldings[i - 1] = r1ToR1Holdings.evaluate (adblExecutionTime[i - 1]);
  160.         }

  161.         DiscreteTradingTrajectory dtt = DiscreteTradingTrajectory.Standard (
  162.             adblExecutionTime,
  163.             adblHoldings
  164.         );

  165.         double[] adblTradeList = dtt.tradeList();

  166.         System.out.println();

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

  168.         System.out.println ("\t| IBM ATHL 2005 Optimal Trajectory   ||");

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

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

  171.         System.out.println ("\t|             - Execution Time Node  ||");

  172.         System.out.println ("\t|             - Holdings Remaining   ||");

  173.         System.out.println ("\t|             - Trade List Amount    ||");

  174.         System.out.println ("\t|             - Holdings (%)         ||");

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

  176.         for (int i = 1; i < adblExecutionTime.length; ++i)
  177.             System.out.println (
  178.                 "\t| " +
  179.                 FormatUtil.FormatDouble (adblExecutionTime[i], 1, 2, 1.) + " | " +
  180.                 FormatUtil.FormatDouble (adblHoldings[i], 6, 0, 1.) + " | " +
  181.                 FormatUtil.FormatDouble (adblTradeList[i - 1], 6, 0, 1.) + " | " +
  182.                 FormatUtil.FormatDouble (adblHoldings[i] / dblTradeSize, 2, 1, 100.) + "% ||"
  183.             );

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

  185.         System.out.println();

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

  187.         System.out.println ("\t|       IBM ATHL 2005 Optimal Trajectory Transaction Cost Measures     ||");

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

  189.         System.out.println (
  190.             "\t| Transaction Cost Expectation ( X 10^-09)                  : " +
  191.             FormatUtil.FormatDouble (pic.transactionCostExpectation(), 4, 2, 1.e-09) + " ||"
  192.         );

  193.         System.out.println (
  194.             "\t| Transaction Cost Variance ( X 10^-09)                     : " +
  195.             FormatUtil.FormatDouble (pic.transactionCostVariance(), 4, 2, 1.e-09) + " ||"
  196.         );

  197.         System.out.println (
  198.             "\t| Characteristic Time                                       : " +
  199.             FormatUtil.FormatDouble (pic.characteristicTime(), 4, 2, 1.) + " ||"
  200.         );

  201.         System.out.println (
  202.             "\t| Efficient Frontier Hyperboloid Boundary Value ( X 10^-12) : " +
  203.             FormatUtil.FormatDouble (pic.hyperboloidBoundaryValue(), 4, 2, 1.e-12) + " ||"
  204.         );

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

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