ConstantTradingEnhancedVolatility.java

  1. package org.drip.sample.almgren2003;

  2. import org.drip.execution.capture.*;
  3. import org.drip.execution.dynamics.*;
  4. import org.drip.execution.impact.ParticipationRateLinear;
  5. import org.drip.execution.nonadaptive.ContinuousConstantTradingEnhanced;
  6. import org.drip.execution.optimum.EfficientTradingTrajectoryContinuous;
  7. import org.drip.execution.profiletime.UniformParticipationRateLinear;
  8. import org.drip.execution.strategy.DiscreteTradingTrajectory;
  9. import org.drip.function.definition.R1ToR1;
  10. import org.drip.measure.gaussian.R1UnivariateNormal;
  11. import org.drip.numerical.common.FormatUtil;
  12. import org.drip.service.env.EnvManager;

  13. /*
  14.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  15.  */

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

  88. /**
  89.  * <i>ConstantTradingEnhancedVolatility</i> demonstrates the Generation of the Optimal Trading Trajectory
  90.  * under the Condition of Constant Trading Enhanced Volatility. The References are:
  91.  *
  92.  * <br><br>
  93.  *  <ul>
  94.  *      <li>
  95.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  96.  *      </li>
  97.  *
  98.  *      <li>
  99.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  100.  *              Risk</i> <b>3 (2)</b> 5-39
  101.  *      </li>
  102.  *
  103.  *      <li>
  104.  *          Almgren, R. (2003): Optimal Execution with Nonlinear Impact Functions and Trading-Enhanced Risk
  105.  *              <i>Applied Mathematical Finance</i> <b>10 (1)</b> 1-18.
  106.  *      </li>
  107.  *
  108.  *      <li>
  109.  *          Almgren, R., and N. Chriss (2003): Bidding Principles <i>Risk</i> 97-102
  110.  *      </li>
  111.  *
  112.  *      <li>
  113.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  114.  *              Markets</i> <b>1</b> 1-50
  115.  *      </li>
  116.  *  </ul>
  117.  *
  118.  * <br><br>
  119.  *  <ul>
  120.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  121.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  122.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  123.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/almgren2003/README.md">Almgren (2003) Power Law Liquidity</a></li>
  124.  *  </ul>
  125.  * <br><br>
  126.  *
  127.  * @author Lakshmi Krishnamurthy
  128.  */

  129. public class ConstantTradingEnhancedVolatility {

  130.     public static final void main (
  131.         final String[] astrArgs)
  132.         throws Exception
  133.     {
  134.         EnvManager.InitEnv (
  135.             "",
  136.             true
  137.         );

  138.         double dblEta = 5.e-06;
  139.         double dblAlpha = 1.;
  140.         double dblSigma = 1.;
  141.         double dblLambda = 1.e-05;
  142.         double dblX = 100000.;
  143.         double dblT = 5.;
  144.         int iNumInterval = 50000;

  145.         ArithmeticPriceEvolutionParameters apep = ArithmeticPriceEvolutionParametersBuilder.TradingEnhancedVolatility (
  146.             dblSigma,
  147.             new UniformParticipationRateLinear (ParticipationRateLinear.SlopeOnly (dblEta)),
  148.             new UniformParticipationRateLinear (
  149.                 new ParticipationRateLinear (
  150.                     dblAlpha,
  151.                     0.
  152.                 )
  153.             )
  154.         );

  155.         ContinuousConstantTradingEnhanced ccte = ContinuousConstantTradingEnhanced.Standard (
  156.             dblX,
  157.             dblT,
  158.             apep,
  159.             dblLambda
  160.         );

  161.         EfficientTradingTrajectoryContinuous ettc = (EfficientTradingTrajectoryContinuous) ccte.generate();

  162.         R1ToR1 r1ToR1Holdings = ettc.holdings();

  163.         double[] adblHoldings = new double[iNumInterval];
  164.         double[] adblExecutionTime = new double[iNumInterval];

  165.         for (int i = 1; i <= iNumInterval; ++i) {
  166.             adblExecutionTime[i - 1] = dblT * i / iNumInterval;

  167.             adblHoldings[i - 1] = r1ToR1Holdings.evaluate (adblExecutionTime[i - 1]);
  168.         }

  169.         DiscreteTradingTrajectory dtt = DiscreteTradingTrajectory.Standard (
  170.             adblExecutionTime,
  171.             adblHoldings
  172.         );

  173.         TrajectoryShortfallEstimator tse = new TrajectoryShortfallEstimator (dtt);

  174.         R1UnivariateNormal r1un = tse.totalCostDistributionSynopsis (apep);

  175.         double[] adblTradeList = dtt.tradeList();

  176.         for (int i = 1; i < adblExecutionTime.length; ++i) {
  177.             System.out.println ("\t| " +
  178.                 FormatUtil.FormatDouble (adblExecutionTime[i], 1, 4, 1.) + " => " +
  179.                 FormatUtil.FormatDouble (adblHoldings[i] / dblX, 2, 4, 100.) + "% | " +
  180.                 FormatUtil.FormatDouble (adblTradeList[i - 1] / dblX, 1, 4, 100.) + "% ||"
  181.             );
  182.         }

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

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

  185.         System.out.println ("\t|  TRANSACTION COST RECONCILIATION: EXPLICIT vs. ALMGREN 2003  ||");

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

  187.         System.out.println (
  188.             "\t| Transaction Cost Expectation         : " +
  189.             FormatUtil.FormatDouble (r1un.mean(), 6, 1, 1.) + " | " +
  190.             FormatUtil.FormatDouble (ettc.transactionCostExpectation(), 6, 1, 1.) + " ||"
  191.         );

  192.         System.out.println (
  193.             "\t| Transaction Cost Variance (X 10^-06) : " +
  194.             FormatUtil.FormatDouble (r1un.variance(), 6, 1, 1.e-06) + " | " +
  195.             FormatUtil.FormatDouble (ettc.transactionCostVariance(), 6, 1, 1.e-06) + " ||"
  196.         );

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

  198.         EnvManager.TerminateEnv();
  199.     }
  200. }