OptimalTrajectoryVolatilityAnalysis.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>OptimalTrajectoryVolatilityAnalysis</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 OptimalTrajectoryVolatilityAnalysis {

  124.     private static final void VolatilitySensitivity (
  125.         final String strAssetName,
  126.         final double dblAverageDailyVolume,
  127.         final double dblDailyVolatility,
  128.         final double dblSharesOutstanding,
  129.         final double dblTradeSize)
  130.         throws Exception
  131.     {
  132.         double dblTradeTime = 0.5;
  133.         int iNumInterval = 10;

  134.         double dblRiskAversion = 1.e-02;

  135.         LinearPermanentExpectationParameters lpep = new DynamicsParameters (
  136.             new AssetFlowSettings (
  137.                 strAssetName,
  138.                 dblAverageDailyVolume,
  139.                 dblSharesOutstanding,
  140.                 dblDailyVolatility
  141.             )
  142.         ).almgren2003();

  143.         ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  144.             dblTradeSize,
  145.             dblTradeTime,
  146.             lpep,
  147.             dblRiskAversion
  148.         );

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

  150.         R1ToR1 r1ToR1Holdings = pic.holdings();

  151.         double[] adblHoldings = new double[iNumInterval];
  152.         double[] adblExecutionTime = new double[iNumInterval];

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

  155.             adblHoldings[i - 1] = r1ToR1Holdings.evaluate (adblExecutionTime[i - 1]);
  156.         }

  157.         String strDump = "";

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

  160.         System.out.println (
  161.             "\t| " +
  162.             FormatUtil.FormatDouble (dblDailyVolatility, 1, 2, 1.) + "% | " + strDump +
  163.             FormatUtil.FormatDouble (pic.characteristicTime(), 1, 3, 1.) + " ||"
  164.         );
  165.     }

  166.     public static final void main (
  167.         final String[] astrArgs)
  168.         throws Exception
  169.     {
  170.         EnvManager.InitEnv (
  171.             "",
  172.             true
  173.         );

  174.         String strAssetName = "IBM";
  175.         double dblAverageDailyVolume = 6561000.;
  176.         double dblSharesOutstanding = 1728000000.;
  177.         double dblTradeSize = 656100.;

  178.         double[] adblDailyVolatility = new double[] {
  179.             0.75,
  180.             1.00,
  181.             1.25,
  182.             1.50,
  183.             1.75,
  184.             2.00,
  185.             2.25,
  186.             2.50,
  187.             2.75,
  188.             3.00
  189.         };

  190.         System.out.println();

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

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

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

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

  195.         System.out.println ("\t|                                                        Daily Volatility                                                        ||");

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

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

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

  199.         for (double dblDailyVolatility : adblDailyVolatility)
  200.             VolatilitySensitivity (
  201.                 strAssetName,
  202.                 dblAverageDailyVolume,
  203.                 dblDailyVolatility,
  204.                 dblSharesOutstanding,
  205.                 dblTradeSize
  206.             );

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

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