OptimalMeasuresDiscountDependence.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.  * OptimalMeasuresDiscountDependence demonstrates the Dependence of the Optimal Principal Measures on the
  59.  *  Discount. 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 OptimalMeasuresDiscountDependence {

  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[] adblPrincipalDiscount = new double[] {
  92.             0.12,
  93.             0.13,
  94.             0.14,
  95.             0.15,
  96.             0.16,
  97.             0.18,
  98.             0.21,
  99.             0.24,
  100.             0.27,
  101.             0.30,
  102.             0.33,
  103.             0.36,
  104.             0.39,
  105.             0.42,
  106.             0.45,
  107.             0.50,
  108.             0.55,
  109.             0.60,
  110.             0.66,
  111.             0.72,
  112.             0.78,
  113.             0.84,
  114.             0.91,
  115.             0.98
  116.         };

  117.         PriceMarketImpactPower pmip = new PriceMarketImpactPower (
  118.             new AssetTransactionSettings (
  119.                 dblS0,
  120.                 dblDailyVolume,
  121.                 0.
  122.             ),
  123.             dblPermanentImpactFactor,
  124.             dblTemporaryImpactFactor,
  125.             dblDailyVolumeExecutionFactor,
  126.             dblK
  127.         );

  128.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.Almgren2003 (
  129.             new ArithmeticPriceDynamicsSettings (
  130.                 0.,
  131.                 new FlatUnivariate (dblVolatility),
  132.                 0.
  133.             ),
  134.             new UniformParticipationRateLinear ((ParticipationRateLinear) pmip.permanentTransactionFunction()),
  135.             new UniformParticipationRate ((ParticipationRatePower) pmip.temporaryTransactionFunction())
  136.         );

  137.         ContinuousPowerImpact cpi = ContinuousPowerImpact.Standard (
  138.             dblX,
  139.             dblT,
  140.             lpep,
  141.             dblLambda
  142.         );

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

  144.         Almgren2003Estimator a2003e = new Almgren2003Estimator (
  145.             pic,
  146.             lpep
  147.         );

  148.         System.out.println();

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

  150.         System.out.println ("\t|         OPTIMAL MEASURES PRINCIPAL DISCOUNT DEPENDENCE           ||");

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

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

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

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

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

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

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

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

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

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

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

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

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