InformationRatioAnalysis.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.  * InformationRatioAnalysis demonstrates the Analysis of the Dependence of the Optimal Principal Measures on
  59.  *  the Information Ratio Hurdle. 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 InformationRatioAnalysis {

  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 dblK = 1.;

  91.         double[] adblInformationRatio = new double[] {
  92.             0.01,
  93.             0.02,
  94.             0.03,
  95.             0.04,
  96.             0.05,
  97.             0.07,
  98.             0.09,
  99.             0.11,
  100.             0.13,
  101.             0.15,
  102.             0.18,
  103.             0.21,
  104.             0.24,
  105.             0.28,
  106.             0.32,
  107.             0.36,
  108.             0.40,
  109.             0.45,
  110.             0.50,
  111.             0.55,
  112.             0.60,
  113.             0.66,
  114.             0.72,
  115.             0.78,
  116.             0.84,
  117.             0.91,
  118.             0.98,
  119.             1.05,
  120.             1.12,
  121.             1.20,
  122.             1.28,
  123.             1.36,
  124.             1.44
  125.         };

  126.         PriceMarketImpactPower pmip = new PriceMarketImpactPower (
  127.             new AssetTransactionSettings (
  128.                 dblS0,
  129.                 dblDailyVolume,
  130.                 0.
  131.             ),
  132.             dblPermanentImpactFactor,
  133.             dblTemporaryImpactFactor,
  134.             dblDailyVolumeExecutionFactor,
  135.             dblK
  136.         );

  137.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.Almgren2003 (
  138.             new ArithmeticPriceDynamicsSettings (
  139.                 0.,
  140.                 new FlatUnivariate (dblVolatility),
  141.                 0.
  142.             ),
  143.             new UniformParticipationRateLinear ((ParticipationRateLinear) pmip.permanentTransactionFunction()),
  144.             new UniformParticipationRate ((ParticipationRatePower) pmip.temporaryTransactionFunction())
  145.         );

  146.         ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  147.             dblX,
  148.             dblT,
  149.             lpep,
  150.             dblLambda
  151.         );

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

  153.         Almgren2003Estimator a2003e = new Almgren2003Estimator (
  154.             pic,
  155.             lpep
  156.         );

  157.         System.out.println();

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

  159.         System.out.println ("\t|             OPTIMAL MEASURES INFORMATION RATIO DEPENDENCE               ||");

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

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

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

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

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

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

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

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

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

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

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

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

  172.         for (double dblInformationRatio : adblInformationRatio) {
  173.             double dblPrincipalDiscount = a2003e.principalDiscountHurdle (dblInformationRatio);

  174.             System.out.println (
  175.                 "\t|" +
  176.                 FormatUtil.FormatDouble (dblInformationRatio, 1, 2, 1.) + " |" +
  177.                 FormatUtil.FormatDouble (dblPrincipalDiscount, 1, 2, 1.) + " |" +
  178.                 FormatUtil.FormatDouble (a2003e.principalMeasure (dblPrincipalDiscount).mean(), 5, 0, 1.) + " |" +
  179.                 FormatUtil.FormatDouble (Math.sqrt (a2003e.principalMeasure (dblPrincipalDiscount).variance()), 6, 0, 1.) + " |" +
  180.                 FormatUtil.FormatDouble (a2003e.horizonPrincipalMeasure (dblPrincipalDiscount).mean(), 5, 0, 1.) + " |" +
  181.                 FormatUtil.FormatDouble (Math.sqrt (a2003e.horizonPrincipalMeasure (dblPrincipalDiscount).variance()), 5, 0, 1.) + " |" +
  182.                 FormatUtil.FormatDouble (a2003e.informationRatio (dblPrincipalDiscount), 1, 4, 1.) + " |" +
  183.                 FormatUtil.FormatDouble (a2003e.optimalInformationRatio (dblPrincipalDiscount), 1, 4, 1.) + " |" +
  184.                 FormatUtil.FormatDouble (a2003e.optimalInformationRatioHorizon (dblPrincipalDiscount), 1, 4, 1.) + " ||"
  185.             );
  186.         }

  187.         System.out.println ("\t|-------------------------------------------------------------------------||");
  188.     }
  189. }