OptimalTrajectoryDRI.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.execution.strategy.DiscreteTradingTrajectory;
  8. import org.drip.function.definition.R1ToR1;
  9. import org.drip.numerical.common.FormatUtil;
  10. import org.drip.service.env.EnvManager;

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

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

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

  124. public class OptimalTrajectoryDRI {

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

  133.         String strAssetName = "DRI";
  134.         double dblAverageDailyVolume = 1929000.;
  135.         double dblSharesOutstanding = 168000000.;
  136.         double dblDailyVolatility = 2.26;

  137.         double dblTradeSize = 192900.;
  138.         double dblTradeTime = 1.;
  139.         int iNumInterval = 20;

  140.         double dblRiskAversion = 1.e-02;

  141.         AssetFlowSettings afs = new AssetFlowSettings (
  142.             strAssetName,
  143.             dblAverageDailyVolume,
  144.             dblSharesOutstanding,
  145.             dblDailyVolatility
  146.         );

  147.         LinearPermanentExpectationParameters lpep = new DynamicsParameters (afs).almgren2003();

  148.         ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  149.             dblTradeSize,
  150.             dblTradeTime,
  151.             lpep,
  152.             dblRiskAversion
  153.         );

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

  155.         R1ToR1 r1ToR1Holdings = pic.holdings();

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

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

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

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

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

  167.         System.out.println();

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

  169.         System.out.println ("\t| DRI ATHL 2005 Optimal Trajectory  ||");

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

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

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

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

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

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

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

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

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

  186.         System.out.println();

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

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

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

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

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

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

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

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

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