ConcaveImpactNoDrift.java

  1. package org.drip.sample.execution;

  2. import org.drip.execution.dynamics.*;
  3. import org.drip.execution.impact.*;
  4. import org.drip.execution.nonadaptive.StaticOptimalSchemeDiscrete;
  5. import org.drip.execution.optimum.EfficientTradingTrajectoryDiscrete;
  6. import org.drip.execution.parameters.*;
  7. import org.drip.execution.profiletime.*;
  8. import org.drip.execution.risk.MeanVarianceObjectiveUtility;
  9. import org.drip.execution.strategy.*;
  10. import org.drip.function.r1tor1.FlatUnivariate;
  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) 2019 Lakshmi Krishnamurthy
  18.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  19.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  20.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  21.  *
  22.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  23.  *      calculations, valuation adjustment, and portfolio construction within and across fixed income,
  24.  *      credit, commodity, equity, FX, and structured products.
  25.  *  
  26.  *      https://lakshmidrip.github.io/DROP/
  27.  *  
  28.  *  DROP is composed of three modules:
  29.  *  
  30.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  31.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  32.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  33.  *
  34.  *  DROP Analytics Core implements libraries for the following:
  35.  *  - Fixed Income Analytics
  36.  *  - Asset Backed Analytics
  37.  *  - XVA Analytics
  38.  *  - Exposure and Margin Analytics
  39.  *
  40.  *  DROP Portfolio Core implements libraries for the following:
  41.  *  - Asset Allocation Analytics
  42.  *  - Transaction Cost Analytics
  43.  *
  44.  *  DROP Numerical Core implements libraries for the following:
  45.  *  - Statistical Learning
  46.  *  - Numerical Optimizer
  47.  *  - Spline Builder
  48.  *  - Algorithm Support
  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>ConcaveImpactNoDrift</i> generates the Trade/Holdings List of Optimal Execution Schedule based on the
  79.  * Concave Power Law Evolution Walk Parameters specified. The Generation follows a Numerical Optimizer
  80.  * Scheme, as opposed to the Closed Form; it also excludes the Impact of Drift. 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
  89.  *              Risk</i> <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.  *          Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
  100.  *              Markets</i> <b>1</b> 1-50
  101.  *      </li>
  102.  *  </ul>
  103.  *
  104.  * <br><br>
  105.  *  <ul>
  106.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  107.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics Library</a></li>
  108.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  109.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/execution/README.md">Execution</a></li>
  110.  *  </ul>
  111.  * <br><br>
  112.  *
  113.  * @author Lakshmi Krishnamurthy
  114.  */

  115. public class ConcaveImpactNoDrift {

  116.     public static final void main (
  117.         final String[] astrArgs)
  118.         throws Exception
  119.     {
  120.         EnvManager.InitEnv ("");

  121.         double dblS0 = 50.;
  122.         double dblDailyVolume = 1000000.;
  123.         double dblBidAskSpread = 0.;
  124.         double dblPermanentImpactFactor = 0.;
  125.         double dblTemporaryImpactFactor = 0.01;
  126.         double dblK = 0.5;
  127.         double dblDailyVolumeExecutionFactor = 0.1;
  128.         double dblDrift = 0.;
  129.         double dblVolatility = 1.;
  130.         double dblX = 100000.;
  131.         double dblFinishTime = 0.04;
  132.         int iNumInterval = 2;
  133.         double dblLambdaU = 3.e-03;

  134.         PriceMarketImpactPower pmip = new PriceMarketImpactPower (
  135.             new AssetTransactionSettings (
  136.                 dblS0,
  137.                 dblDailyVolume,
  138.                 dblBidAskSpread
  139.             ),
  140.             dblPermanentImpactFactor,
  141.             dblTemporaryImpactFactor,
  142.             dblDailyVolumeExecutionFactor,
  143.             dblK
  144.         );

  145.         LinearPermanentExpectationParameters lpep = ArithmeticPriceEvolutionParametersBuilder.Almgren2003 (
  146.             new ArithmeticPriceDynamicsSettings (
  147.                 dblDrift,
  148.                 new FlatUnivariate (dblVolatility),
  149.                 0.
  150.             ),
  151.             new UniformParticipationRateLinear ((ParticipationRateLinear) pmip.permanentTransactionFunction()),
  152.             new UniformParticipationRate ((ParticipationRatePower) pmip.temporaryTransactionFunction())
  153.         );

  154.         DiscreteTradingTrajectoryControl dttc = DiscreteTradingTrajectoryControl.FixedInterval (
  155.             new OrderSpecification (
  156.                 dblX,
  157.                 dblFinishTime
  158.             ),
  159.             iNumInterval
  160.         );

  161.         EfficientTradingTrajectoryDiscrete ettd = (EfficientTradingTrajectoryDiscrete) new StaticOptimalSchemeDiscrete (
  162.             dttc,
  163.             lpep,
  164.             new MeanVarianceObjectiveUtility (dblLambdaU)
  165.         ).generate();

  166.         double[] adblExecutionTimeNode = ettd.executionTimeNode();

  167.         double[] adblTradeList = ettd.tradeList();

  168.         double[] adblHoldings = ettd.holdings();

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

  170.         System.out.println ("\t| Optimal Trading Trajectory  ||");

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

  172.         System.out.println ("\t|     L -> R:                 ||");

  173.         System.out.println ("\t|        Time Node            ||");

  174.         System.out.println ("\t|        Holdings             ||");

  175.         System.out.println ("\t|        Trade Amount         ||");

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

  177.         for (int i = 0; i <= iNumInterval; ++i) {
  178.             if (i == 0)
  179.                 System.out.println (
  180.                     "\t|" + FormatUtil.FormatDouble (adblExecutionTimeNode[i], 1, 3, 1.) + " =>" +
  181.                     FormatUtil.FormatDouble (adblHoldings[i], 7, 1, 1.) + " | " +
  182.                     FormatUtil.FormatDouble (0., 6, 1, 1.) + " ||"
  183.                 );
  184.             else
  185.                 System.out.println (
  186.                     "\t|" + FormatUtil.FormatDouble (adblExecutionTimeNode[i], 1, 3, 1.) + " =>" +
  187.                     FormatUtil.FormatDouble (adblHoldings[i], 7, 1, 1.) + " | " +
  188.                     FormatUtil.FormatDouble (adblTradeList[i - 1], 6, 1, 1.) + " ||"
  189.                 );
  190.         }

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

  192.         EnvManager.TerminateEnv();
  193.     }
  194. }