ExpectedExcessReturnsWeights.java

  1. package org.drip.sample.idzorek;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.portfolioconstruction.allocator.ForwardReverseHoldingsAllocation;
  4. import org.drip.portfolioconstruction.asset.*;
  5. import org.drip.service.env.EnvManager;

  6. /*
  7.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  8.  */

  9. /*!
  10.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  13.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  14.  *
  15.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  16.  *      calculations, valuation adjustment, and portfolio construction within and across fixed income,
  17.  *      credit, commodity, equity, FX, and structured products.
  18.  *  
  19.  *      https://lakshmidrip.github.io/DROP/
  20.  *  
  21.  *  DROP is composed of three modules:
  22.  *  
  23.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  24.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  25.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  26.  *
  27.  *  DROP Analytics Core implements libraries for the following:
  28.  *  - Fixed Income Analytics
  29.  *  - Asset Backed Analytics
  30.  *  - XVA Analytics
  31.  *  - Exposure and Margin Analytics
  32.  *
  33.  *  DROP Portfolio Core implements libraries for the following:
  34.  *  - Asset Allocation Analytics
  35.  *  - Transaction Cost Analytics
  36.  *
  37.  *  DROP Numerical Core implements libraries for the following:
  38.  *  - Statistical Learning
  39.  *  - Numerical Optimizer
  40.  *  - Spline Builder
  41.  *  - Algorithm Support
  42.  *
  43.  *  Documentation for DROP is Spread Over:
  44.  *
  45.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  46.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  47.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  48.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  49.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  50.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  51.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  52.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  53.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  54.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  55.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  56.  *
  57.  *  Licensed under the Apache License, Version 2.0 (the "License");
  58.  *      you may not use this file except in compliance with the License.
  59.  *  
  60.  *  You may obtain a copy of the License at
  61.  *      http://www.apache.org/licenses/LICENSE-2.0
  62.  *  
  63.  *  Unless required by applicable law or agreed to in writing, software
  64.  *      distributed under the License is distributed on an "AS IS" BASIS,
  65.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  66.  *  
  67.  *  See the License for the specific language governing permissions and
  68.  *      limitations under the License.
  69.  */

  70. /**
  71.  * <i>ExpectedExcessReturnsWeights</i> reconciles the Expected Returns and the corresponding Weights for
  72.  * different Input Asset Distributions using the Black-Litterman Model Process. The References are:
  73.  *  
  74.  * <br><br>
  75.  *  <ul>
  76.  *      <li>
  77.  *          He. G., and R. Litterman (1999): The Intuition behind the Black-Litterman Model Portfolios,
  78.  *              Goldman Sachs Asset Management
  79.  *      </li>
  80.  *      <li>
  81.  *          Idzorek, T. (2005): A Step-by-Step Guide to the Black-Litterman Model: Incorporating User
  82.  *              Specified Confidence Levels, Ibbotson Associates, Chicago
  83.  *      </li>
  84.  *  </ul>
  85.  *  
  86.  * <br><br>
  87.  *  <ul>
  88.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  89.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AssetAllocationAnalyticsLibrary.md">Asset Allocation Analytics Library</a></li>
  90.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  91.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/idzorek/README.md">Idzorek (2005) User Confidence Setting</a></li>
  92.  *  </ul>
  93.  * <br><br>
  94.  *
  95.  * @author Lakshmi Krishnamurthy
  96.  */

  97. public class ExpectedExcessReturnsWeights
  98. {

  99.     private static final void ForwardOptimizationWeights (
  100.         final ForwardReverseHoldingsAllocation forwardReverseOptimizationOutput,
  101.         final double[] weightReconcilerArray,
  102.         final int preDecimalDigits,
  103.         final int postDecimalDigits,
  104.         final String header)
  105.     {
  106.         Portfolio optimalPortfolio = forwardReverseOptimizationOutput.optimalPortfolio();

  107.         String[] assetIDArray = optimalPortfolio.assetIDArray();

  108.         double[] weightArray = optimalPortfolio.weightArray();

  109.         AssetComponent highestWeightAsset = optimalPortfolio.highestWeightAsset();

  110.         AssetComponent lowestWeightAsset = optimalPortfolio.lowestWeightAsset();

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

  112.         System.out.println (header);

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

  114.         System.out.println ("\t|                  ID               =>  CALC  | VERIFY ||");

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

  116.         for (int assetIndex = 0;
  117.             assetIndex < weightArray.length;
  118.             ++assetIndex)
  119.         {
  120.             System.out.println (
  121.                 "\t| [" + assetIDArray[assetIndex] + "] => " +
  122.                 FormatUtil.FormatDouble (
  123.                     weightArray[assetIndex], preDecimalDigits, postDecimalDigits, 100.
  124.                 ) + "% | " +
  125.                 FormatUtil.FormatDouble (
  126.                     weightReconcilerArray[assetIndex], preDecimalDigits, postDecimalDigits, 100.
  127.                 ) + "% ||"
  128.             );
  129.         }

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

  131.         System.out.println (
  132.             "\t| HIGH : " + highestWeightAsset.id() + " => "+ FormatUtil.FormatDouble (
  133.                 highestWeightAsset.amount(), preDecimalDigits, postDecimalDigits, 100.
  134.             ) + "%     ||"
  135.         );

  136.         System.out.println (
  137.             "\t| LOW  : " + lowestWeightAsset.id() + " => "+ FormatUtil.FormatDouble (
  138.                 lowestWeightAsset.amount(), preDecimalDigits, postDecimalDigits, 100.
  139.             ) + "%     ||"
  140.         );

  141.         System.out.println ("\t|------------------------------------------------------||\n");
  142.     }

  143.     public static final void main (
  144.         final String[] argumentArray)
  145.         throws Exception
  146.     {
  147.         EnvManager.InitEnv ("");

  148.         double riskAversion = 3.07;
  149.         String[] assetIDArray = new String[]
  150.         {
  151.             "US BONDS                       ",
  152.             "INTERNATIONAL BONDS            ",
  153.             "US LARGE GROWTH                ",
  154.             "US LARGE VALUE                 ",
  155.             "US SMALL GROWTH                ",
  156.             "US SMALL VALUE                 ",
  157.             "INTERNATIONAL DEVELOPED EQUITY ",
  158.             "INTERNATIONAL EMERGING EQUITY  "
  159.         };
  160.         double[] assetEquilibriumWeightArray = new double[]
  161.         {
  162.             0.1934,
  163.             0.2613,
  164.             0.1209,
  165.             0.1209,
  166.             0.0134,
  167.             0.0134,
  168.             0.2418,
  169.             0.0349
  170.         };
  171.         double[][] assetExcessReturnsCovarianceMatrix = new double[][]
  172.         {
  173.             { 0.001005,  0.001328, -0.000579, -0.000675,  0.000121,  0.000128, -0.000445, -0.000437},
  174.             { 0.001328,  0.007277, -0.001307, -0.000610, -0.002237, -0.000989,  0.001442, -0.001535},
  175.             {-0.000579, -0.001307,  0.059582,  0.027588,  0.063497,  0.023036,  0.032967,  0.048039},
  176.             {-0.000675, -0.000610,  0.027588,  0.029609,  0.026572,  0.021465,  0.020697,  0.029854},
  177.             { 0.000121, -0.002237,  0.063497,  0.026572,  0.102488,  0.042744,  0.039943,  0.065994},
  178.             { 0.000128, -0.000989,  0.023036,  0.021465,  0.042744,  0.032056,  0.019881,  0.032235},
  179.             {-0.000445,  0.001442,  0.032967,  0.020697,  0.039943,  0.019881,  0.028355,  0.035064},
  180.             {-0.000437, -0.001535,  0.048039,  0.029854,  0.065994,  0.032235,  0.035064,  0.079958}
  181.         };
  182.         double[] assetSpaceHistoricalReturnsArray = new double[]
  183.         {
  184.              0.0315,
  185.              0.0175,
  186.             -0.0639,
  187.             -0.0286,
  188.             -0.0675,
  189.             -0.0054,
  190.             -0.0675,
  191.             -0.0526
  192.         };
  193.         double[] assetSpaceCAPMReturnsArray = new double[]
  194.         {
  195.             0.0008,
  196.             0.0067,
  197.             0.0641,
  198.             0.0408,
  199.             0.0743,
  200.             0.0370,
  201.             0.0480,
  202.             0.0660
  203.         };
  204.         double[] assetSpaceGSMIReturnsArray = new double[]
  205.         {
  206.              0.0002,
  207.              0.0018,
  208.              0.0557,
  209.              0.0339,
  210.              0.0659,
  211.              0.0316,
  212.              0.0392,
  213.              0.0560
  214.         };
  215.         double[] historicalPortfolioWeightReconcilerArray = new double[]
  216.         {
  217.              11.4432,
  218.              -1.0459,
  219.               0.5459,
  220.              -0.0529,
  221.              -0.6052,
  222.               0.8147,
  223.              -1.0436,
  224.               0.1459
  225.         };
  226.         double[] capmGSMIPortfolioWeightReconcilerArray = new double[]
  227.         {
  228.               0.2133,
  229.               0.0519,
  230.               0.1080,
  231.               0.1082,
  232.               0.0373,
  233.              -0.0049,
  234.               0.1710,
  235.               0.0214
  236.         };

  237.         double[] impliedEquilibriumExcessReturnsArray = ForwardReverseHoldingsAllocation.Reverse (
  238.             Portfolio.Standard (
  239.                 assetIDArray,
  240.                 assetEquilibriumWeightArray
  241.             ),
  242.             assetExcessReturnsCovarianceMatrix,
  243.             riskAversion
  244.         ).expectedAssetExcessReturnsArray();

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

  246.         System.out.println ("\t|               STARTING RETURNS SOURCES RECONCILIATION               ||");

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

  248.         System.out.println ("\t|                ID                 =>  HIST  | GSMI  | CAPM  | IMPL  ||");

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

  250.         for (int assetIndex = 0;
  251.             assetIndex < impliedEquilibriumExcessReturnsArray.length;
  252.             ++assetIndex)
  253.         {
  254.             System.out.println (
  255.                 "\t| [" + assetIDArray[assetIndex] + "] => " +
  256.                 FormatUtil.FormatDouble (assetSpaceHistoricalReturnsArray[assetIndex], 1, 2, 100.) + "% |" +
  257.                 FormatUtil.FormatDouble (assetSpaceGSMIReturnsArray[assetIndex], 1, 2, 100.) + "% |" +
  258.                 FormatUtil.FormatDouble (assetSpaceCAPMReturnsArray[assetIndex], 1, 2, 100.) + "% |" +
  259.                 FormatUtil.FormatDouble (
  260.                     riskAversion * impliedEquilibriumExcessReturnsArray[assetIndex], 1, 2, 100.
  261.                 ) + "% ||"
  262.             );
  263.         }

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

  265.         ForwardOptimizationWeights (
  266.             ForwardReverseHoldingsAllocation.Forward (
  267.                 assetIDArray,
  268.                 assetSpaceHistoricalReturnsArray,
  269.                 assetExcessReturnsCovarianceMatrix,
  270.                 riskAversion
  271.             ),
  272.             historicalPortfolioWeightReconcilerArray,
  273.             4,
  274.             0,
  275.             "\t|             HISTORICAL WEIGHTS RECONCILER            ||"
  276.         );

  277.         ForwardOptimizationWeights (
  278.             ForwardReverseHoldingsAllocation.Forward (
  279.                 assetIDArray,
  280.                 assetSpaceGSMIReturnsArray,
  281.                 assetExcessReturnsCovarianceMatrix,
  282.                 riskAversion
  283.             ),
  284.             capmGSMIPortfolioWeightReconcilerArray,
  285.             2,
  286.             1,
  287.             "\t|              CAPM GSMI WEIGHTS RECONCILER            ||"
  288.         );

  289.         ForwardOptimizationWeights (
  290.             ForwardReverseHoldingsAllocation.Forward (
  291.                 assetIDArray,
  292.                 assetSpaceCAPMReturnsArray,
  293.                 assetExcessReturnsCovarianceMatrix,
  294.                 riskAversion
  295.             ),
  296.             assetEquilibriumWeightArray,
  297.             2,
  298.             1,
  299.             "\t|             EQUILIBRIUM WEIGHTS RECONCILER           ||"
  300.         );

  301.         EnvManager.TerminateEnv();
  302.     }
  303. }