ContinuousLowUrgencyAsymptote.java

  1. package org.drip.execution.nonadaptive;

  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>ContinuousLowUrgencyAsymptote</i> contains the Low Urgency Asymptote of the Static Continuous Trading
  79.  * Trajectory generated by the Almgren and Chriss (2000) Scheme under the Criterion of No-Drift. The
  80.  * References are:
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Almgren, R. F., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  86.  *              Risk</i> <b>3 (2)</b> 5-39
  87.  *      </li>
  88.  *      <li>
  89.  *          Almgren, R. F. (2009): Optimal Trading in a Dynamic Market
  90.  *              https://www.math.nyu.edu/financial_mathematics/content/02_financial/2009-2.pdf
  91.  *      </li>
  92.  *      <li>
  93.  *          Almgren, R. F. (2012): Optimal Trading with Stochastic Liquidity and Volatility <i>SIAM Journal
  94.  *          of Financial Mathematics</i> <b>3 (1)</b> 163-181
  95.  *      </li>
  96.  *      <li>
  97.  *          Geman, H., D. B. Madan, and M. Yor (2001): Time Changes for Levy Processes <i>Mathematical
  98.  *              Finance</i> <b>11 (1)</b> 79-96
  99.  *      </li>
  100.  *      <li>
  101.  *          Walia, N. (2006): <i>Optimal Trading: Dynamic Stock Liquidation Strategies</i> Princeton
  102.                 University
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  110.  *      <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>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/nonadaptive/README.md">Almgren-Chriss Static Optimal Trajectory</a></li>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class ContinuousLowUrgencyAsymptote extends
  117.     org.drip.execution.nonadaptive.StaticOptimalSchemeContinuous {

  118.     /**
  119.      * Create the Standard ContinuousLowUrgencyAsymptote Instance
  120.      *
  121.      * @param dblStartHoldings Trajectory Start Holdings
  122.      * @param dblFinishTime Trajectory Finish Time
  123.      * @param lpep The Linear Impact Expectation Parameters
  124.      * @param dblRiskAversion The Risk Aversion Parameter
  125.      *
  126.      * @return The ContinuousLowUrgencyAsymptote Instance
  127.      */

  128.     public static final ContinuousLowUrgencyAsymptote Standard (
  129.         final double dblStartHoldings,
  130.         final double dblFinishTime,
  131.         final org.drip.execution.dynamics.LinearPermanentExpectationParameters lpep,
  132.         final double dblRiskAversion)
  133.     {
  134.         try {
  135.             return new ContinuousLowUrgencyAsymptote (new org.drip.execution.strategy.OrderSpecification
  136.                 (dblStartHoldings, dblFinishTime), lpep, new
  137.                     org.drip.execution.risk.MeanVarianceObjectiveUtility (dblRiskAversion));
  138.         } catch (java.lang.Exception e) {
  139.             e.printStackTrace();
  140.         }

  141.         return null;
  142.     }

  143.     private ContinuousLowUrgencyAsymptote (
  144.         final org.drip.execution.strategy.OrderSpecification os,
  145.         final org.drip.execution.dynamics.LinearPermanentExpectationParameters lpep,
  146.         final org.drip.execution.risk.MeanVarianceObjectiveUtility mvou)
  147.         throws java.lang.Exception
  148.     {
  149.         super (os, lpep, mvou);
  150.     }

  151.     @Override public org.drip.execution.optimum.EfficientTradingTrajectory generate()
  152.     {
  153.         org.drip.execution.dynamics.LinearPermanentExpectationParameters lpep =
  154.             (org.drip.execution.dynamics.LinearPermanentExpectationParameters) priceEvolutionParameters();

  155.         org.drip.execution.impact.TransactionFunction tfTemporaryExpectation =
  156.             lpep.temporaryExpectation().epochImpactFunction();

  157.         if (!(tfTemporaryExpectation instanceof org.drip.execution.impact.TransactionFunctionLinear))
  158.             return null;

  159.         double dblEpochVolatility = java.lang.Double.NaN;
  160.         org.drip.execution.impact.TransactionFunctionLinear tflTemporaryExpectation =
  161.             (org.drip.execution.impact.TransactionFunctionLinear) tfTemporaryExpectation;

  162.         try {
  163.             dblEpochVolatility = lpep.arithmeticPriceDynamicsSettings().epochVolatility();
  164.         } catch (java.lang.Exception e) {
  165.             e.printStackTrace();

  166.             return null;
  167.         }

  168.         final double dblSigma = dblEpochVolatility;

  169.         final double dblEta = tflTemporaryExpectation.slope();

  170.         final double dblLambda = ((org.drip.execution.risk.MeanVarianceObjectiveUtility)
  171.             objectiveUtility()).riskAversion();

  172.         final double dblKappa = java.lang.Math.sqrt (dblLambda * dblSigma * dblSigma / dblEta);

  173.         org.drip.execution.strategy.OrderSpecification os = orderSpecification();

  174.         final double dblT = os.maxExecutionTime();

  175.         final double dblX = os.size();

  176.         final org.drip.function.definition.R1ToR1 r1ToR1Holdings = new org.drip.function.definition.R1ToR1
  177.             (null) {
  178.             @Override public double evaluate (
  179.                 final double dblTime)
  180.                 throws java.lang.Exception
  181.             {
  182.                 if (!org.drip.numerical.common.NumberUtil.IsValid (dblTime))
  183.                     throw new java.lang.Exception
  184.                         ("ContinuousLowUrgencyAsymptote::Holdings::evaluate => Invalid Inputs");

  185.                 return java.lang.Math.sinh (dblKappa * (dblT - dblTime)) / java.lang.Math.sinh (dblKappa *
  186.                     dblT) * dblX;
  187.             }
  188.         };

  189.         org.drip.function.definition.R1ToR1 r1ToR1TradeRate = new org.drip.function.definition.R1ToR1 (null)
  190.         {
  191.             @Override public double evaluate (
  192.                 final double dblTime)
  193.                 throws java.lang.Exception
  194.             {
  195.                 if (!org.drip.numerical.common.NumberUtil.IsValid (dblTime))
  196.                     throw new java.lang.Exception
  197.                         ("ContinuousLowUrgencyAsymptote::TradeRate::evaluate => Invalid Inputs");

  198.                 return dblT == dblTime ? 0. : r1ToR1Holdings.evaluate (dblTime) / (dblT - dblTime);
  199.             }
  200.         };

  201.         org.drip.function.definition.R1ToR1 r1ToR1TransactionCostExpectation = new
  202.             org.drip.function.definition.R1ToR1 (null) {
  203.             @Override public double evaluate (
  204.                 final double dblTime)
  205.                 throws java.lang.Exception
  206.             {
  207.                 if (!org.drip.numerical.common.NumberUtil.IsValid (dblTime))
  208.                     throw new java.lang.Exception
  209.                         ("ContinuousLowUrgencyAsymptote::TransactionCostExpectation::evaluate => Invalid Inputs");

  210.                 double dblRemainingTime = dblT - dblTime;

  211.                 if (0. >= dblRemainingTime) return 0.;

  212.                 double dblHoldings = r1ToR1Holdings.evaluate (dblTime);

  213.                 return dblEta * dblHoldings * dblHoldings / dblRemainingTime + (dblLambda * dblSigma *
  214.                     dblSigma * dblHoldings * dblHoldings * dblRemainingTime / 3.);
  215.             }
  216.         };

  217.         final org.drip.function.definition.R1ToR1 r1ToR1TransactionCostVarianceRate = new
  218.             org.drip.function.definition.R1ToR1 (null) {
  219.             @Override public double evaluate (
  220.                 final double dblTime)
  221.                 throws java.lang.Exception
  222.             {
  223.                 double dblHoldings = r1ToR1Holdings.evaluate (dblTime);

  224.                 return dblSigma * dblSigma * dblHoldings * dblHoldings;
  225.             }
  226.         };

  227.         org.drip.function.definition.R1ToR1 r1ToR1TransactionCostVariance = new
  228.             org.drip.function.definition.R1ToR1 (null) {
  229.             @Override public double evaluate (
  230.                 final double dblTime)
  231.                 throws java.lang.Exception
  232.             {
  233.                 return r1ToR1TransactionCostVarianceRate.integrate (dblTime, dblT);
  234.             }
  235.         };

  236.         try {
  237.             return new org.drip.execution.optimum.EfficientTradingTrajectoryContinuous (dblT, dblEta *
  238.                 dblKappa * dblX * dblX / java.lang.Math.tanh (dblKappa * dblT),
  239.                     r1ToR1TransactionCostExpectation.evaluate (0.), 1. / dblKappa, dblEta * dblX / (dblT *
  240.                         dblEpochVolatility * java.lang.Math.sqrt (dblT)), r1ToR1Holdings, r1ToR1TradeRate,
  241.                             r1ToR1TransactionCostExpectation, r1ToR1TransactionCostVariance);
  242.         } catch (java.lang.Exception e) {
  243.             e.printStackTrace();
  244.         }

  245.         return null;
  246.     }
  247. }