TrajectoryComparisonNoDrift.java

  1. package org.drip.sample.almgrenchriss;

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

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

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

  86. /**
  87.  * <i>TrajectoryComparisonNoDrift</i> compares different Optimal Trading Trajectories computed in accordance
  88.  * with the Specification of Almgren and Chriss (2000) for a Set of Risk Aversion Parameters, excluding the
  89.  * Asset Drift. The References are:
  90.  *
  91.  * <br><br>
  92.  *  <ul>
  93.  *      <li>
  94.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  95.  *      </li>
  96.  *      <li>
  97.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  98.  *              Risk</i> <b>3 (2)</b> 5-39
  99.  *      </li>
  100.  *      <li>
  101.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  102.  *              Markets</i> <b>1</b> 1-50
  103.  *      </li>
  104.  *      <li>
  105.  *          Chan, L. K. C., and J. Lakonishak (1995): The Behavior of Stock Prices around Institutional
  106.  *              Trades <i>Journal of Finance</i> <b>50</b> 1147-1174
  107.  *      </li>
  108.  *      <li>
  109.  *          Keim, D. B., and A. Madhavan (1997): Transaction Costs and Investment Style: An Inter-exchange
  110.  *              Analysis of Institutional Equity Trades <i>Journal of Financial Economics</i> <b>46</b>
  111.  *              265-292
  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/almgrenchriss/README.md">Almgren Chriss Efficient Frontier Trajectories</a></li>
  121.  *  </ul>
  122.  * <br><br>
  123.  *
  124.  * @author Lakshmi Krishnamurthy
  125.  */

  126. public class TrajectoryComparisonNoDrift {

  127.     private static final void DisplayTrajectory (
  128.         final AlmgrenChrissDiscrete acd,
  129.         final double dblLambda,
  130.         final double dblX)
  131.         throws Exception
  132.     {
  133.         double[] adblHoldings = acd.holdings();

  134.         String strHoldings = "\t| [LAMBDA = " + FormatUtil.FormatDouble (dblLambda, 1, 3, dblX) + "]";

  135.         for (int i = 0; i < adblHoldings.length; ++i)
  136.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (adblHoldings[i] / dblX, 2, 3, 100.);

  137.         System.out.println (strHoldings + " ||");
  138.     }

  139.     public static void main (
  140.         final String[] astrArgs)
  141.         throws Exception
  142.     {
  143.         EnvManager.InitEnv (
  144.             "",
  145.             true
  146.         );

  147.         double dblS0 = 50.;
  148.         double dblX = 1000000.;
  149.         double dblT = 5.;
  150.         int iN = 5;
  151.         double dblAnnualVolatility = 0.30;
  152.         double dblAnnualReturns = 0.10;
  153.         double dblBidAsk = 0.125;
  154.         double dblDailyVolume = 5.e06;
  155.         double dblDailyVolumePermanentImpact = 0.1;
  156.         double dblDailyVolumeTemporaryImpact = 0.01;
  157.         double[] adblLambdaU = {
  158.             0.001e-06,
  159.             0.250e-06,
  160.             0.500e-06,
  161.             0.750e-06,
  162.             1.000e-06,
  163.             1.250e-06,
  164.             1.500e-06,
  165.             1.750e-06,
  166.             2.000e-06,
  167.             2.250e-06,
  168.             2.500e-06,
  169.             2.750e-06,
  170.             3.000e-06,
  171.             3.250e-06,
  172.             3.500e-06,
  173.             3.750e-06,
  174.             4.000e-06
  175.         };

  176.         ArithmeticPriceDynamicsSettings apds = ArithmeticPriceDynamicsSettings.FromAnnualReturnsSettings (
  177.             dblAnnualReturns,
  178.             dblAnnualVolatility,
  179.             0.,
  180.             dblS0
  181.         );

  182.         double dblAlpha = apds.drift();

  183.         double dblSigma = apds.epochVolatility();

  184.         PriceMarketImpactLinear pmil = new PriceMarketImpactLinear (
  185.             new AssetTransactionSettings (
  186.                 dblS0,
  187.                 dblDailyVolume,
  188.                 dblBidAsk
  189.             ),
  190.             dblDailyVolumePermanentImpact,
  191.             dblDailyVolumeTemporaryImpact
  192.         );

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

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

  195.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.LinearExpectation (
  196.             new ArithmeticPriceDynamicsSettings (
  197.                 dblAlpha,
  198.                 new FlatUnivariate (dblSigma),
  199.                 0.
  200.             ),
  201.             new UniformParticipationRateLinear (prlPermanent),
  202.             new UniformParticipationRateLinear (prlTemporary)
  203.         );

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

  205.         System.out.println ("\t| ALMGREN-CHRISS TRAJECTORY GENERATOR INPUTS  ||");

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

  207.         System.out.println ("\t| Initial Stock Price           : " + dblS0);

  208.         System.out.println ("\t| Initial Holdings              : " + dblX);

  209.         System.out.println ("\t| Liquidation Time              : " + dblT);

  210.         System.out.println ("\t| Number of Time Periods        : " + iN);

  211.         System.out.println ("\t| Annual Volatility             :" + FormatUtil.FormatDouble (dblAnnualVolatility, 1, 0, 100.) + "%");

  212.         System.out.println ("\t| Annual Growth                 :" + FormatUtil.FormatDouble (dblAnnualReturns, 1, 0, 100.) + "%");

  213.         System.out.println ("\t| Bid-Ask Spread                : " + dblBidAsk);

  214.         System.out.println ("\t| Daily Volume                  : " + dblDailyVolume);

  215.         System.out.println ("\t| Daily Volume Temporary Impact : " + dblDailyVolumeTemporaryImpact);

  216.         System.out.println ("\t| Daily Volume Permanent Impact : " + dblDailyVolumePermanentImpact);

  217.         System.out.println ("\t| Daily Volume 5 million Shares : " + prlPermanent.slope());

  218.         System.out.println ("\t|");

  219.         System.out.println (
  220.             "\t| Daily Volatility              : " +
  221.             FormatUtil.FormatDouble (dblSigma, 1, 4, 1.)
  222.         );

  223.         System.out.println (
  224.             "\t| Daily Returns                 : " +
  225.             FormatUtil.FormatDouble (dblAlpha, 1, 4, 1.)
  226.         );

  227.         System.out.println ("\t| Temporary Impact Fixed Offset :  " + prlTemporary.offset());

  228.         System.out.println ("\t| Eta                           :  " + prlTemporary.slope());

  229.         System.out.println ("\t| Gamma                         :  " + prlPermanent.slope());

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

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

  232.         System.out.println ("\t|             OPTIMAL TRADING TRAJECTORY FOR DIFFERENT RISK AVERSION             ||");

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

  234.         for (double dblLambdaU : adblLambdaU)
  235.             DisplayTrajectory (
  236.                 (AlmgrenChrissDiscrete) DiscreteAlmgrenChriss.Standard (
  237.                     dblX,
  238.                     dblT,
  239.                     iN,
  240.                     lpep,
  241.                     dblLambdaU
  242.                 ).generate(),
  243.                 dblLambdaU,
  244.                 dblX
  245.             );

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

  247.         EnvManager.TerminateEnv();
  248.     }
  249. }