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

  127. public class EfficientFrontierWithDrift {

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

  136.         double dblS0 = 50.;
  137.         double dblX = 1000000.;
  138.         double dblT = 5.;
  139.         int iN = 5;
  140.         double dblSigma = 0.95;
  141.         double dblAlpha = 0.02;
  142.         double dblEpsilon = 0.0625;
  143.         double dblGamma = 2.5e-07;
  144.         double dblEta = 2.5e-06;
  145.         double[] adblLambdaShortEndU = {
  146.             0.001e-06,
  147.             0.002e-06,
  148.             0.003e-06,
  149.             0.004e-06,
  150.             0.005e-06,
  151.             0.006e-06,
  152.             0.007e-06,
  153.             0.008e-06,
  154.             0.009e-06
  155.         };
  156.         double[] adblLambdaLongEndU = {
  157.             0.250e-06,
  158.             0.500e-06,
  159.             0.750e-06,
  160.             1.000e-06,
  161.             1.250e-06,
  162.             1.500e-06,
  163.             1.750e-06,
  164.             2.000e-06,
  165.             2.250e-06,
  166.             2.500e-06,
  167.             2.750e-06,
  168.             3.000e-06,
  169.             3.250e-06,
  170.             3.500e-06,
  171.             3.750e-06,
  172.             4.000e-06
  173.         };

  174.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.LinearExpectation (
  175.             new ArithmeticPriceDynamicsSettings (
  176.                 dblAlpha,
  177.                 new FlatUnivariate (dblSigma),
  178.                 0.
  179.             ),
  180.             new UniformParticipationRateLinear (
  181.                 new ParticipationRateLinear (
  182.                     0.,
  183.                     dblGamma
  184.                 )
  185.             ),
  186.             new UniformParticipationRateLinear (
  187.                 new ParticipationRateLinear (
  188.                     dblEpsilon,
  189.                     dblEta
  190.                 )
  191.             )
  192.         );

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

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

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

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

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

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

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

  200.         System.out.println ("\t| 30% Annual Volatility         : " + dblSigma);

  201.         System.out.println ("\t| 10% Annual Growth             : " + dblAlpha);

  202.         System.out.println ("\t| Bid-Ask Spread = 1/8          : " + dblEpsilon);

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

  204.         System.out.println ("\t| Impact at 1% of Market        : " + dblEta);

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

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

  207.         System.out.println ("\t|      SHORT END COST DISTRIBUTION, PENALTY, AND DECAY       ||");

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

  209.         System.out.println ("\t|       LAMBDA      |   MEAN  | SIGMA^2 | PENALTY | HALFLIFE ||");

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

  211.         for (double dblLambda : adblLambdaShortEndU) {
  212.             AlmgrenChrissDriftDiscrete acdd = (AlmgrenChrissDriftDiscrete) DiscreteAlmgrenChrissDrift.Standard (
  213.                 dblX,
  214.                 dblT,
  215.                 iN,
  216.                 lpep,
  217.                 dblLambda
  218.             ).generate();
  219.    
  220.             String strHoldings = "\t| [LAMBDA = " + FormatUtil.FormatDouble (dblLambda, 1, 3, dblX) + "]";

  221.             double dblTransactionCostExpectation = acdd.transactionCostExpectation();

  222.             double dblTransactionCostVariance = acdd.transactionCostVariance();

  223.             double dblTransactionCostPenalty = dblTransactionCostExpectation + dblLambda * dblTransactionCostVariance;

  224.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (dblTransactionCostExpectation / dblX, 1, 4, 1.);

  225.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (dblTransactionCostVariance / dblX / dblX, 1, 4, 1.);

  226.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (dblTransactionCostPenalty / dblX, 1, 4, 1.);

  227.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (acdd.halfLife(), 2, 2, 1.);

  228.             System.out.println (strHoldings + "   ||");
  229.         }

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

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

  232.         System.out.println ("\t|       LONG END COST DISTRIBUTION, PENALTY, AND DECAY       ||");

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

  234.         System.out.println ("\t|       LAMBDA      |   MEAN  | SIGMA^2 | PENALTY | HALFLIFE ||");

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

  236.         for (double dblLambda : adblLambdaLongEndU) {
  237.             AlmgrenChrissDriftDiscrete acdd = (AlmgrenChrissDriftDiscrete) DiscreteAlmgrenChrissDrift.Standard (
  238.                 dblX,
  239.                 dblT,
  240.                 iN,
  241.                 lpep,
  242.                 dblLambda
  243.             ).generate();
  244.    
  245.             String strHoldings = "\t| [LAMBDA = " + FormatUtil.FormatDouble (dblLambda, 1, 3, dblX) + "]";

  246.             double dblTransactionCostExpectation = acdd.transactionCostExpectation();

  247.             double dblTransactionCostVariance = acdd.transactionCostVariance();

  248.             double dblTransactionCostPenalty = dblTransactionCostExpectation + dblLambda * dblTransactionCostVariance;

  249.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (dblTransactionCostExpectation / dblX, 1, 4, 1.);

  250.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (dblTransactionCostVariance / dblX / dblX, 1, 4, 1.);

  251.             strHoldings = strHoldings + " | " + FormatUtil.FormatDouble (dblTransactionCostPenalty / dblX, 1, 4, 1.);

  252.             strHoldings = strHoldings + " |  " + FormatUtil.FormatDouble (acdd.halfLife(), 1, 2, 1.);

  253.             System.out.println (strHoldings + "   ||");
  254.         }

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

  256.         EnvManager.TerminateEnv();
  257.     }
  258. }