OptimalSerialCorrelationImpact.java

  1. package org.drip.sample.almgrenchriss;

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

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

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

  88. /**
  89.  * <i>OptimalSerialCorrelationImpact</i> estimates the Optimal Adjustment to the Optimal Trading Trajectory
  90.  * attributable to Serial Correlation in accordance with the Specification of Almgren and Chriss (2000) for
  91.  * the given Risk Aversion Parameter without the Asset Drift. The References are:
  92.  *
  93.  * <br><br>
  94.  *  <ul>
  95.  *      <li>
  96.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  97.  *      </li>
  98.  *      <li>
  99.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  100.  *              Risk</i> <b>3 (2)</b> 5-39
  101.  *      </li>
  102.  *      <li>
  103.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  104.  *              Markets</i> <b>1</b> 1-50
  105.  *      </li>
  106.  *      <li>
  107.  *          Chan, L. K. C., and J. Lakonishak (1995): The Behavior of Stock Prices around Institutional
  108.  *              Trades <i>Journal of Finance</i> <b>50</b> 1147-1174
  109.  *      </li>
  110.  *      <li>
  111.  *          Keim, D. B., and A. Madhavan (1997): Transaction Costs and Investment Style: An Inter-exchange
  112.  *              Analysis of Institutional Equity Trades <i>Journal of Financial Economics</i> <b>46</b>
  113.  *              265-292
  114.  *      </li>
  115.  *  </ul>
  116.  *
  117.  * <br><br>
  118.  *  <ul>
  119.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  120.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  121.  *      <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>
  122.  *      <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>
  123.  *  </ul>
  124.  * <br><br>
  125.  *
  126.  * @author Lakshmi Krishnamurthy
  127.  */

  128. public class OptimalSerialCorrelationImpact {

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

  137.         double dblS0 = 50.;
  138.         double dblX = 1000000.;
  139.         double dblT = 5.;
  140.         int iN = 5;
  141.         double dblAnnualVolatility = 0.30;
  142.         double dblAnnualReturns = 0.10;
  143.         double dblBidAsk = 0.125;
  144.         double dblDailyVolume = 5.e06;
  145.         double dblDailyVolumePermanentImpact = 0.1;
  146.         double dblDailyVolumeTemporaryImpact = 0.01;
  147.         double dblLambdaU = 1.e-06;
  148.         double dblSerialCorrelation = 0.1;

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

  155.         double dblAlpha = apds.drift();

  156.         double dblSigma = apds.epochVolatility();

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

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

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

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

  177.         DiscreteAlmgrenChriss dac = DiscreteAlmgrenChriss.Standard (
  178.             dblX,
  179.             dblT,
  180.             iN,
  181.             lpep,
  182.             dblLambdaU
  183.         );

  184.         AlmgrenChrissDiscrete acd = (AlmgrenChrissDiscrete) dac.generate();

  185.         double[] adblExecutionTimeNode = acd.executionTimeNode();

  186.         double[] adblTradeList = acd.tradeList();

  187.         double[] adblHoldings = acd.holdings();

  188.         TrajectoryShortfallEstimator tse = new TrajectoryShortfallEstimator (acd);

  189.         OptimalSerialCorrelationAdjustment[] aOSCA = tse.serialCorrelationAdjustment (lpep);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  204.         System.out.println ("\t| Static Holdings 11,000 Shares : " + dblLambdaU);

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

  206.         System.out.println (
  207.             "\t| Daily Volatility              : " +
  208.             FormatUtil.FormatDouble (dblSigma, 1, 4, 1.)
  209.         );

  210.         System.out.println (
  211.             "\t| Daily Returns                 : " +
  212.             FormatUtil.FormatDouble (dblAlpha, 1, 4, 1.)
  213.         );

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

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

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

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

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

  219.         System.out.println ("\t|            AC2000 Optimal Trajectory            ||");

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

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

  222.         System.out.println ("\t|      Time Node                                  ||");

  223.         System.out.println ("\t|      Holdings                                   ||");

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

  225.         System.out.println ("\t|      Holdings Serial Correlation Adjustment     ||");

  226.         System.out.println ("\t|      Trade Amount Serial Correlation Adjustment ||");

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

  228.         for (int i = 0; i <= iN; ++i) {
  229.             if (i == 0)
  230.                 System.out.println (
  231.                     "\t|" + FormatUtil.FormatDouble (adblExecutionTimeNode[i], 1, 0, 1.) + " => " +
  232.                     FormatUtil.FormatDouble (adblHoldings[i], 7, 1, 1.) + " | " +
  233.                     FormatUtil.FormatDouble (0., 6, 1, 1.) + " | " +
  234.                     FormatUtil.FormatDouble (aOSCA[i].holdingsShift(), 5, 1, 1.) + " | " +
  235.                     FormatUtil.FormatDouble (aOSCA[i].gain(), 3, 1, 1.) + " ||"
  236.                 );
  237.             else
  238.                 System.out.println (
  239.                     "\t|" + FormatUtil.FormatDouble (adblExecutionTimeNode[i], 1, 0, 1.) + " => " +
  240.                     FormatUtil.FormatDouble (adblHoldings[i], 7, 1, 1.) + " | " +
  241.                     FormatUtil.FormatDouble (adblTradeList[i - 1], 6, 1, 1.) + " | " +
  242.                     FormatUtil.FormatDouble (aOSCA[i].holdingsShift(), 5, 1, 1.) + " | " +
  243.                     FormatUtil.FormatDouble (aOSCA[i].gain(), 3, 1, 1.) + " ||"
  244.                 );
  245.         }

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

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