PowerVarianceObjectiveUtility.java

  1. package org.drip.execution.risk;

  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>PowerVarianceObjectiveUtility</i> implements the Mean-Power-Variance Objective Utility Function that
  79.  * needs to be optimized to extract the Optimal Execution Trajectory. The Exact Objective Function is of the
  80.  * Form:
  81.  *  
  82.  *              U[x] = E[x] + lambda * (V[x] ^p)
  83.  *  
  84.  *  where p is greater than 0.
  85.  *  
  86.  *  p = 1
  87.  *  
  88.  *  is the Regular Mean-Variance, and
  89.  *  
  90.  *  p = 0.5
  91.  *  
  92.  *  is VaR Minimization (L-VaR). The References are:
  93.  *
  94.  * <br><br>
  95.  *  <ul>
  96.  *      <li>
  97.  *          Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
  98.  *      </li>
  99.  *      <li>
  100.  *          Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
  101.  *              Risk</i> <b>3 (2)</b> 5-39
  102.  *      </li>
  103.  *      <li>
  104.  *          Almgren, R. (2003): Optimal Execution with Non-linear Impact Functions and Trading Enhanced Risk
  105.  *              <i>Applied Mathematical Finance</i> <b>10 (1)</b> 1-18
  106.  *      </li>
  107.  *      <li>
  108.  *          Artzner, P., F. Delbaen, J. M. Eber, and D. Heath (1999): Coherent Measures of Risk
  109.  *              <i>Mathematical Finance</i> <b>9</b> 203-228
  110.  *      </li>
  111.  *      <li>
  112.  *          Basak, S., and A. Shapiro (2001): Value-at-Risk Based Risk Management: Optimal Policies and Asset
  113.  *              Prices <i>Review of Financial Studies</i> <b>14</b> 371-405
  114.  *      </li>
  115.  *  </ul>
  116.  *
  117.  *  <br><br>
  118.  *  <ul>
  119.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  120.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  121.  *      <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>
  122.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/risk/README.md">Optimal Execution MVO Efficient Frontier</a></li>
  123.  *  </ul>
  124.  *
  125.  * @author Lakshmi Krishnamurthy
  126.  */

  127. public class PowerVarianceObjectiveUtility implements org.drip.execution.risk.ObjectiveUtility {
  128.     private double _dblRiskAversion = java.lang.Double.NaN;
  129.     private double _dblVarianceExponent = java.lang.Double.NaN;

  130.     /**
  131.      * Generate the Liquidity VaR Version of the Power Variance Utility Function
  132.      *
  133.      * @param dblRiskAversion The Risk Aversion Parameter
  134.      *
  135.      * @return The Liquidity VaR Version of the Power Variance Utility Function
  136.      */

  137.     public static final PowerVarianceObjectiveUtility LiquidityVaR (
  138.         final double dblRiskAversion)
  139.     {
  140.         try {
  141.             return new PowerVarianceObjectiveUtility (0.5, dblRiskAversion);
  142.         } catch (java.lang.Exception e) {
  143.             e.printStackTrace();
  144.         }

  145.         return null;
  146.     }

  147.     /**
  148.      * PowerVarianceObjectiveUtility Constructor
  149.      *
  150.      * @param dblVarianceExponent The Variance Exponent
  151.      * @param dblRiskAversion The Risk Aversion Parameter
  152.      *
  153.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  154.      */

  155.     public PowerVarianceObjectiveUtility (
  156.         final double dblVarianceExponent,
  157.         final double dblRiskAversion)
  158.         throws java.lang.Exception
  159.     {
  160.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblVarianceExponent = dblVarianceExponent) || 0. >
  161.             _dblVarianceExponent || !org.drip.numerical.common.NumberUtil.IsValid (_dblRiskAversion =
  162.                 dblRiskAversion) || 0. > _dblRiskAversion)
  163.             throw new java.lang.Exception ("PowerVarianceObjectiveUtility Constructor => Invalid Inputs!");
  164.     }

  165.     /**
  166.      * Retrieve the Risk Aversion Parameter
  167.      *
  168.      * @return The Risk Aversion Parameter
  169.      */

  170.     public double riskAversion()
  171.     {
  172.         return _dblRiskAversion;
  173.     }

  174.     /**
  175.      * Retrieve the Variance Exponent
  176.      *
  177.      * @return The Variance Exponent
  178.      */

  179.     public double varianceExponent()
  180.     {
  181.         return _dblVarianceExponent;
  182.     }

  183.     @Override public org.drip.execution.sensitivity.ControlNodesGreek sensitivity (
  184.         final org.drip.execution.sensitivity.TrajectoryControlNodesGreek tcngExpectation,
  185.         final org.drip.execution.sensitivity.TrajectoryControlNodesGreek tcngVariance)
  186.     {
  187.         if (null == tcngExpectation || null == tcngVariance) return null;

  188.         double[] adblVarianceJacobian = tcngVariance.innerJacobian();

  189.         if (null == adblVarianceJacobian) return null;

  190.         double dblVarianceValue = tcngVariance.value();

  191.         double[][] aadblVarianceHessian = tcngVariance.innerHessian();

  192.         double[] adblExpectationJacobian = tcngExpectation.innerJacobian();

  193.         double[][] aadblExpectationHessian = tcngExpectation.innerHessian();

  194.         int iNumControlNode = adblVarianceJacobian.length;
  195.         double[] adblObjectiveJacobian = new double[iNumControlNode];
  196.         double[][] aadblObjectiveHessian = new double[iNumControlNode][iNumControlNode];

  197.         double dblJacobianMultiplier = _dblVarianceExponent * _dblRiskAversion * java.lang.Math.pow
  198.             (dblVarianceValue, _dblVarianceExponent - 1.);

  199.         double dblJacobianProductMultiplier = _dblVarianceExponent * (_dblVarianceExponent - 1.) *
  200.             _dblRiskAversion * java.lang.Math.pow (dblVarianceValue, _dblVarianceExponent - 2.);

  201.         for (int i = 0; i < iNumControlNode; ++i) {
  202.             adblObjectiveJacobian[i] = adblExpectationJacobian[i] + dblJacobianMultiplier *
  203.                 adblVarianceJacobian[i];

  204.             for (int j = 0; j < iNumControlNode; ++j)
  205.                 aadblObjectiveHessian[i][j] = aadblExpectationHessian[i][j] + dblJacobianProductMultiplier *
  206.                     adblVarianceJacobian[i] * adblVarianceJacobian[j] + dblJacobianMultiplier *
  207.                         aadblVarianceHessian[i][j];
  208.         }

  209.         try {
  210.             return new org.drip.execution.sensitivity.ControlNodesGreek (tcngExpectation.value() +
  211.                 _dblRiskAversion * java.lang.Math.pow (dblVarianceValue, _dblVarianceExponent),
  212.                     adblObjectiveJacobian, aadblObjectiveHessian);
  213.         } catch (java.lang.Exception e) {
  214.             e.printStackTrace();
  215.         }
  216.         return null;
  217.     }
  218. }