DaJagannathan2005e.java

  1. package org.drip.sample.blacklitterman;

  2. import org.drip.measure.bayesian.R1MultivariateConvolutionMetrics;
  3. import org.drip.measure.continuous.MultivariateMeta;
  4. import org.drip.measure.gaussian.*;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.portfolioconstruction.allocator.ForwardReverseHoldingsAllocation;
  7. import org.drip.portfolioconstruction.asset.Portfolio;
  8. import org.drip.portfolioconstruction.bayesian.*;
  9. import org.drip.service.env.EnvManager;

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

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

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

  110. public class DaJagannathan2005e {

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

  119.         double dblTau = 0.0025;
  120.         double dblRiskAversion = 1.0;
  121.         double dblRiskFreeRate = 0.03;

  122.         String[] astrAssetID = new String[] {
  123.             "CORPORATE BOND     ",
  124.             "LONG TERM GOVVIE   ",
  125.             "MEDIUM TERM GOVVIE ",
  126.             "STRONG BUY EQUITY  ",
  127.             "BUY EQUITY         ",
  128.             "NEUTRAL EQUITY     ",
  129.             "SELL EQUITY        ",
  130.             "STRONG SELL EQUITY "
  131.         };

  132.         double[] adblAssetEquilibriumWeight = new double[] {
  133.             0.1667,
  134.             0.0833,
  135.             0.0833,
  136.             0.2206,
  137.             0.1184,
  138.             0.1065,
  139.             0.0591,
  140.             0.1622
  141.         };

  142.         double[][] aadblAssetExcessReturnsCovariance = new double[][] {
  143.             {0.0050, 0.0047, 0.0024, 0.0036, 0.0023, 0.0031, 0.0032, 0.0030},
  144.             {0.0047, 0.0062, 0.0030, 0.0033, 0.0016, 0.0024, 0.0026, 0.0020},
  145.             {0.0024, 0.0030, 0.0020, 0.0015, 0.0006, 0.0009, 0.0012, 0.0008},
  146.             {0.0036, 0.0033, 0.0015, 0.0468, 0.0354, 0.0371, 0.0379, 0.0414},
  147.             {0.0023, 0.0016, 0.0006, 0.0354, 0.0354, 0.0323, 0.0317, 0.0371},
  148.             {0.0031, 0.0024, 0.0009, 0.0371, 0.0323, 0.0349, 0.0342, 0.0364},
  149.             {0.0032, 0.0026, 0.0012, 0.0379, 0.0317, 0.0342, 0.0432, 0.0384},
  150.             {0.0030, 0.0020, 0.0008, 0.0414, 0.0371, 0.0364, 0.0384, 0.0498}
  151.         };

  152.         double[][] aadblAssetSpaceViewProjection = new double[][] {
  153.             {  0.00,  0.00,  0.00,  0.33,  0.18,  0.16,  0.09,  0.24},
  154.             { -0.50, -0.25, -0.25,  0.33,  0.18,  0.16,  0.09,  0.24},
  155.             {  0.00,  0.00,  0.00,  1.00,  0.00,  0.00,  0.00,  0.00},
  156.             {  0.00,  0.00,  0.00,  0.00,  1.00,  0.00,  0.00,  0.00},
  157.             {  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00,  0.00},
  158.             {  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00}
  159.         };

  160.         double[] adblProjectionExpectedExcessReturns = new double[] {
  161.             0.0634,
  162.             0.0400,
  163.             0.0834,
  164.             0.0784,
  165.             0.0484,
  166.             0.0434
  167.         };

  168.         double[][] aadblProjectionExcessReturnsCovariance = new double[][] {
  169.             {0.0012, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000},
  170.             {0.0000, 0.0009, 0.0000, 0.0000, 0.0000, 0.0000},
  171.             {0.0000, 0.0000, 0.0009, 0.0000, 0.0000, 0.0000},
  172.             {0.0000, 0.0000, 0.0000, 0.0036, 0.0000, 0.0000},
  173.             {0.0000, 0.0000, 0.0000, 0.0000, 0.0036, 0.0000},
  174.             {0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0009}
  175.         };

  176.         R1MultivariateNormal viewDistribution = R1MultivariateNormal.Standard (
  177.             new MultivariateMeta (
  178.                 new String[] {
  179.                     "PROJECTION #1",
  180.                     "PROJECTION #2",
  181.                     "PROJECTION #3",
  182.                     "PROJECTION #4",
  183.                     "PROJECTION #5",
  184.                     "PROJECTION #6"
  185.                 }
  186.             ),
  187.             adblProjectionExpectedExcessReturns,
  188.             aadblProjectionExcessReturnsCovariance
  189.         );

  190.         double[] adblAssetSpaceJointReturnsReconciler = new double[] {
  191.             0.0336,
  192.             0.0333,
  193.             0.0315,
  194.             0.0614,
  195.             0.0562,
  196.             0.0568,
  197.             0.0577,
  198.             0.0608
  199.         };

  200.         BlackLittermanCombinationEngine blce = new BlackLittermanCombinationEngine (
  201.             ForwardReverseHoldingsAllocation.Reverse (
  202.                 Portfolio.Standard (
  203.                     astrAssetID,
  204.                     adblAssetEquilibriumWeight
  205.                 ),
  206.                 aadblAssetExcessReturnsCovariance,
  207.                 dblRiskAversion
  208.             ),
  209.             new PriorControlSpecification (
  210.                 false,
  211.                 dblRiskFreeRate,
  212.                 dblTau
  213.             ),
  214.             new ProjectionSpecification (
  215.                 viewDistribution,
  216.                 aadblAssetSpaceViewProjection
  217.             )
  218.         );

  219.         R1MultivariateConvolutionMetrics jpm = blce.customConfidenceRun().jointPosteriorMetrics();

  220.         R1MultivariateNormal jointDistribution = (R1MultivariateNormal) jpm.joint();

  221.         R1MultivariateNormal posteriorDistribution = (R1MultivariateNormal) jpm.posterior();

  222.         double[] adblAssetSpaceJointReturns = jointDistribution.mean();

  223.         double[][] aadblAssetSpaceJointCovariance = jointDistribution.covariance().covarianceMatrix();

  224.         double[][] aadblAssetSpacePosteriorCovariance = posteriorDistribution.covariance().covarianceMatrix();

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

  226.         System.out.println ("\t| TAU   => " + FormatUtil.FormatDouble (dblTau, 1, 8, 1.) + "   ||");

  227.         System.out.println ("\t| DELTA => " + FormatUtil.FormatDouble (dblRiskAversion, 1, 8, 1.) + "   ||");

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

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

  230.         System.out.println ("\t|                           PRIOR CROSS ASSET COVARIANCE MATRIX                                  ||");

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

  232.         String strHeader = "\t|     |";

  233.         for (int i = 0; i < astrAssetID.length; ++i)
  234.             strHeader += "    " + astrAssetID[i] + "     |";

  235.         System.out.println (strHeader + "|");

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

  237.         for (int i = 0; i < astrAssetID.length; ++i) {
  238.             String strDump = "\t| " + astrAssetID[i] + " ";

  239.             for (int j = 0; j < astrAssetID.length; ++j)
  240.                 strDump += "|" + FormatUtil.FormatDouble (aadblAssetExcessReturnsCovariance[i][j], 1, 8, 1.) + " ";

  241.             System.out.println (strDump + "||");
  242.         }

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

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

  245.         System.out.println ("\t|                          VIEW SCOPING ASSET PROJECTION LOADING                                 ||");

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

  247.         strHeader = "\t|     |";

  248.         for (int i = 0; i < astrAssetID.length; ++i)
  249.             strHeader += "    " + astrAssetID[i] + "     |";

  250.         System.out.println (strHeader + "|");

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

  252.         for (int i = 0; i < aadblAssetSpaceViewProjection.length; ++i) {
  253.             String strDump = "\t|  #" + i + " ";

  254.             for (int j = 0; j < astrAssetID.length; ++j)
  255.                 strDump += "|" + FormatUtil.FormatDouble (aadblAssetSpaceViewProjection[i][j], 1, 8, 1.) + " ";

  256.             System.out.println (strDump + "||");
  257.         }

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

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

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

  261.         for (int i = 0; i < aadblAssetSpaceViewProjection.length; ++i) {
  262.             String strDump = "\t|  #" + i + " ";

  263.             for (int j = 0; j < aadblAssetSpaceViewProjection.length; ++j)
  264.                 strDump += "|" + FormatUtil.FormatDouble (aadblProjectionExcessReturnsCovariance[i][j], 1, 8, 1.) + " ";

  265.             System.out.println (strDump + "|" + FormatUtil.FormatDouble (adblProjectionExpectedExcessReturns[i], 1, 2, 100.) + "%");
  266.         }

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

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

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

  270.         System.out.println ("\t|                           JOINT CROSS ASSET COVARIANCE MATRIX                                  ||");

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

  272.         strHeader = "\t|     |";

  273.         for (int i = 0; i < astrAssetID.length; ++i)
  274.             strHeader += "    " + astrAssetID[i] + "     |";

  275.         System.out.println (strHeader + "|");

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

  277.         for (int i = 0; i < astrAssetID.length; ++i) {
  278.             String strDump = "\t| " + astrAssetID[i] + " ";

  279.             for (int j = 0; j < astrAssetID.length; ++j)
  280.                 strDump += "|" + FormatUtil.FormatDouble (aadblAssetSpaceJointCovariance[i][j], 1, 8, 1.) + " ";

  281.             System.out.println (strDump + "||");
  282.         }

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

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

  285.         System.out.println ("\t|                         POSTERIOR CROSS ASSET COVARIANCE MATRIX                                ||");

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

  287.         strHeader = "\t|     |";

  288.         for (int i = 0; i < astrAssetID.length; ++i)
  289.             strHeader += "    " + astrAssetID[i] + "     |";

  290.         System.out.println (strHeader + "|");

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

  292.         for (int i = 0; i < astrAssetID.length; ++i) {
  293.             String strDump = "\t| " + astrAssetID[i] + " ";

  294.             for (int j = 0; j < astrAssetID.length; ++j)
  295.                 strDump += "|" + FormatUtil.FormatDouble (aadblAssetSpacePosteriorCovariance[i][j], 1, 8, 1.) + " ";

  296.             System.out.println (strDump + "||");
  297.         }

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

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

  300.         System.out.println ("\t| JOINT/POSTERIOR RETURN ||");

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

  302.         System.out.println ("\t|   ID  => RIOC  | HL99  ||");

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

  304.         for (int i = 0; i < adblAssetSpaceJointReturnsReconciler.length; ++i) {
  305.             System.out.println (
  306.                 "\t| [" + astrAssetID[i] + "] =>" +
  307.                 FormatUtil.FormatDouble (adblAssetSpaceJointReturns[i], 2, 2, 100.) + "% |" +
  308.                 FormatUtil.FormatDouble (adblAssetSpaceJointReturnsReconciler[i], 2, 2, 100.) + "% ||"
  309.             );
  310.         }

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

  312.         EnvManager.TerminateEnv();
  313.     }
  314. }