LinearLiquidityVolatility.java

  1. package org.drip.sample.almgren2003;

  2. import org.drip.execution.dynamics.*;
  3. import org.drip.execution.impact.ParticipationRateLinear;
  4. import org.drip.execution.nonadaptive.DiscreteLinearTradingEnhanced;
  5. import org.drip.execution.optimum.TradingEnhancedDiscrete;
  6. import org.drip.execution.profiletime.UniformParticipationRateLinear;
  7. import org.drip.numerical.common.FormatUtil;
  8. import org.drip.service.env.EnvManager;

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

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

  84. /**
  85.  * <i>LinearLiquidityVolatility</i> demonstrates the Dependence of the Optimal Trading Trajectory as a
  86.  * Function of Linear Trading Enhanced Volatilities. The References are:
  87.  *
  88.  * <br><br>
  89.  *  <ul>
  90.  *      <li>
  91.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  92.  *      </li>
  93.  *
  94.  *      <li>
  95.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  96.  *              Risk</i> <b>3 (2)</b> 5-39
  97.  *      </li>
  98.  *
  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.  *
  104.  *      <li>
  105.  *          Almgren, R., and N. Chriss (2003): Bidding Principles <i>Risk</i> 97-102
  106.  *      </li>
  107.  *
  108.  *      <li>
  109.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  110.  *              Markets</i> <b>1</b> 1-50
  111.  *      </li>
  112.  *  </ul>
  113.  *
  114.  * <br><br>
  115.  *  <ul>
  116.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  117.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  118.  *      <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>
  119.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/almgren2003/README.md">Almgren (2003) Power Law Liquidity</a></li>
  120.  *  </ul>
  121.  * <br><br>
  122.  *
  123.  * @author Lakshmi Krishnamurthy
  124.  */

  125. public class LinearLiquidityVolatility {

  126.     private static final void BetaRun (
  127.         final double dblBeta,
  128.         final double dblT,
  129.         final int iNumInterval)
  130.         throws Exception
  131.     {
  132.         double dblEta = 5.e-06;
  133.         double dblSigma = 1.;
  134.         double dblLambda = 1.e-05;
  135.         double dblX = 100000.;

  136.         ArithmeticPriceEvolutionParameters apep = ArithmeticPriceEvolutionParametersBuilder.TradingEnhancedVolatility (
  137.             dblSigma,
  138.             new UniformParticipationRateLinear (ParticipationRateLinear.SlopeOnly (dblEta)),
  139.             new UniformParticipationRateLinear (
  140.                 new ParticipationRateLinear (
  141.                     0.,
  142.                     dblBeta
  143.                 )
  144.             )
  145.         );

  146.         DiscreteLinearTradingEnhanced dlte = DiscreteLinearTradingEnhanced.Standard (
  147.             dblX,
  148.             dblT,
  149.             iNumInterval,
  150.             apep,
  151.             dblLambda
  152.         );

  153.         TradingEnhancedDiscrete ted = (TradingEnhancedDiscrete) dlte.generate();

  154.         double[] adblExecutionTimeNode = ted.executionTimeNode();

  155.         double[] adblHoldings = ted.holdings();

  156.         String strDump = "\t|" + FormatUtil.FormatDouble (dblBeta, 1, 1, 1.e+06) + " =>";

  157.         for (int i = 0; i < adblExecutionTimeNode.length; ++i)
  158.             strDump = strDump + FormatUtil.FormatDouble (adblHoldings[i] / dblX, 2, 1, 100.) + "% ";

  159.         strDump = strDump + FormatUtil.FormatDouble (ted.transactionCostExpectation(), 5, 0, 1.) + " | ";

  160.         strDump = strDump + FormatUtil.FormatDouble (ted.transactionCostVariance(), 5, 0, 1.e-06) + " | ";

  161.         strDump = strDump + FormatUtil.FormatDouble (ted.characteristicTime(), 1, 3, 1.) + " | ";

  162.         strDump = strDump + FormatUtil.FormatDouble (ted.characteristicSize(), 6, 0, 1.) + " ||";

  163.         System.out.println (strDump);
  164.     }

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

  173.         double dblT = 5.;
  174.         int iNumInterval = 10;

  175.         double[] adblBeta = new double[] {
  176.             0.1,
  177.             0.2,
  178.             0.3,
  179.             0.4,
  180.             0.5,
  181.             0.6,
  182.             0.7,
  183.             0.8,
  184.             0.9,
  185.             1.0,
  186.             1.1,
  187.             1.2,
  188.             1.3,
  189.             1.4,
  190.             1.5,
  191.             1.6,
  192.             1.7,
  193.             1.8,
  194.             1.9,
  195.             2.0
  196.         };

  197.         System.out.println();

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

  199.         System.out.println ("\t|                        ALMGREN (2003) LINEAR TEMPORARY IMPACT VOLATILITY - OFFSET DEPENDENCE                           ||");

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

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

  202.         System.out.println ("\t|              Beta Level (X 10^06)                                                                                      ||");

  203.         System.out.println ("\t|              Outstanding Trajectory (%)                                                                                ||");

  204.         System.out.println ("\t|              Transaction Cost Expectation                                                                              ||");

  205.         System.out.println ("\t|              Transaction Cost Variance (X 10^-06)                                                                      ||");

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

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

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

  209.         String strTimeNode = "\t|        ";

  210.         for (int i = 0; i <= iNumInterval; ++i)
  211.             strTimeNode = strTimeNode + FormatUtil.FormatDouble (dblT * i / iNumInterval, 1, 2, 1.) + "  ";

  212.         System.out.println (strTimeNode);

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

  214.         for (double dblBeta : adblBeta)
  215.             BetaRun (
  216.                 dblBeta * 1.e-06,
  217.                 dblT,
  218.                 iNumInterval
  219.             );

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

  221.         EnvManager.TerminateEnv();
  222.     }
  223. }