EquityMarketImpactIBM.java

  1. package org.drip.sample.athl;

  2. import org.drip.execution.athl.*;
  3. import org.drip.execution.parameters.AssetFlowSettings;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;

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

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

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

  119. public class EquityMarketImpactIBM {

  120.     private static final void TemporaryImpactReconciler (
  121.         final TemporaryImpact ti,
  122.         final double dblTradeSize,
  123.         final double dblTime,
  124.         final double dblNormalizedTemporaryImpactReconciler,
  125.         final double dblDenormalizedTemporaryImpactReconciler,
  126.         final double dblDenormalizedPermanentImpact,
  127.         final double dblRealizedImpactReconciler)
  128.         throws Exception
  129.     {
  130.         double dblNormalizedTemporaryImpact = ti.evaluate (
  131.             dblTradeSize / (ti.assetFlowParameters().averageDailyVolume() * dblTime)
  132.         );

  133.         double dblDenormalizedTemporaryImpact = ti.evaluate (
  134.             dblTradeSize,
  135.             dblTime
  136.         );

  137.         System.out.println (
  138.             "\t| " +
  139.             FormatUtil.FormatDouble (dblTime, 1, 1, 1.) + " | " +
  140.             FormatUtil.FormatDouble (dblNormalizedTemporaryImpact, 1, 3, 1.) + " | " +
  141.             FormatUtil.FormatDouble (dblNormalizedTemporaryImpactReconciler, 1, 3, 1.) + " || " +
  142.             FormatUtil.FormatDouble (dblDenormalizedTemporaryImpact, 2, 0, 100.) + " | " +
  143.             FormatUtil.FormatDouble (dblDenormalizedTemporaryImpactReconciler, 2, 0, 1.) + " ||" +
  144.             FormatUtil.FormatDouble (dblDenormalizedPermanentImpact + dblDenormalizedTemporaryImpact, 2, 0, 100.) + " | " +
  145.             FormatUtil.FormatDouble (dblRealizedImpactReconciler, 2, 0, 1.) + " ||"
  146.         );
  147.     }

  148.     public static final void main (
  149.         final String[] astrArgs)
  150.         throws Exception
  151.     {
  152.         EnvManager.InitEnv (
  153.             "",
  154.             true
  155.         );

  156.         String strAssetName = "IBM";
  157.         double dblAverageDailyVolume = 6561000.;
  158.         double dblSharesOutstanding = 1728000000.;
  159.         double dblDailyVolatility = 1.57;
  160.         double dblTradeSize = 656100.;
  161.         double dblTradeTime = 1.;

  162.         double dblInverseTurnoverReconciler = 263.374;
  163.         double dblNormalizedTradeSizeReconciler = 0.1;
  164.         double dblNormalizedPermanentImpactReconciler = 0.126;
  165.         double dblDenormalizedPermanentImpactReconciler = 19.86;

  166.         double[] adblTime = new double[] {
  167.             0.1,
  168.             0.2,
  169.             0.5
  170.         };

  171.         double[] adblNormalizedTemporaryImpactReconciler = new double[] {
  172.             0.142,
  173.             0.094,
  174.             0.054
  175.         };

  176.         double[] adblDenormalizedTemporaryImpactReconciler = new double[] {
  177.             22,
  178.             15,
  179.             8
  180.         };

  181.         double[] adblRealizedImpactReconciler = new double[] {
  182.             32,
  183.             25,
  184.             18
  185.         };

  186.         AssetFlowSettings afs = new AssetFlowSettings (
  187.             strAssetName,
  188.             dblAverageDailyVolume,
  189.             dblSharesOutstanding,
  190.             dblDailyVolatility
  191.         );

  192.         TemporaryImpact ti = new TemporaryImpact (afs);

  193.         PermanentImpactNoArbitrage pina = new PermanentImpactNoArbitrage (afs);

  194.         double dblDenormalizedPermanentImpact = pina.evaluate (
  195.             dblTradeSize,
  196.             dblTradeTime
  197.         );

  198.         double dblNormalizedPermanentImpact = pina.evaluate (dblTradeSize / (afs.averageDailyVolume() * dblTradeTime));

  199.         System.out.println();

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

  201.         System.out.println ("\t|  Asset                   =>  " + strAssetName);

  202.         System.out.println ("\t|  Average Daily Volume    => " + FormatUtil.FormatDouble (dblAverageDailyVolume, 1, 0, 1.));

  203.         System.out.println ("\t|  Shares Outstanding      => " + FormatUtil.FormatDouble (dblSharesOutstanding, 1, 0, 1.));

  204.         System.out.println ("\t|  Daily Volatility        => " + FormatUtil.FormatDouble (dblDailyVolatility, 1, 2, 1.) + "%");

  205.         System.out.println ("\t|  Trade Size              => " + FormatUtil.FormatDouble (dblTradeSize, 1, 0, 1.));

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

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

  208.         System.out.println ("\t|  ALMGREN, THUM, HAUPTMANN, and LI (2005) PERM. RECON   ||");

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

  210.         System.out.println (
  211.             "\t|  Inverse Turn-over              => " +
  212.             FormatUtil.FormatDouble (afs.inverseTurnover(), 3, 3, 1.) + " | " +
  213.             FormatUtil.FormatDouble (dblInverseTurnoverReconciler, 3, 3, 1.) + " ||"
  214.         );

  215.         System.out.println (
  216.             "\t|  Normalized Trade Size          => " +
  217.             FormatUtil.FormatDouble (afs.normalizeTradeSize (dblTradeSize, dblTradeTime), 3, 3, 1.) + " | " +
  218.             FormatUtil.FormatDouble (dblNormalizedTradeSizeReconciler, 3, 3, 1.) + " ||"
  219.         );

  220.         System.out.println (
  221.             "\t|  Normalized Permanent Impact    => " +
  222.             FormatUtil.FormatDouble (2. * dblNormalizedPermanentImpact, 3, 3, 1.) + " | " +
  223.             FormatUtil.FormatDouble (dblNormalizedPermanentImpactReconciler, 3, 3, 1.) + " ||"
  224.         );

  225.         System.out.println (
  226.             "\t|  De-normalized Permanent Impact => " +
  227.             FormatUtil.FormatDouble (2. * dblDenormalizedPermanentImpact, 3, 3, 100.) + " | " +
  228.             FormatUtil.FormatDouble (dblDenormalizedPermanentImpactReconciler, 3, 3, 1.) + " ||"
  229.         );

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

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

  232.         System.out.println ("\t|    TEMPORARY IMPACT PARAMETERS RECONCILIATION   ||");

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

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

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

  236.         System.out.println ("\t|                - Normalized K (Computed)        ||");

  237.         System.out.println ("\t|                - Normalized K (Reconciler)      ||");

  238.         System.out.println ("\t|                - De-normalized K (Computed)     ||");

  239.         System.out.println ("\t|                - De-normalized K (Reconciler)   ||");

  240.         System.out.println ("\t|                - De-normalized J (Computed)     ||");

  241.         System.out.println ("\t|                - De-normalized J (Reconciler)   ||");

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

  243.         for (int i = 0; i < adblTime.length; ++i)
  244.             TemporaryImpactReconciler (
  245.                 ti,
  246.                 dblTradeSize,
  247.                 adblTime[i],
  248.                 adblNormalizedTemporaryImpactReconciler[i],
  249.                 adblDenormalizedTemporaryImpactReconciler[i],
  250.                 dblDenormalizedPermanentImpact,
  251.                 adblRealizedImpactReconciler[i]
  252.             );

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

  254.         EnvManager.TerminateEnv();
  255.     }
  256. }