ConstantLiquidityVolatility.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.ContinuousConstantTradingEnhanced;
  5. import org.drip.execution.optimum.EfficientTradingTrajectoryContinuous;
  6. import org.drip.execution.profiletime.UniformParticipationRateLinear;
  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>ConstantLiquidityVolatility</i> demonstrates the Dependence of the Optimal Trading Trajectory as a
  87.  * Function of Constant Trading Enhanced Volatilities. The References are:
  88.  *
  89.  * <br><br>
  90.  *  <ul>
  91.  *      <li>
  92.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  93.  *      </li>
  94.  *
  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.  *
  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.  *
  105.  *      <li>
  106.  *          Almgren, R., and N. Chriss (2003): Bidding Principles <i>Risk</i> 97-102
  107.  *      </li>
  108.  *
  109.  *      <li>
  110.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  111.  *              Markets</i> <b>1</b> 1-50
  112.  *      </li>
  113.  *  </ul>
  114.  *
  115.  * <br><br>
  116.  *  <ul>
  117.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  118.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  119.  *      <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>
  120.  *      <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>
  121.  *  </ul>
  122.  * <br><br>
  123.  *
  124.  * @author Lakshmi Krishnamurthy
  125.  */

  126. public class ConstantLiquidityVolatility {

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

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

  147.         ContinuousConstantTradingEnhanced ccte = ContinuousConstantTradingEnhanced.Standard (
  148.             dblX,
  149.             dblT,
  150.             apep,
  151.             dblLambda
  152.         );

  153.         EfficientTradingTrajectoryContinuous ettc = (EfficientTradingTrajectoryContinuous) ccte.generate();

  154.         R1ToR1 r1ToR1Holdings = ettc.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] = dblT * i / iNumInterval;

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

  161.         String strDump = "\t|" + FormatUtil.FormatDouble (dblAlpha, 1, 1, 1.) + " =>";

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

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

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

  166.         strDump = strDump + FormatUtil.FormatDouble (ettc.characteristicTime(), 1, 3, 1.) + " ||";

  167.         System.out.println (strDump);
  168.     }

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

  177.         double dblT = 5.;
  178.         int iNumInterval = 10;

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

  202.         System.out.println();

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

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

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

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

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

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

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

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

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

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

  213.         String strTimeNode = "\t|        ";

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

  216.         System.out.println (strTimeNode);

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

  218.         for (double dblAlpha : adblAlpha)
  219.             AlphaRun (
  220.                 dblAlpha,
  221.                 dblT,
  222.                 iNumInterval
  223.             );

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

  225.         EnvManager.TerminateEnv();
  226.     }
  227. }