OptimalMeasuresConstantExponent.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.*;
  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.  * OptimalMeasuresConstantExponent demonstrates the Dependence Exponents on Liquidity, Trade Size, and
  59.  *  Permanent Impact Adjusted Principal Discount for the Optimal Principal Horizon and the Optional
  60.  *  Information Ratio. The References are:
  61.  *
  62.  *  - Almgren, R., and N. Chriss (1999): Value under Liquidation, Risk 12 (12).
  63.  *
  64.  *  - Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions, Journal of Risk 3 (2)
  65.  *      5-39.
  66.  *
  67.  *  - Almgren, R. (2003): Optimal Execution with Nonlinear Impact Functions and Trading-Enhanced Risk,
  68.  *      Applied Mathematical Finance 10 (1) 1-18.
  69.  *
  70.  *  - Almgren, R., and N. Chriss (2003): Bidding Principles, Risk 16 (6) 97-102.
  71.  *
  72.  *  - Almgren, R., C. Thum, E. Hauptmann, and H. Li (2005): Equity Market Impact, Risk 18 (7) 57-62.
  73.  *
  74.  * @author Lakshmi Krishnamurthy
  75.  */

  76. public class OptimalMeasuresConstantExponent {

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

  82.         double dblS0 = 50.;
  83.         double dblDailyVolume = 1000000.;
  84.         double dblBidAskSpread = 0.;
  85.         double dblPermanentImpactFactor = 0.;
  86.         double dblTemporaryImpactFactor = 0.01;
  87.         double dblDailyVolumeExecutionFactor = 0.1;
  88.         double dblDrift = 0.;
  89.         double dblVolatility = 1.;
  90.         double dblSerialCorrelation = 0.;
  91.         double dblX = 100000.;
  92.         double dblFinishTime = 1.;
  93.         double dblLambda = 5.e-06;

  94.         double[] adblK = new double[] {
  95.             0.5,
  96.             1.0,
  97.             1.5,
  98.             2.0,
  99.             2.5,
  100.             3.0,
  101.             3.5,
  102.             4.0,
  103.             4.5,
  104.             5.0,
  105.             5.5,
  106.             6.0,
  107.             6.5,
  108.             7.0,
  109.             7.5,
  110.             8.0,
  111.             8.5,
  112.             9.0,
  113.             9.5
  114.         };

  115.         System.out.println();

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

  117.         System.out.println ("\t|    Optimal Market Parameters Horizon Dependence     ||");

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

  119.         for (double dblK : adblK) {
  120.             PriceMarketImpactPower pmip = new PriceMarketImpactPower (
  121.                 new AssetTransactionSettings (
  122.                     dblS0,
  123.                     dblDailyVolume,
  124.                     dblBidAskSpread
  125.                 ),
  126.                 dblPermanentImpactFactor,
  127.                 dblTemporaryImpactFactor,
  128.                 dblDailyVolumeExecutionFactor,
  129.                 dblK
  130.             );

  131.             LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.Almgren2003 (
  132.                 new ArithmeticPriceDynamicsSettings (
  133.                     dblDrift,
  134.                     new FlatUnivariate (dblVolatility),
  135.                     dblSerialCorrelation
  136.                 ),
  137.                 new UniformParticipationRateLinear ((ParticipationRateLinear) pmip.permanentTransactionFunction()),
  138.                 new UniformParticipationRate ((ParticipationRatePower) pmip.temporaryTransactionFunction())
  139.             );

  140.             Almgren2003Estimator a2003e = new Almgren2003Estimator (
  141.                 (PowerImpactContinuous) ContinuousPowerImpact.Standard (
  142.                     dblX,
  143.                     dblFinishTime,
  144.                     lpep,
  145.                     dblLambda
  146.                 ).generate(),
  147.                 lpep
  148.             );

  149.             OptimalMeasureDependence omd = a2003e.optimalMeasures().omdHorizon();

  150.             System.out.println (
  151.                 "\t| " +
  152.                 FormatUtil.FormatDouble (dblK, 1, 3, 1.) + " | " +
  153.                 FormatUtil.FormatDouble (omd.constant(), 1, 3, 1.) + " | " +
  154.                 FormatUtil.FormatDouble (omd.liquidityExponent(), 1, 3, 1.) + " | " +
  155.                 FormatUtil.FormatDouble (omd.blockSizeExponent(), 1, 3, 1.) + " | " +
  156.                 FormatUtil.FormatDouble (omd.volatilityExponent(), 1, 3, 1.) + " | " +
  157.                 FormatUtil.FormatDouble (omd.adjustedPrincipalDiscountExponent(), 1, 3, 1.) + " ||"
  158.             );
  159.         }

  160.         System.out.println ("\t|-----------------------------------------------------||");
  161.     }
  162. }