DaJagannathan2005d.java

  1. package org.drip.sample.blacklitterman;

  2. import org.drip.measure.statistics.MultivariateMoments;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.numerical.linearalgebra.Matrix;
  5. import org.drip.portfolioconstruction.allocator.*;
  6. import org.drip.portfolioconstruction.asset.AssetComponent;
  7. import org.drip.portfolioconstruction.params.AssetUniverseStatisticalProperties;
  8. import org.drip.service.env.EnvManager;

  9. /*
  10.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  11.  */

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

  84. /**
  85.  * <i>DaJagannathan2005d</i> reconciles the Outputs of the Black-Litterman Model Process. The References are:
  86.  *  
  87.  * <br><br>
  88.  *  <ul>
  89.  *      <li>
  90.  *          Da, Z., and R. Jagannathan (2005): https://www3.nd.edu/~zda/TeachingNote_Black-Litterman.pdf
  91.  *      </li>
  92.  *      <li>
  93.  *          He. G., and R. Litterman (1999): <i>The Intuition behind the Black-Litterman Model Portfolios</i>
  94.  *              <b>Goldman Sachs Asset Management</b>
  95.  *      </li>
  96.  *  </ul>
  97.  *  
  98.  * <br><br>
  99.  *  <ul>
  100.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  101.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
  102.  *      <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>
  103.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/blacklitterman/README.md">Canonical Black Litterman and Extensions</a></li>
  104.  *  </ul>
  105.  * <br><br>
  106.  *
  107.  * @author Lakshmi Krishnamurthy
  108.  */

  109. public class DaJagannathan2005d {

  110.     public static final void main (
  111.         final String[] astArgs)
  112.         throws Exception
  113.     {
  114.         EnvManager.InitEnv (
  115.             "",
  116.             true
  117.         );

  118.         String[] astrID = new String[] {
  119.             "CORPORATE BOND     ",
  120.             "LONG TERM GOVVIE   ",
  121.             "MEDIUM TERM GOVVIE ",
  122.             "STRONG BUY EQUITY  ",
  123.             "BUY EQUITY         ",
  124.             "NEUTRAL EQUITY     ",
  125.             "SELL EQUITY        ",
  126.             "STRONG SELL EQUITY "
  127.         };

  128.         double[][] aadblHistoricalCovariance = new double[][] {
  129.             {0.0050, 0.0047, 0.0024, 0.0036, 0.0023, 0.0031, 0.0032, 0.0030},
  130.             {0.0047, 0.0062, 0.0030, 0.0033, 0.0016, 0.0024, 0.0026, 0.0020},
  131.             {0.0024, 0.0030, 0.0020, 0.0015, 0.0006, 0.0009, 0.0012, 0.0008},
  132.             {0.0036, 0.0033, 0.0015, 0.0468, 0.0354, 0.0371, 0.0379, 0.0414},
  133.             {0.0023, 0.0016, 0.0006, 0.0354, 0.0354, 0.0323, 0.0317, 0.0371},
  134.             {0.0031, 0.0024, 0.0009, 0.0371, 0.0323, 0.0349, 0.0342, 0.0364},
  135.             {0.0032, 0.0026, 0.0012, 0.0379, 0.0317, 0.0342, 0.0432, 0.0384},
  136.             {0.0030, 0.0020, 0.0008, 0.0414, 0.0371, 0.0364, 0.0384, 0.0498}
  137.         };

  138.         double[] adblHistoricalReturn = new double[] {
  139.             0.0595,
  140.             0.0553,
  141.             0.0545,
  142.             0.1302,
  143.             0.1114,
  144.             0.1116,
  145.             0.1217,
  146.             0.1220
  147.         };

  148.         double[] adblHistoricalOptimalWeight = new double[] {
  149.              0.2154,
  150.             -0.5434,
  151.              1.1976,
  152.              0.0624,
  153.              0.0808,
  154.             -0.0450,
  155.              0.0472,
  156.             -0.0149
  157.         };

  158.         double[] adblMarketWeight = new double[] {
  159.             0.1667,
  160.             0.0833,
  161.             0.0833,
  162.             0.2206,
  163.             0.1184,
  164.             0.1065,
  165.             0.0591,
  166.             0.1622
  167.         };

  168.         double[] adblMarketImpliedReturnReconciler = new double[] {
  169.             0.0335,
  170.             0.0332,
  171.             0.0315,
  172.             0.0584,
  173.             0.0539,
  174.             0.0544,
  175.             0.0554,
  176.             0.0585
  177.         };

  178.         double dblRiskFreeRate = 0.03;
  179.         double[] adblAdjustedHistoricalReturn = new double[adblHistoricalReturn.length];

  180.         for (int i = 0; i < adblHistoricalReturn.length; ++i)
  181.             adblAdjustedHistoricalReturn[i] = adblHistoricalReturn[i] - dblRiskFreeRate;

  182.         HoldingsAllocation op = new QuadraticMeanVarianceOptimizer().allocate (
  183.             new HoldingsAllocationControl (
  184.                 astrID,
  185.                 CustomRiskUtilitySettings.RiskTolerant (0.078),
  186.                 EqualityConstraintSettings.FullyInvested()
  187.             ),
  188.             AssetUniverseStatisticalProperties.FromMultivariateMetrics (
  189.                 MultivariateMoments.Standard (
  190.                     astrID,
  191.                     adblAdjustedHistoricalReturn,
  192.                     aadblHistoricalCovariance
  193.                 )
  194.             )
  195.         );

  196.         AssetComponent[] aAC = op.optimalPortfolio().assetComponentArray();

  197.         double[] adblMarketImpliedReturn = Matrix.Product (
  198.             aadblHistoricalCovariance,
  199.             adblMarketWeight
  200.         );

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

  202.         System.out.println ("\t|                                HISTORICAL COVARIANCE MATRIX                                 ||");

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

  204.         for (int i = 0; i < astrID.length; ++i) {
  205.             String strDump = "\t| " + astrID[i] + " ";

  206.             for (int j = 0; j < astrID.length; ++j)
  207.                 strDump += "|" + FormatUtil.FormatDouble (aadblHistoricalCovariance[i][j], 1, 4, 1.) + " ";

  208.             System.out.println (strDump + "||");
  209.         }

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

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

  212.         System.out.println ("\t||         MARKET WEIGHT           ||");

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

  214.         for (int i = 0; i < adblMarketWeight.length; ++i)
  215.             System.out.println (
  216.                 "\t||  " + astrID[i] + " => " +
  217.                 FormatUtil.FormatDouble (adblMarketWeight[i], 2, 2, 100.) + "% ||"
  218.             );

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

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

  221.         System.out.println ("\t||       HISTORICAL RETURNS        ||");

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

  223.         for (int i = 0; i < adblHistoricalReturn.length; ++i)
  224.             System.out.println (
  225.                 "\t||  " + astrID[i] + " => " +
  226.                 FormatUtil.FormatDouble (adblHistoricalReturn[i], 2, 2, 100.) + "% ||"
  227.             );

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

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

  230.         System.out.println ("\t||      HISTORICAL PARAM OPTIMAL WEIGHTS       ||");

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

  232.         System.out.println ("\t||         ASSET        =>   CALC   |   PAPER  ||");

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

  234.         for (int i = 0; i < aAC.length; ++i)
  235.             System.out.println (
  236.                 "\t||  " + astrID[i] + " => " +
  237.                 FormatUtil.FormatDouble (adblHistoricalOptimalWeight[i], 3, 2, 100.) + "% | " +
  238.                 FormatUtil.FormatDouble (aAC[i].amount(), 3, 2, 100.) + "% ||"
  239.             );

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

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

  242.         System.out.println ("\t||         MARKET IMPLIED RETURNS         ||");

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

  244.         System.out.println ("\t||         ASSET        =>  CALC  | PAPER ||");

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

  246.         for (int i = 0; i < aAC.length; ++i)
  247.             System.out.println (
  248.                 "\t||  " + astrID[i] + " => " +
  249.                 FormatUtil.FormatDouble (adblMarketImpliedReturn[i] + dblRiskFreeRate, 1, 2, 100.) + "% |" +
  250.                 FormatUtil.FormatDouble (adblMarketImpliedReturnReconciler[i], 1, 2, 100.) + "% ||"
  251.             );

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

  253.         EnvManager.TerminateEnv();
  254.     }
  255. }