ContinuousTrajectoryLinearImpact.java

  1. package org.drip.sample.almgren2003;

  2. import org.drip.execution.dynamics.*;
  3. import org.drip.execution.impact.*;
  4. import org.drip.execution.nonadaptive.ContinuousPowerImpact;
  5. import org.drip.execution.optimum.PowerImpactContinuous;
  6. import org.drip.execution.parameters.*;
  7. import org.drip.execution.profiletime.*;
  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>ContinuousTrajectoryLinearImpact</i> reconciles the Characteristic Times of the Optimal Continuous
  88.  * Trading Trajectory resulting from the Application of the Almgren (2003) Scheme to a Linear Power Law
  89.  * Temporary Market Impact Function. The Power Exponent Considered here is
  90.  *
  91.  * k = 1.0
  92.  *
  93.  * The References are:
  94.  *
  95.  * <br><br>
  96.  *  <ul>
  97.  *      <li>
  98.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  99.  *      </li>
  100.  *
  101.  *      <li>
  102.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  103.  *              Risk</i> <b>3 (2)</b> 5-39
  104.  *      </li>
  105.  *
  106.  *      <li>
  107.  *          Almgren, R. (2003): Optimal Execution with Nonlinear Impact Functions and Trading-Enhanced Risk
  108.  *              <i>Applied Mathematical Finance</i> <b>10 (1)</b> 1-18.
  109.  *      </li>
  110.  *
  111.  *      <li>
  112.  *          Almgren, R., and N. Chriss (2003): Bidding Principles <i>Risk</i> 97-102
  113.  *      </li>
  114.  *
  115.  *      <li>
  116.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  117.  *              Markets</i> <b>1</b> 1-50
  118.  *      </li>
  119.  *  </ul>
  120.  *
  121.  * <br><br>
  122.  *  <ul>
  123.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  124.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  125.  *      <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>
  126.  *      <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>
  127.  *  </ul>
  128.  * <br><br>
  129.  *
  130.  * @author Lakshmi Krishnamurthy
  131.  */

  132. public class ContinuousTrajectoryLinearImpact {

  133.     public static final void main (
  134.         final String[] astrArgs)
  135.         throws Exception
  136.     {
  137.         EnvManager.InitEnv (
  138.             "",
  139.             true
  140.         );

  141.         double dblS0 = 50.;
  142.         double dblDailyVolume = 1000000.;
  143.         double dblBidAskSpread = 0.;
  144.         double dblPermanentImpactFactor = 0.;
  145.         double dblTemporaryImpactFactor = 0.01;
  146.         double dblK = 1.0;
  147.         double dblGamma = 0.;
  148.         double dblDailyVolumeExecutionFactor = 0.1;
  149.         double dblDrift = 0.;
  150.         double dblVolatility = 1.;
  151.         double dblSerialCorrelation = 0.;
  152.         double dblX = 100000.;
  153.         double dblFinishTime = 1.;

  154.         double[] adblLambda = new double[] {
  155.             1.e-03,
  156.             1.e-04,
  157.             1.e-05,
  158.             1.e-06,
  159.             1.e-07
  160.         };

  161.         double[][] aadblAlmgren2003Reconciler = new double[][] {
  162.             {0.07, 354.,  19.},
  163.             {0.22, 112.,  33.},
  164.             {0.71,  35.,  59.},
  165.             {2.24,  11., 106.},
  166.             {7.07,   4., 188.}
  167.         };

  168.         PriceMarketImpactPower pmip = new PriceMarketImpactPower (
  169.             new AssetTransactionSettings (
  170.                 dblS0,
  171.                 dblDailyVolume,
  172.                 dblBidAskSpread
  173.             ),
  174.             dblPermanentImpactFactor,
  175.             dblTemporaryImpactFactor,
  176.             dblDailyVolumeExecutionFactor,
  177.             dblK
  178.         );

  179.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.Almgren2003 (
  180.             new ArithmeticPriceDynamicsSettings (
  181.                 dblDrift,
  182.                 new FlatUnivariate (dblVolatility),
  183.                 dblSerialCorrelation
  184.             ),
  185.             new UniformParticipationRateLinear (
  186.                 new ParticipationRateLinear (
  187.                     0.,
  188.                     dblGamma
  189.                 )
  190.             ),
  191.             new UniformParticipationRate ((ParticipationRatePower) pmip.temporaryTransactionFunction())
  192.         );

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

  194.         System.out.println ("\t|                  COMPUTED                 ||");

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

  196.         System.out.println ("\t| LAMBDAINV || T_STAR | COST_EXP | COST_STD ||");

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

  198.         for (int i = 0; i < adblLambda.length; ++i) {
  199.             ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  200.                 dblX,
  201.                 dblFinishTime,
  202.                 lpep,
  203.                 adblLambda[i]
  204.             );

  205.             PowerImpactContinuous pic = (PowerImpactContinuous) cpi.generate();

  206.             System.out.println ("\t|  " +
  207.                 FormatUtil.FormatDouble (1. / adblLambda[i], 5, 0, 1.e-03) + "   || " +
  208.                 FormatUtil.FormatDouble (pic.characteristicTime(), 1, 2, 1.) + "      " +
  209.                 FormatUtil.FormatDouble (pic.transactionCostExpectation(), 3, 0, 1.e-03) + "       " +
  210.                 FormatUtil.FormatDouble (Math.sqrt (pic.transactionCostVariance()), 3, 0, 1.e-03) + "   ||"
  211.             );
  212.         }

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

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

  215.         System.out.println ("\t|               ALMGREN (2003)              ||");

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

  217.         System.out.println ("\t| LAMBDAINV || T_STAR | COST_EXP | COST_STD ||");

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

  219.         for (int i = 0; i < adblLambda.length; ++i)
  220.             System.out.println ("\t|  " +
  221.                 FormatUtil.FormatDouble (1. / adblLambda[i], 5, 0, 1.e-03) + "   || " +
  222.                 FormatUtil.FormatDouble (aadblAlmgren2003Reconciler[i][0], 1, 2, 1.) + "      " +
  223.                 FormatUtil.FormatDouble (aadblAlmgren2003Reconciler[i][1], 3, 0, 1.) + "       " +
  224.                 FormatUtil.FormatDouble (aadblAlmgren2003Reconciler[i][2], 3, 0, 1.) + "   ||"
  225.             );

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

  227.         EnvManager.TerminateEnv();
  228.     }
  229. }