Almgren2003Estimator.java

  1. package org.drip.execution.principal;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  10.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  11.  *
  12.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  13.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  14.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  15.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  16.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  17.  *      and computational support.
  18.  *  
  19.  *      https://lakshmidrip.github.io/DROP/
  20.  *  
  21.  *  DROP is composed of three modules:
  22.  *  
  23.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  24.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  25.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  26.  *
  27.  *  DROP Product Core implements libraries for the following:
  28.  *  - Fixed Income Analytics
  29.  *  - Loan Analytics
  30.  *  - Transaction Cost Analytics
  31.  *
  32.  *  DROP Portfolio Core implements libraries for the following:
  33.  *  - Asset Allocation Analytics
  34.  *  - Asset Liability Management Analytics
  35.  *  - Capital Estimation Analytics
  36.  *  - Exposure Analytics
  37.  *  - Margin Analytics
  38.  *  - XVA Analytics
  39.  *
  40.  *  DROP Computational Core implements libraries for the following:
  41.  *  - Algorithm Support
  42.  *  - Computation Support
  43.  *  - Function Analysis
  44.  *  - Model Validation
  45.  *  - Numerical Analysis
  46.  *  - Numerical Optimizer
  47.  *  - Spline Builder
  48.  *  - Statistical Learning
  49.  *
  50.  *  Documentation for DROP is Spread Over:
  51.  *
  52.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  53.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  54.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  55.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  56.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  57.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  58.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  59.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  60.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  61.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  62.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  63.  *
  64.  *  Licensed under the Apache License, Version 2.0 (the "License");
  65.  *      you may not use this file except in compliance with the License.
  66.  *  
  67.  *  You may obtain a copy of the License at
  68.  *      http://www.apache.org/licenses/LICENSE-2.0
  69.  *  
  70.  *  Unless required by applicable law or agreed to in writing, software
  71.  *      distributed under the License is distributed on an "AS IS" BASIS,
  72.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  73.  *  
  74.  *  See the License for the specific language governing permissions and
  75.  *      limitations under the License.
  76.  */

  77. /**
  78.  * <i>Almgren2003Estimator</i> generates the Gross Profit Distribution and the Information Ratio for a given
  79.  * Level of Principal Discount for an Optimal Trajectory that is generated using the Almgren (2003) Scheme.
  80.  * The References are:
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *  <li>
  85.  *      Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  86.  *  </li>
  87.  *  <li>
  88.  *      Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of Risk</i>
  89.  *          <b>3 (2)</b> 5-39
  90.  *  </li>
  91.  *  <li>
  92.  *      Almgren, R. (2003): Optimal Execution with Nonlinear Impact Functions and Trading-Enhanced Risk
  93.  *          <i>Applied Mathematical Finance</i> <b>10 (1)</b> 1-18
  94.  *  </li>
  95.  *  <li>
  96.  *      Almgren, R., and N. Chriss (2003): Bidding Principles <i>Risk</i> 97-102
  97.  *  </li>
  98.  *  <li>
  99.  *      Almgren, R., C. Thum, E. Hauptmann, and H. Li (2005): Equity Market Impact <i>Risk</i> <b>18 (7)</b>
  100.  *          57-62
  101.  *  </li>
  102.  *  </ul>
  103.  *
  104.  *  <br><br>
  105.  *  <ul>
  106.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  107.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  108.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/README.md">Optimal Impact/Capture Based Trading Trajectories - Deterministic, Stochastic, Static, and Dynamic</a></li>
  109.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/principal/README.md">Information Ratio Based Principal Trades</a></li>
  110.  *  </ul>
  111.  *
  112.  * @author Lakshmi Krishnamurthy
  113.  */

  114. public class Almgren2003Estimator extends org.drip.execution.principal.GrossProfitEstimator {
  115.     private org.drip.execution.dynamics.LinearPermanentExpectationParameters _lpep =  null;

  116.     /**
  117.      * Almgren2003Estimator Constructor
  118.      *
  119.      * @param pic The Power Continuous Market Impact Trajectory
  120.      * @param lpep The Linear Permanent Expectation Paremeter
  121.      *
  122.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  123.      */

  124.     public Almgren2003Estimator (
  125.         final org.drip.execution.optimum.PowerImpactContinuous pic,
  126.         final org.drip.execution.dynamics.LinearPermanentExpectationParameters lpep)
  127.         throws java.lang.Exception
  128.     {
  129.         super (pic);

  130.         if (null == (_lpep = lpep))
  131.             throw new java.lang.Exception ("Almgren2003Estimator Constructor => Invalid Inputs");
  132.     }

  133.     /**
  134.      * Generate the Horizon that results in the Optimal Information Ratio
  135.      *
  136.      * @param dblD The Principal Discount "D"
  137.      *
  138.      * @return The Horizon that results in the Optimal Information Ratio
  139.      *
  140.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  141.      */

  142.     public double optimalInformationRatioHorizon (
  143.         final double dblD)
  144.         throws java.lang.Exception
  145.     {
  146.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblD))
  147.             throw new java.lang.Exception
  148.                 ("Almgren2003Estimator::optimalInformationRatioHorizon => Invalid Inputs");

  149.         org.drip.execution.impact.TransactionFunctionPower tfpTemporaryExpectation =
  150.             (org.drip.execution.impact.TransactionFunctionPower)
  151.                 _lpep.temporaryExpectation().epochImpactFunction();

  152.         double dblGamma = ((org.drip.execution.impact.TransactionFunctionLinear)
  153.             _lpep.linearPermanentExpectation().epochImpactFunction()).slope();

  154.         double dblEta = tfpTemporaryExpectation.constant();

  155.         double dblK = tfpTemporaryExpectation.exponent();

  156.         double dblX = efficientTrajectory().tradeSize();

  157.         return dblX * java.lang.Math.pow (dblEta * (dblK + 1.) * (dblK + 1.) / (3. * dblK + 1.) / (dblD - 0.5
  158.             * dblGamma * dblX), 1. / dblK);
  159.     }

  160.     /**
  161.      * Compute the Optimal Information Ratio
  162.      *
  163.      * @param dblD The Principal Discount "D"
  164.      *
  165.      * @return The Optimal Information Ratio
  166.      *
  167.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  168.      */

  169.     public double optimalInformationRatio (
  170.         final double dblD)
  171.         throws java.lang.Exception
  172.     {
  173.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblD))
  174.             throw new java.lang.Exception
  175.                 ("Almgren2003Estimator::optimalInformationRatio => Invalid Inputs");

  176.         org.drip.execution.impact.TransactionFunctionPower tfpTemporaryExpectation =
  177.             (org.drip.execution.impact.TransactionFunctionPower)
  178.                 _lpep.temporaryExpectation().epochImpactFunction();

  179.         double dblSigma = _lpep.arithmeticPriceDynamicsSettings().epochVolatility();

  180.         double dblGamma = ((org.drip.execution.impact.TransactionFunctionLinear)
  181.             _lpep.linearPermanentExpectation().epochImpactFunction()).slope();

  182.         double dblEta = tfpTemporaryExpectation.constant();

  183.         double dblK = tfpTemporaryExpectation.exponent();

  184.         double dblX = efficientTrajectory().tradeSize();

  185.         return java.lang.Math.pow (3. * dblK + 1.              , (1. * dblK + 2.) / (2. * dblK)) /
  186.                java.lang.Math.pow (1. * dblK + 1.              , (3. * dblK + 4.) / (2. * dblK)) *
  187.                java.lang.Math.pow (dblD - 0.5 * dblGamma * dblX, (1. * dblK + 1.) / (1. * dblK)) /
  188.                java.lang.Math.pow (dblEta                      , (0. * dblK + 1.) / (1. * dblK)) /
  189.                (dblX * dblSigma);
  190.     }

  191.     /**
  192.      * Compute the Principal Discount Hurdle given the Information Ratio
  193.      *
  194.      * @param dblI The Optimal Information Ratio "I"
  195.      *
  196.      * @return The Principal Discount Hurdle
  197.      *
  198.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  199.      */

  200.     public double principalDiscountHurdle (
  201.         final double dblI)
  202.         throws java.lang.Exception
  203.     {
  204.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblI))
  205.             throw new java.lang.Exception
  206.                 ("Almgren2003Estimator::principalDiscountHurdle => Invalid Inputs");

  207.         org.drip.execution.impact.TransactionFunctionPower tfpTemporaryExpectation =
  208.             (org.drip.execution.impact.TransactionFunctionPower)
  209.                 _lpep.temporaryExpectation().epochImpactFunction();

  210.         double dblEta = tfpTemporaryExpectation.constant();

  211.         double dblGamma = ((org.drip.execution.impact.TransactionFunctionLinear)
  212.             _lpep.linearPermanentExpectation().epochImpactFunction()).slope();

  213.         double dblSigma = _lpep.arithmeticPriceDynamicsSettings().epochVolatility();

  214.         double dblK = tfpTemporaryExpectation.exponent();

  215.         double dblX = efficientTrajectory().tradeSize();

  216.         return java.lang.Math.pow (
  217.                0.5 * dblGamma * dblX +
  218.                java.lang.Math.pow (1. * dblK + 1.              , (3. * dblK + 4.) / (2. * dblK)) /
  219.                java.lang.Math.pow (3. * dblK + 1.              , (1. * dblK + 2.) / (2. * dblK)) *
  220.                java.lang.Math.pow (dblEta                      , (0. * dblK + 1.) / (1. * dblK)) *
  221.                (dblX * dblSigma * dblI),
  222.                dblK / (dblK + 1.)
  223.         );
  224.     }

  225.     /**
  226.      * Generate the Constant/Exponent Dependencies on the Market Parameters for the Optimal Execution Horizon
  227.      *  / Information Ratio
  228.      *  
  229.      * @return The Optimal Execution Horizon/Information Ratio Dependency
  230.      */

  231.     public org.drip.execution.principal.HorizonInformationRatioDependence optimalMeasures()
  232.     {
  233.         org.drip.execution.impact.TransactionFunctionPower tfpTemporaryExpectation =
  234.             (org.drip.execution.impact.TransactionFunctionPower)
  235.                 _lpep.temporaryExpectation().epochImpactFunction();

  236.         double dblK = tfpTemporaryExpectation.exponent();

  237.         try {
  238.             return new org.drip.execution.principal.HorizonInformationRatioDependence (
  239.                 new org.drip.execution.principal.OptimalMeasureDependence (
  240.                     java.lang.Math.pow ((dblK + 1.) * (dblK + 1.) / (3. * dblK + 1.), 1. / dblK),
  241.                     1. / dblK,
  242.                     1.,
  243.                     0.,
  244.                     -1. / dblK
  245.                 ),
  246.                 new org.drip.execution.principal.OptimalMeasureDependence (
  247.                     java.lang.Math.pow (3. * dblK + 1., (1. * dblK + 2.) / (2. * dblK)) /
  248.                         java.lang.Math.pow (1. * dblK + 1., (3. * dblK + 4.) / (2. * dblK)),
  249.                     -1. / dblK,
  250.                     -1.,
  251.                     -1.,
  252.                     (dblK + 1.) / dblK
  253.                 )
  254.             );
  255.         } catch (java.lang.Exception e) {
  256.             e.printStackTrace();
  257.         }

  258.         return null;
  259.     }
  260. }