HighUrgencyTrajectoryComparison.java

  1. package org.drip.sample.almgren2009;

  2. import org.drip.execution.dynamics.*;
  3. import org.drip.execution.impact.ParticipationRateLinear;
  4. import org.drip.execution.nonadaptive.*;
  5. import org.drip.execution.optimum.EfficientTradingTrajectoryContinuous;
  6. import org.drip.execution.parameters.*;
  7. import org.drip.execution.profiletime.UniformParticipationRateLinear;
  8. import org.drip.function.definition.R1ToR1;
  9. import org.drip.function.r1tor1.FlatUnivariate;
  10. import org.drip.numerical.common.FormatUtil;
  11. import org.drip.service.env.EnvManager;

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

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

  87. /**
  88.  * <i>HighUrgencyTrajectoryComparison</i> compares the Static Continuous Trading Trajectory generated by the
  89.  * Almgren and Chriss (2012) Scheme against the High Urgency Asymptote Version. The References are:
  90.  *
  91.  * <br><br>
  92.  *  <ul>
  93.  *      <li>
  94.  *          Almgren, R. F., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  95.  *              Risk</i> <b>3 (2)</b> 5-39
  96.  *      </li>
  97.  *      <li>
  98.  *          Almgren, R. F. (2009): Optimal Trading in a Dynamic Market
  99.  *              https://www.math.nyu.edu/financial_mathematics/content/02_financial/2009-2.pdf
  100.  *      </li>
  101.  *      <li>
  102.  *          Almgren, R. F. (2012): Optimal Trading with Stochastic Liquidity and Volatility <i>SIAM Journal
  103.  *              of Financial Mathematics</i> <b>3 (1)</b> 163-181
  104.  *      </li>
  105.  *      <li>
  106.  *          Geman, H., D. B. Madan, and M. Yor (2001): Time Changes for Levy Processes <i>Mathematical
  107.  *              Finance</i> <b>11 (1)</b> 79-96
  108.  *      </li>
  109.  *      <li>
  110.  *          Walia, N. (2006): Optimal Trading: Dynamic Stock Liquidation Strategies <b>Princeton
  111.  *              University</b>
  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/almgren2009/README.md">Almgren (2009) Optimal Adaptive HJB</a></li>
  121.  *  </ul>
  122.  * <br><br>
  123.  *
  124.  * @author Lakshmi Krishnamurthy
  125.  */

  126. public class HighUrgencyTrajectoryComparison {

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

  135.         double dblS0 = 50.;
  136.         double dblX = 1000000.;
  137.         double dblT = 5.;
  138.         double dblAnnualVolatility = 1.00;
  139.         double dblAnnualReturns = 0.10;
  140.         double dblBidAsk = 0.125;
  141.         double dblDailyVolume = 5.e06;
  142.         double dblDailyVolumePermanentImpact = 0.1;
  143.         double dblDailyVolumeTemporaryImpact = 0.01;
  144.         double dblLambdaU = 1.5e-06;

  145.         int iN = 20;

  146.         double dblTime = 0.;
  147.         double dblTimeWidth = dblT / iN;

  148.         ArithmeticPriceDynamicsSettings apds = ArithmeticPriceDynamicsSettings.FromAnnualReturnsSettings (
  149.             dblAnnualReturns,
  150.             dblAnnualVolatility,
  151.             0.,
  152.             dblS0
  153.         );

  154.         double dblSigma = apds.epochVolatility();

  155.         PriceMarketImpactLinear pmil = new PriceMarketImpactLinear (
  156.             new AssetTransactionSettings (
  157.                 dblS0,
  158.                 dblDailyVolume,
  159.                 dblBidAsk
  160.             ),
  161.             dblDailyVolumePermanentImpact,
  162.             dblDailyVolumeTemporaryImpact
  163.         );

  164.         ParticipationRateLinear prlPermanent = (ParticipationRateLinear) pmil.permanentTransactionFunction();

  165.         ParticipationRateLinear prlTemporary = (ParticipationRateLinear) pmil.temporaryTransactionFunction();

  166.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.LinearExpectation (
  167.             new ArithmeticPriceDynamicsSettings (
  168.                 0.,
  169.                 new FlatUnivariate (dblSigma),
  170.                 0.
  171.             ),
  172.             new UniformParticipationRateLinear (prlPermanent),
  173.             new UniformParticipationRateLinear (prlTemporary)
  174.         );

  175.         ContinuousAlmgrenChriss cac = ContinuousAlmgrenChriss.Standard (
  176.             dblX,
  177.             dblT,
  178.             lpep,
  179.             dblLambdaU
  180.         );

  181.         EfficientTradingTrajectoryContinuous ettcA2012S = (EfficientTradingTrajectoryContinuous) cac.generate();

  182.         R1ToR1 r1ToR1HoldingsA2012S = ettcA2012S.holdings();

  183.         R1ToR1 r1ToR1TradeRateA2012S = ettcA2012S.tradeRate();

  184.         R1ToR1 r1ToR1TransactionCostA2012S = ettcA2012S.transactionCostExpectationFunction();

  185.         ContinuousHighUrgencyAsymptote huas = ContinuousHighUrgencyAsymptote.Standard (
  186.             dblX,
  187.             dblT,
  188.             lpep,
  189.             dblLambdaU
  190.         );

  191.         EfficientTradingTrajectoryContinuous ettcHUAS = (EfficientTradingTrajectoryContinuous) huas.generate();

  192.         R1ToR1 r1ToR1HoldingsHUAS = ettcHUAS.holdings();

  193.         R1ToR1 r1ToR1TradeRateHUAS = ettcHUAS.tradeRate();

  194.         R1ToR1 r1ToR1TransactionCostHUAS = ettcHUAS.transactionCostExpectationFunction();

  195.         System.out.println ();

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

  197.         System.out.println ("\t|  HIGH URGENCY vs. ALMGREN 2012 STATIC TRAJECTORY COMPARISON ||");

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

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

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

  201.         System.out.println ("\t|            - Almgren 2012 Holdings                          ||");

  202.         System.out.println ("\t|            - Almgren 2012 Trade Rate                        ||");

  203.         System.out.println ("\t|            - Almgren 2012 Transaction Cost                  ||");

  204.         System.out.println ("\t|            - High Urgency Asymptote Holdings                ||");

  205.         System.out.println ("\t|            - High Urgency Asymptote Trade Rate              ||");

  206.         System.out.println ("\t|            - High Urgency Asymptote Transaction Cost        ||");

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

  208.         for (int i = 1; i <= iN; ++i) {
  209.             dblTime = dblTime + dblTimeWidth;

  210.             System.out.println (
  211.                 "\t|" +
  212.                 FormatUtil.FormatDouble (dblTime, 1, 2, 1.) + " => " +
  213.                 FormatUtil.FormatDouble (r1ToR1HoldingsA2012S.evaluate (dblTime) / dblX, 1, 3, 1.) + " | " +
  214.                 FormatUtil.FormatDouble (r1ToR1TradeRateA2012S.evaluate (dblTime) * dblTimeWidth / dblX, 1, 3, 1.) + " | " +
  215.                 FormatUtil.FormatDouble (r1ToR1TransactionCostA2012S.evaluate (dblTime) / dblX, 1, 3, 1.) + " | " +
  216.                 FormatUtil.FormatDouble (r1ToR1HoldingsHUAS.evaluate (dblTime) / dblX, 1, 3, 1.) + " | " +
  217.                 FormatUtil.FormatDouble (r1ToR1TradeRateHUAS.evaluate (dblTime) * dblTimeWidth / dblX, 1, 3, 1.) + " | " +
  218.                 FormatUtil.FormatDouble (r1ToR1TransactionCostHUAS.evaluate (dblTime) / dblX, 1, 3, 1.) + " ||"
  219.             );
  220.         }

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

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