ContinuousCoordinatedVariationStochastic.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>ContinuousCoordinatedVariationStochastic</i> uses the Coordinated Variation Version of the Linear
  79.  * Participation Rate Transaction Function as described in the "Trading Time" Model to construct an Optimal
  80.  * Trading Trajectory in the T To Infinite Limit. The 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.  *          Jones, C. M., G. Kaul, and M. L. Lipson (1994): Transactions, Volume, and Volatility <i>Review of
  102.  *              Financial Studies</i> <b>7 (4)</b> 631-651
  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 ContinuousCoordinatedVariationStochastic extends
  117.     org.drip.execution.nonadaptive.StaticOptimalSchemeContinuous {

  118.     /**
  119.      * Create the Standard ContinuousCoordinatedVariationStochastic Instance
  120.      *
  121.      * @param dblStartHoldings Trajectory Start Holdings
  122.      * @param dblFinishTime Trajectory Finish Time
  123.      * @param apep The Arithmetic Price Evolution Parameters
  124.      * @param dblRiskAversion The Risk Aversion Parameter
  125.      *
  126.      * @return The ContinuousCoordinatedVariationStochastic Instance
  127.      */

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

  141.         return null;
  142.     }

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

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

  155.         org.drip.execution.profiletime.BackgroundParticipationRate bprTemporary =
  156.             apep.temporaryExpectation();

  157.         if (!(bprTemporary instanceof org.drip.execution.profiletime.BackgroundParticipationRateLinear))
  158.             return null;

  159.         double dblInitialVolatility = java.lang.Double.NaN;
  160.         final org.drip.execution.profiletime.BackgroundParticipationRateLinear bprlTemporary =
  161.             (org.drip.execution.profiletime.BackgroundParticipationRateLinear) bprTemporary;

  162.         org.drip.execution.impact.TransactionFunctionLinear tflTemporaryExpectation =
  163.             bprlTemporary.epochLiquidityFunction();

  164.         try {
  165.             dblInitialVolatility = apep.arithmeticPriceDynamicsSettings().epochVolatility();
  166.         } catch (java.lang.Exception e) {
  167.             e.printStackTrace();

  168.             return null;
  169.         }

  170.         final double dblEpochVolatility = dblInitialVolatility;

  171.         final double dblEpochLiquidity = tflTemporaryExpectation.slope();

  172.         final double dblLambda = ((org.drip.execution.risk.MeanVarianceObjectiveUtility)
  173.             objectiveUtility()).riskAversion();

  174.         double dblEpochUrgency = java.lang.Math.sqrt (dblLambda * dblEpochVolatility * dblEpochVolatility /
  175.             dblEpochLiquidity);

  176.         final org.drip.function.definition.R1ToR1 r1ToR1VolatilityFunction =
  177.             apep.arithmeticPriceDynamicsSettings().volatilityFunction();

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

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

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

  181.         final org.drip.function.definition.R1ToR1 r1ToR1Holdings = new org.drip.function.definition.R1ToR1
  182.             (null) {
  183.             @Override public double evaluate (
  184.                 final double dblTime)
  185.                 throws java.lang.Exception
  186.             {
  187.                 double dblVolatility = r1ToR1VolatilityFunction.evaluate (dblTime);

  188.                 double dblKappa = java.lang.Math.sqrt (dblLambda * dblVolatility * dblVolatility /
  189.                     bprlTemporary.liquidityFunction (dblTime).slope());

  190.                 return java.lang.Math.sinh (dblKappa * (dblT - dblTime)) / java.lang.Math.sinh (dblKappa *
  191.                     dblT) * dblX;
  192.             }
  193.         };

  194.         org.drip.function.definition.R1ToR1 r1ToR1TradeRate = new org.drip.function.definition.R1ToR1 (null)
  195.         {
  196.             @Override public double evaluate (
  197.                 final double dblTime)
  198.                 throws java.lang.Exception
  199.             {
  200.                 double dblVolatility = r1ToR1VolatilityFunction.evaluate (dblTime);

  201.                 return java.lang.Math.sqrt (dblLambda * dblVolatility * dblVolatility /
  202.                     bprlTemporary.liquidityFunction (dblTime).slope()) * r1ToR1Holdings.evaluate (dblTime);
  203.             }
  204.         };

  205.         final org.drip.function.definition.R1ToR1 r1ToR1TransactionCostExpectationRate = new
  206.             org.drip.function.definition.R1ToR1 (null) {
  207.             @Override public double evaluate (
  208.                 final double dblTime)
  209.                 throws java.lang.Exception
  210.             {
  211.                 double dblHoldings = r1ToR1Holdings.evaluate (dblTime);

  212.                 double dblVolatility = r1ToR1VolatilityFunction.evaluate (dblTime);

  213.                 return java.lang.Math.sqrt (dblLambda * dblVolatility * dblVolatility *
  214.                     bprlTemporary.liquidityFunction (dblTime).slope()) * dblHoldings * dblHoldings;
  215.             }
  216.         };

  217.         org.drip.function.definition.R1ToR1 r1ToR1TransactionCostExpectation = new
  218.             org.drip.function.definition.R1ToR1 (null) {
  219.             @Override public double evaluate (
  220.                 final double dblTime)
  221.                 throws java.lang.Exception
  222.             {
  223.                 return r1ToR1TransactionCostExpectationRate.integrate (dblTime, dblT);
  224.             }
  225.         };

  226.         final org.drip.function.definition.R1ToR1 r1ToR1TransactionCostVarianceRate = new
  227.             org.drip.function.definition.R1ToR1 (null) {
  228.             @Override public double evaluate (
  229.                 final double dblTime)
  230.                 throws java.lang.Exception
  231.             {
  232.                 double dblHoldings = r1ToR1Holdings.evaluate (dblTime);

  233.                 double dblVolatility = r1ToR1VolatilityFunction.evaluate (dblTime);

  234.                 return dblVolatility * dblVolatility * dblHoldings * dblHoldings;
  235.             }
  236.         };

  237.         org.drip.function.definition.R1ToR1 r1ToR1TransactionCostVariance = new
  238.             org.drip.function.definition.R1ToR1 (null) {
  239.             @Override public double evaluate (
  240.                 final double dblTime)
  241.                 throws java.lang.Exception
  242.             {
  243.                 return r1ToR1TransactionCostVarianceRate.integrate (dblTime, dblT);
  244.             }
  245.         };

  246.         try {
  247.             return new org.drip.execution.optimum.EfficientTradingTrajectoryContinuous (dblT,
  248.                 dblEpochLiquidity * dblEpochUrgency * dblX * dblX / java.lang.Math.tanh (dblEpochUrgency *
  249.                     dblT), r1ToR1TransactionCostExpectation.evaluate (0.), 1. / dblEpochUrgency,
  250.                         dblEpochLiquidity * dblX / (dblT * dblEpochVolatility * java.lang.Math.sqrt (dblT)),
  251.                             r1ToR1Holdings, r1ToR1TradeRate, r1ToR1TransactionCostExpectation,
  252.                                 r1ToR1TransactionCostVariance);
  253.         } catch (java.lang.Exception e) {
  254.             e.printStackTrace();
  255.         }

  256.         return null;
  257.     }
  258. }