ImpactExponentAnalysis.java

  1. package org.drip.sample.principal;

  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.principal.Almgren2003Estimator;
  8. import org.drip.execution.profiletime.*;
  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) 2018 Lakshmi Krishnamurthy
  17.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  18.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  19.  *
  20.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  21.  *      libraries targeting analysts and developers
  22.  *      https://lakshmidrip.github.io/DRIP/
  23.  *  
  24.  *  DRIP is composed of four main libraries:
  25.  *  
  26.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  27.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  28.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  29.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  30.  *
  31.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  32.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  33.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  34.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  35.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  36.  *
  37.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  38.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  39.  *
  40.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  41.  *
  42.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  43.  *
  44.  *  Licensed under the Apache License, Version 2.0 (the "License");
  45.  *      you may not use this file except in compliance with the License.
  46.  *  
  47.  *  You may obtain a copy of the License at
  48.  *      http://www.apache.org/licenses/LICENSE-2.0
  49.  *  
  50.  *  Unless required by applicable law or agreed to in writing, software
  51.  *      distributed under the License is distributed on an "AS IS" BASIS,
  52.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  53.  *  
  54.  *  See the License for the specific language governing permissions and
  55.  *      limitations under the License.
  56.  */

  57. /**
  58.  * ImpactExponentAnalysis demonstrates the Analysis of the Dependence of the Optimal Principal Measures on
  59.  *  the Exponent of the Temporary Market Impact. The References are:
  60.  *
  61.  *  - Almgren, R., and N. Chriss (1999): Value under Liquidation, Risk 12 (12).
  62.  *
  63.  *  - Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions, Journal of Risk 3 (2)
  64.  *      5-39.
  65.  *
  66.  *  - Almgren, R. (2003): Optimal Execution with Nonlinear Impact Functions and Trading-Enhanced Risk,
  67.  *      Applied Mathematical Finance 10 (1) 1-18.
  68.  *
  69.  *  - Almgren, R., and N. Chriss (2003): Bidding Principles, Risk 97-102.
  70.  *
  71.  *  - Almgren, R., C. Thum, E. Hauptmann, and H. Li (2005): Equity Market Impact, Risk 18 (7) 57-62.
  72.  *
  73.  * @author Lakshmi Krishnamurthy
  74.  */

  75. public class ImpactExponentAnalysis {

  76.     public static final void main (
  77.         final String[] astrArgs)
  78.         throws Exception
  79.     {
  80.         EnvManager.InitEnv ("");

  81.         double dblS0 = 50.;
  82.         double dblX = 100000.;
  83.         double dblVolatility = 1.;
  84.         double dblDailyVolume = 1000000.;
  85.         double dblDailyVolumeExecutionFactor = 0.1;
  86.         double dblPermanentImpactFactor = 0.;
  87.         double dblTemporaryImpactFactor = 0.01;
  88.         double dblT = 5.;
  89.         double dblLambda = 1.e-06;
  90.         double dblPrincipalDiscount = 0.15;

  91.         double[] adblK = new double[] {
  92.             0.20,
  93.             0.25,
  94.             0.30,
  95.             0.35,
  96.             0.40,
  97.             0.45,
  98.             0.50,
  99.             0.55,
  100.             0.60,
  101.             0.65,
  102.             0.70,
  103.             0.75,
  104.             0.80,
  105.             0.85,
  106.             0.90,
  107.             0.95,
  108.             1.00,
  109.             1.10,
  110.             1.20,
  111.             1.35,
  112.             1.50
  113.         };

  114.         System.out.println();

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

  116.         System.out.println ("\t|                OPTIMAL MEASURES IMPACT EXPONENT DEPENDENCE                ||");

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

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

  119.         System.out.println ("\t|            - Temporary Market Impact Exponent                             ||");

  120.         System.out.println ("\t|            - Principal Discount                                           ||");

  121.         System.out.println ("\t|            - Gross Profit Expectation                                     ||");

  122.         System.out.println ("\t|            - Gross Profit Standard Deviation                              ||");

  123.         System.out.println ("\t|            - Gross Returns Expectation                                    ||");

  124.         System.out.println ("\t|            - Gross Returns Standard Deviation                             ||");

  125.         System.out.println ("\t|            - Information Ratio                                            ||");

  126.         System.out.println ("\t|            - Optimal Information Ratio                                    ||");

  127.         System.out.println ("\t|            - Optimal Information Ratio Horizon                            ||");

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

  129.         for (double dblK : adblK) {
  130.             PriceMarketImpactPower pmip = new PriceMarketImpactPower (
  131.                 new AssetTransactionSettings (
  132.                     dblS0,
  133.                     dblDailyVolume,
  134.                     0.
  135.                 ),
  136.                 dblPermanentImpactFactor,
  137.                 dblTemporaryImpactFactor,
  138.                 dblDailyVolumeExecutionFactor,
  139.                 dblK
  140.             );

  141.             LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.Almgren2003 (
  142.                 new ArithmeticPriceDynamicsSettings (
  143.                     0.,
  144.                     new FlatUnivariate (dblVolatility),
  145.                     0.
  146.                 ),
  147.                 new UniformParticipationRateLinear ((ParticipationRateLinear) pmip.permanentTransactionFunction()),
  148.                 new UniformParticipationRate ((ParticipationRatePower) pmip.temporaryTransactionFunction())
  149.             );

  150.             ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  151.                 dblX,
  152.                 dblT,
  153.                 lpep,
  154.                 dblLambda
  155.             );

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

  157.             Almgren2003Estimator a2003e = new Almgren2003Estimator (
  158.                 pic,
  159.                 lpep
  160.             );

  161.             System.out.println (
  162.                 "\t|" +
  163.                 FormatUtil.FormatDouble (dblK, 1, 2, 1.) + " |" +
  164.                 FormatUtil.FormatDouble (a2003e.breakevenPrincipalDiscount(), 1, 2, 1.) + " | " +
  165.                 FormatUtil.FormatDouble (a2003e.principalMeasure (dblPrincipalDiscount).mean(), 5, 0, 1.) + " |" +
  166.                 FormatUtil.FormatDouble (Math.sqrt (a2003e.principalMeasure (dblPrincipalDiscount).variance()), 6, 0, 1.) + " |" +
  167.                 FormatUtil.FormatDouble (a2003e.horizonPrincipalMeasure (dblPrincipalDiscount).mean(), 5, 0, 1.) + " |" +
  168.                 FormatUtil.FormatDouble (Math.sqrt (a2003e.horizonPrincipalMeasure (dblPrincipalDiscount).variance()), 5, 0, 1.) + " | " +
  169.                 FormatUtil.FormatDouble (a2003e.informationRatio (dblPrincipalDiscount), 1, 4, 1.) + " |" +
  170.                 FormatUtil.FormatDouble (a2003e.optimalInformationRatio (dblPrincipalDiscount), 1, 4, 1.) + " |" +
  171.                 FormatUtil.FormatDouble (a2003e.optimalInformationRatioHorizon (dblPrincipalDiscount), 3, 2, 1.) + " ||"
  172.             );
  173.         }

  174.         System.out.println ("\t|---------------------------------------------------------------------------||");
  175.     }
  176. }