ContinuousCoordinatedVariationDeterministic.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>ContinuousCoordinatedVariationDeterministic</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. 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 ContinuousCoordinatedVariationDeterministic extends
  117.     org.drip.execution.nonadaptive.StaticOptimalSchemeContinuous {

  118.     /**
  119.      * Create the Standard ContinuousCoordinatedVariationDeterministic 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 ContinuousCoordinatedVariationDeterministic Instance
  127.      */

  128.     public static final ContinuousCoordinatedVariationDeterministic 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 ContinuousCoordinatedVariationDeterministic (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 ContinuousCoordinatedVariationDeterministic (
  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.         final org.drip.function.definition.R1ToR1 r1ToR1TradeRate = new org.drip.function.definition.R1ToR1
  195.             (null)
  196.         {
  197.             @Override public double evaluate (
  198.                 final double dblTime)
  199.                 throws java.lang.Exception
  200.             {
  201.                 if (!org.drip.numerical.common.NumberUtil.IsValid (dblTime))
  202.                     throw new java.lang.Exception
  203.                         ("ContinuousCoordinatedVariationDeterministic::TradeRate::evaluate => Invalid Inputs");

  204.                 org.drip.function.definition.R1ToR1 r1ToR1VarianceFunction = new
  205.                     org.drip.function.definition.R1ToR1 (null) {
  206.                     @Override public double evaluate (
  207.                         final double dblForwardTime)
  208.                         throws java.lang.Exception
  209.                     {
  210.                         double dblForwardVolatility = r1ToR1VolatilityFunction.evaluate (dblForwardTime);

  211.                         return dblForwardVolatility * dblForwardVolatility;
  212.                     }
  213.                 };

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

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

  217.                 return dblKappa * dblX / java.lang.Math.tanh (dblKappa * r1ToR1VarianceFunction.integrate
  218.                     (dblTime, dblT) / dblVolatility * dblVolatility);
  219.             }
  220.         };

  221.         final org.drip.function.definition.R1ToR1 r1ToR1TransactionCostExpectationRate = new
  222.             org.drip.function.definition.R1ToR1 (null) {
  223.             @Override public double evaluate (
  224.                 final double dblTime)
  225.                 throws java.lang.Exception
  226.             {
  227.                 double dblTradeRate = r1ToR1TradeRate.evaluate (dblTime);

  228.                 if (!org.drip.numerical.common.NumberUtil.IsValid (dblTradeRate))
  229.                     throw new java.lang.Exception
  230.                         ("ContinuousCoordinatedVariationStochastic::ExpectationRate::evaluate => Invalid Inputs");

  231.                 return bprlTemporary.liquidityFunction (dblTime).slope() * dblTradeRate * dblTradeRate;
  232.             }
  233.         };

  234.         org.drip.function.definition.R1ToR1 r1ToR1TransactionCostExpectation = new
  235.             org.drip.function.definition.R1ToR1 (null) {
  236.             @Override public double evaluate (
  237.                 final double dblTime)
  238.                 throws java.lang.Exception
  239.             {
  240.                 return r1ToR1TransactionCostExpectationRate.integrate (dblTime, dblT);
  241.             }
  242.         };

  243.         final org.drip.function.definition.R1ToR1 r1ToR1TransactionCostVarianceRate = new
  244.             org.drip.function.definition.R1ToR1 (null) {
  245.             @Override public double evaluate (
  246.                 final double dblTime)
  247.                 throws java.lang.Exception
  248.             {
  249.                 double dblHoldings = r1ToR1Holdings.evaluate (dblTime);

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

  251.                 return dblVolatility * dblVolatility * dblHoldings * dblHoldings;
  252.             }
  253.         };

  254.         org.drip.function.definition.R1ToR1 r1ToR1TransactionCostVariance = new
  255.             org.drip.function.definition.R1ToR1 (null) {
  256.             @Override public double evaluate (
  257.                 final double dblTime)
  258.                 throws java.lang.Exception
  259.             {
  260.                 return r1ToR1TransactionCostVarianceRate.integrate (dblTime, dblT);
  261.             }
  262.         };

  263.         try {
  264.             return new org.drip.execution.optimum.EfficientTradingTrajectoryContinuous (dblT,
  265.                 dblEpochLiquidity * dblEpochUrgency * dblX * dblX / java.lang.Math.tanh (dblEpochUrgency *
  266.                     dblT), r1ToR1TransactionCostExpectation.evaluate (0.), 1. / dblEpochUrgency,
  267.                         dblEpochLiquidity * dblX / (dblT * dblEpochVolatility * java.lang.Math.sqrt (dblT)),
  268.                             r1ToR1Holdings, r1ToR1TradeRate, r1ToR1TransactionCostExpectation,
  269.                                 r1ToR1TransactionCostVariance);
  270.         } catch (java.lang.Exception e) {
  271.             e.printStackTrace();
  272.         }

  273.         return null;
  274.     }
  275. }