Table4DetailedBlowout.java

  1. package org.drip.sample.helitterman;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.numerical.linearalgebra.Matrix;
  4. import org.drip.service.env.EnvManager;

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

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

  69. /**
  70.  * <i>Table4DetailedBlowout</i> replicates the detailed Steps involved in the Black-Litterman Model Process
  71.  * as illustrated in Table #4 the Following Paper:
  72.  *  
  73.  * <br><br>
  74.  *  <ul>
  75.  *      <li>
  76.  *          He. G., and R. Litterman (1999): The Intuition behind the Black-Litterman Model Portfolios,
  77.  *              Goldman Sachs Asset Management
  78.  *      </li>
  79.  *  </ul>
  80.  *  
  81.  * <br><br>
  82.  *  <ul>
  83.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  84.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AssetAllocationAnalyticsLibrary.md">Asset Allocation Analytics Library</a></li>
  85.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/helitterman/README.md">He and Litterman (1999) Reconcilers</a></li>
  87.  *  </ul>
  88.  * <br><br>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class Table4DetailedBlowout
  93. {

  94.     public static void main (
  95.         final String[] argumentArray)
  96.         throws Exception
  97.     {
  98.         EnvManager.InitEnv ("");

  99.         String[] sovereignArray = new String[]
  100.         {
  101.             "AUS",
  102.             "CAD",
  103.             "FRA",
  104.             "GER",
  105.             "JPN",
  106.             "UK ",
  107.             "USA"
  108.         };
  109.         double[][] inputCorrelationMatrix = new double[][]
  110.         {
  111.             {1.000, 0.488, 0.478, 0.515, 0.439, 0.512, 0.491},
  112.             {0.488, 1.000, 0.664, 0.655, 0.310, 0.608, 0.779},
  113.             {0.478, 0.664, 1.000, 0.861, 0.355, 0.783, 0.668},
  114.             {0.515, 0.655, 0.861, 1.000, 0.354, 0.777, 0.653},
  115.             {0.439, 0.310, 0.355, 0.354, 1.000, 0.405, 0.306},
  116.             {0.512, 0.608, 0.783, 0.777, 0.405, 1.000, 0.652},
  117.             {0.491, 0.779, 0.668, 0.653, 0.306, 0.652, 1.000}
  118.         };
  119.         double[] inputVolatilityArray = new double[]
  120.         {
  121.             0.160,
  122.             0.203,
  123.             0.248,
  124.             0.271,
  125.             0.210,
  126.             0.200,
  127.             0.187
  128.         };
  129.         double[] inputWArray = new double[]
  130.         {
  131.             0.016,
  132.             0.022,
  133.             0.052,
  134.             0.055,
  135.             0.116,
  136.             0.124,
  137.             0.615
  138.         };
  139.         double inputTAU = 0.05;
  140.         double inputDELTA = 2.5;
  141.         double[][] inputPMatrix = new double[][]
  142.         {
  143.             { 0.000,  0.000, -0.295,  1.000,  0.000, -0.705,  0.000}
  144.         };
  145.         double[][] inputOmegaMatrix = new double[][]
  146.         {
  147.             {0.021}
  148.         };
  149.         double[] inputQArray = new double[]
  150.         {
  151.             0.05
  152.         };

  153.         int sovereignCount = sovereignArray.length;
  154.         double[][] sigmaMatrix = new double[sovereignCount][sovereignCount];

  155.         for (int sovereignIndexI = 0; sovereignIndexI < sovereignCount; ++sovereignIndexI)
  156.         {
  157.             for (int sovereignIndexJ = 0; sovereignIndexJ < sovereignCount; ++sovereignIndexJ)
  158.             {
  159.                 sigmaMatrix[sovereignIndexI][sovereignIndexJ] = inputVolatilityArray[sovereignIndexI] *
  160.                     inputVolatilityArray[sovereignIndexJ] *
  161.                     inputCorrelationMatrix[sovereignIndexI][sovereignIndexJ];
  162.             }
  163.         }

  164.         double[] piArray = Matrix.Product (
  165.             sigmaMatrix,
  166.             inputWArray
  167.         );

  168.         for (int sovereignIndex = 0; sovereignIndex < sovereignCount; ++sovereignIndex)
  169.         {
  170.             piArray[sovereignIndex] *= inputDELTA;
  171.         }

  172.         System.out.println();

  173.         for (int sovereignIndex = 0; sovereignIndex < sovereignCount; ++sovereignIndex)
  174.         {
  175.             System.out.println (
  176.                 "\t{PI}[" + sovereignArray[sovereignIndex] + "] =>" +
  177.                 FormatUtil.FormatDouble (piArray[sovereignIndex], 1, 1, 100.) + "%"
  178.             );
  179.         }

  180.         System.out.println();

  181.         double[] pDotPIArray = Matrix.Product (
  182.             inputPMatrix,
  183.             piArray
  184.         );

  185.         for (int pDotPIIndex = 0; pDotPIIndex < pDotPIArray.length; ++pDotPIIndex)
  186.         {
  187.             System.out.println (
  188.                 "\t{P.PI}[" + pDotPIIndex + "] =>" +
  189.                 FormatUtil.FormatDouble (pDotPIArray[pDotPIIndex], 1, 6, 1.)
  190.             );
  191.         }

  192.         System.out.println();

  193.         double[] qMinus_PdotPI_Array = new double[inputQArray.length];

  194.         for (int qIndex = 0; qIndex < inputQArray.length; ++qIndex)
  195.         {
  196.             qMinus_PdotPI_Array[qIndex] = inputQArray[qIndex] - pDotPIArray[qIndex];
  197.         }

  198.         for (int qMinus_PdotPI_ArrayIndex = 0;
  199.             qMinus_PdotPI_ArrayIndex < qMinus_PdotPI_Array.length;
  200.             ++qMinus_PdotPI_ArrayIndex)
  201.         {
  202.             System.out.println (
  203.                 "\t{Q-P.PI}[" + qMinus_PdotPI_ArrayIndex + "] =>" +
  204.                 FormatUtil.FormatDouble (qMinus_PdotPI_Array[qMinus_PdotPI_ArrayIndex], 1, 6, 1.)
  205.             );
  206.         }

  207.         System.out.println();

  208.         double[][] pTransposeMatrix = Matrix.Transpose (
  209.             inputPMatrix
  210.         );

  211.         double[][] sigmaDot_PTranspose_Matrix = Matrix.Product (
  212.             sigmaMatrix,
  213.             pTransposeMatrix
  214.         );

  215.         for (int sigmaDot_PTranspose_MatrixRowIndex = 0;
  216.             sigmaDot_PTranspose_MatrixRowIndex < sigmaDot_PTranspose_Matrix.length;
  217.             ++sigmaDot_PTranspose_MatrixRowIndex)
  218.         {
  219.             for (int sigmaDot_PTranspose_MatrixColumnIndex = 0;
  220.                 sigmaDot_PTranspose_MatrixColumnIndex < sigmaDot_PTranspose_Matrix[0].length;
  221.                 ++sigmaDot_PTranspose_MatrixColumnIndex)
  222.             {
  223.                 System.out.println (
  224.                     "\t{SIGMA.PTRANSPOSE}[" + sigmaDot_PTranspose_MatrixRowIndex + "][" + sigmaDot_PTranspose_MatrixColumnIndex + "] =>" +
  225.                     FormatUtil.FormatDouble (sigmaDot_PTranspose_Matrix[sigmaDot_PTranspose_MatrixRowIndex][sigmaDot_PTranspose_MatrixColumnIndex], 1, 6, 1.)
  226.                 );
  227.             }
  228.         }

  229.         System.out.println();

  230.         double[][] pDotSIGMAdot_PTranspose_Matrix = Matrix.Product (
  231.             inputPMatrix,
  232.             sigmaDot_PTranspose_Matrix
  233.         );

  234.         for (int pDotSIGMAdot_PTranspose_MatrixRowIndex = 0;
  235.             pDotSIGMAdot_PTranspose_MatrixRowIndex < pDotSIGMAdot_PTranspose_Matrix.length;
  236.             ++pDotSIGMAdot_PTranspose_MatrixRowIndex)
  237.         {
  238.             for (int pDotSIGMAdot_PTranspose_MatrixColumnIndex = 0;
  239.                 pDotSIGMAdot_PTranspose_MatrixColumnIndex < pDotSIGMAdot_PTranspose_Matrix[0].length;
  240.                 ++pDotSIGMAdot_PTranspose_MatrixColumnIndex)
  241.             {
  242.                 System.out.println (
  243.                     "\t{P.SIGMA.PTRANSPOSE}[" + pDotSIGMAdot_PTranspose_MatrixRowIndex + "][" + pDotSIGMAdot_PTranspose_MatrixColumnIndex + "] =>" +
  244.                     FormatUtil.FormatDouble (pDotSIGMAdot_PTranspose_Matrix[pDotSIGMAdot_PTranspose_MatrixRowIndex][pDotSIGMAdot_PTranspose_MatrixColumnIndex], 1, 6, 1.)
  245.                 );
  246.             }
  247.         }

  248.         System.out.println();

  249.         double[][] pDotSIGMAdot_PTranspose_PlusOMEGAMatrix =
  250.             new double[pDotSIGMAdot_PTranspose_Matrix.length][pDotSIGMAdot_PTranspose_Matrix[0].length];

  251.         for (int pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex = 0;
  252.             pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex < pDotSIGMAdot_PTranspose_PlusOMEGAMatrix.length;
  253.             ++pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex)
  254.         {
  255.             for (int pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex = 0;
  256.                 pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex <
  257.                     pDotSIGMAdot_PTranspose_PlusOMEGAMatrix[0].length;
  258.                 ++pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex)
  259.             {
  260.                 pDotSIGMAdot_PTranspose_PlusOMEGAMatrix[pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex][pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex] =
  261.                     pDotSIGMAdot_PTranspose_Matrix[pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex][pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex] +
  262.                     inputOmegaMatrix[pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex][pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex];

  263.                 System.out.println (
  264.                     "\t{P.SIGMA.PTRANSPOSE+OMEGA}[" + pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex + "][" + pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex + "] =>" +
  265.                     FormatUtil.FormatDouble (
  266.                         pDotSIGMAdot_PTranspose_PlusOMEGAMatrix[pDotSIGMAdot_PTranspose_PlusOMEGAMatrixRowIndex][pDotSIGMAdot_PTranspose_PlusOMEGAMatrixColumnIndex],
  267.                         1, 6, 1.
  268.                     )
  269.                 );
  270.             }
  271.         }

  272.         System.out.println();

  273.         double[][] $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrix = Matrix.InvertUsingGaussianElimination (
  274.             pDotSIGMAdot_PTranspose_PlusOMEGAMatrix
  275.         );

  276.         for (int $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixRowIndex = 0;
  277.             $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixRowIndex <
  278.                 $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrix.length;
  279.             ++$PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixRowIndex)
  280.         {
  281.             for (int $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixColumnIndex = 0;
  282.                 $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixColumnIndex <
  283.                     $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrix[0].length;
  284.                 ++$PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixColumnIndex)
  285.             {
  286.                 System.out.println (
  287.                     "\t{P.SIGMA.PTRANSPOSE+OMEGA}^(-1)[" + $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixRowIndex + "][" + $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixColumnIndex + "] =>" +
  288.                     FormatUtil.FormatDouble ($PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrix[$PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixRowIndex][$PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrixColumnIndex], 1, 6, 1.)
  289.                 );
  290.             }
  291.         }

  292.         System.out.println();

  293.         double[] __$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__Array = Matrix.Product (
  294.             $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrix,
  295.             qMinus_PdotPI_Array
  296.         );

  297.         for (int __$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__ArrayIndex = 0;
  298.             __$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__ArrayIndex <
  299.                 __$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__Array.length;
  300.             ++__$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__ArrayIndex)
  301.         {
  302.             System.out.println (
  303.                 "\t{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{Q-P.PI}[" + __$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__ArrayIndex + "] =>" +
  304.                 FormatUtil.FormatDouble (__$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__Array[__$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__ArrayIndex], 1, 6, 1.)
  305.             );
  306.         }

  307.         System.out.println();

  308.         double[] sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__Array
  309.             = Matrix.Product (
  310.                 sigmaDot_PTranspose_Matrix,
  311.                 __$PDotSIGMADot_PTranspose_plusOMEGA$Inverse__Dot_QMinus__PDotPI__Array
  312.             );

  313.         for (int sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__ArrayIndex = 0;
  314.             sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__ArrayIndex <
  315.                 sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__Array.length;
  316.             ++sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__ArrayIndex)
  317.         {
  318.             System.out.println (
  319.                 "\t{SIGMA.PTRANSPOSE}{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{Q-P.PI}[" + sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__ArrayIndex + "] =>" +
  320.                 FormatUtil.FormatDouble (sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__Array[sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__ArrayIndex], 1, 6, 1.)
  321.             );
  322.         }

  323.         System.out.println();

  324.         double[] piHatArray = new double[piArray.length];

  325.         for (int piHatArrayIndex = 0; piHatArrayIndex < piHatArray.length; ++piHatArrayIndex)
  326.         {
  327.             piHatArray[piHatArrayIndex] = piArray[piHatArrayIndex] +
  328.                 sigmaDot$PTranspose$__$PDotSIGMADot_PTranspose_PlusOmega$Inverse__Dot_QMinus__PDotPI__Array[piHatArrayIndex];

  329.             System.out.println (
  330.                 "\tPIHAT=PI+{SIGMA.PTRANSPOSE}{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{Q-P.PI}[" + piHatArrayIndex + "] =>" +
  331.                 FormatUtil.FormatDouble (piHatArray[piHatArrayIndex], 1, 1, 100.) + "%"
  332.             );
  333.         }

  334.         System.out.println();

  335.         double[][] pDotSigmaMatrix = Matrix.Product (
  336.             inputPMatrix,
  337.             sigmaMatrix
  338.         );

  339.         for (int pDotSigmaMatrixRowIndex = 0;
  340.             pDotSigmaMatrixRowIndex < pDotSigmaMatrix.length;
  341.             ++pDotSigmaMatrixRowIndex)
  342.         {
  343.             for (int pDotSigmaMatrixColumnIndex = 0;
  344.                 pDotSigmaMatrixColumnIndex < pDotSigmaMatrix[0].length;
  345.                 ++pDotSigmaMatrixColumnIndex)
  346.             {
  347.                 System.out.println (
  348.                     "\tP.SIGMA[" + pDotSigmaMatrixRowIndex + "][" + pDotSigmaMatrixColumnIndex + "] =>" +
  349.                     FormatUtil.FormatDouble (pDotSigmaMatrix[pDotSigmaMatrixRowIndex][pDotSigmaMatrixColumnIndex], 1, 6, 1.)
  350.                 );
  351.             }
  352.         }

  353.         System.out.println();

  354.         double[][] __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix = Matrix.Product (
  355.             $PDotSIGMAdot_PTranspose_PlusOMEGA$InverseMatrix,
  356.             pDotSigmaMatrix
  357.         );

  358.         for (int __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex = 0;
  359.             __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex <
  360.                 __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix.length;
  361.             ++__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex)
  362.         {
  363.             for (int __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex = 0;
  364.                 __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex <
  365.                     __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix[0].length;
  366.                 ++__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex)
  367.             {
  368.                 System.out.println (
  369.                     "\t{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA}[" + __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex + "][" + __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex + "] =>" +
  370.                     FormatUtil.FormatDouble (__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix[__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex][__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex], 1, 6, 1.)
  371.                 );
  372.             }
  373.         }

  374.         System.out.println();

  375.         double[][] sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrix =
  376.             Matrix.Product (
  377.                 sigmaDot_PTranspose_Matrix,
  378.                 __$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix
  379.             );

  380.         for (int sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixRowIndex = 0;
  381.             sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixRowIndex <
  382.                 sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrix.length;
  383.             ++sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixRowIndex)
  384.         {
  385.             for (int sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixColumnIndex = 0;
  386.                 sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixColumnIndex <
  387.                     sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrix[0].length;
  388.                 ++sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixColumnIndex)
  389.             {
  390.                 System.out.println (
  391.                     "\t{SIGMA.PTRANSPOSE}.{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA}[" + sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixRowIndex + "][" + sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixColumnIndex + "] =>" +
  392.                     FormatUtil.FormatDouble (
  393.                         sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrix[sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixRowIndex][sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrixColumnIndex],
  394.                         1, 6, 1.
  395.                     )
  396.                 );
  397.             }
  398.         }

  399.         System.out.println();

  400.         double[][]
  401.             sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix
  402.                 = new double[sovereignCount][sovereignCount];

  403.         for (int sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex = 0;
  404.             sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex <
  405.                 sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix.length;
  406.             ++sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex)
  407.         {
  408.             for (int sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex = 0;
  409.                 sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex <
  410.                     sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix[0].length;
  411.                 ++sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex)
  412.             {
  413.                 sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix[sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex][sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex] =
  414.                     sigmaMatrix[sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex][sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex] -
  415.                     sigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmegaPDotSigmaMatrix[sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex][sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex];

  416.                 System.out.println (
  417.                     "\tSIGMA-{SIGMA.PTRANSPOSE}.{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA}[" + sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex + "][" + sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex + "] =>" +
  418.                     FormatUtil.FormatDouble (sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix[sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixRowIndex][sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrixColumnIndex], 1, 6, 1.)
  419.                 );
  420.             }
  421.         }

  422.         System.out.println();

  423.         double[][] tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix =
  424.             new double[sovereignCount][sovereignCount];

  425.         for (int tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex = 0;
  426.             tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex <
  427.                 tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix.length;
  428.             ++tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex)
  429.         {
  430.             for (int tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex = 0;
  431.                 tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex <
  432.                     tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[0].length;
  433.                 ++tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex)
  434.             {
  435.                 tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex] =
  436.                     inputTAU * sigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigmaMatrix[tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex];

  437.                 System.out.println (
  438.                     "\tTAU.(SIGMA-{SIGMA.PTRANSPOSE}.{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA})[" + tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex + "][" + tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex + "] =>" +
  439.                     FormatUtil.FormatDouble (tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex], 1, 6, 1.)
  440.                 );
  441.             }
  442.         }

  443.         System.out.println();

  444.         double[][] sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix =
  445.             new double[sovereignCount][sovereignCount];

  446.         for (int sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex = 0;
  447.                 sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex <
  448.                 sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix.length;
  449.             ++sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex)
  450.         {
  451.             for (int sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex = 0;
  452.                 sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex <
  453.                     sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[0].length;
  454.                 ++sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex)
  455.             {
  456.                 sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex] =
  457.                     sigmaMatrix[sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex] +
  458.                     tauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex];

  459.                 System.out.println (
  460.                     "\tSIGMA+TAU.(SIGMA-{SIGMA.PTRANSPOSE}.{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA})[" + sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex + "][" + sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex + "] =>" +
  461.                     FormatUtil.FormatDouble (sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix[sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixRowIndex][sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$MatrixColumnIndex], 1, 6, 1.)
  462.                 );
  463.             }
  464.         }

  465.         System.out.println();

  466.         double[][] sigmaPInverseMatrix = Matrix.InvertUsingGaussianElimination (
  467.             sigmaPlusTauDot$$SigmaMinusSigmaDot_PTranspose_Dot__$PDotSigmaDot_PTranspose_PlusOmega$Inverse__DotPDotSigma$$Matrix
  468.         );

  469.         for (int sigmaPInverseMatrixRowIndex = 0;
  470.             sigmaPInverseMatrixRowIndex< sigmaPInverseMatrix.length;
  471.             ++sigmaPInverseMatrixRowIndex)
  472.         {
  473.             for (int sigmaPInverseMatrixColumnIndex = 0;
  474.                 sigmaPInverseMatrixColumnIndex < sigmaPInverseMatrix[0].length;
  475.                 ++sigmaPInverseMatrixColumnIndex)
  476.             {
  477.                 System.out.println (
  478.                     "\t[SIGMA+TAU.(SIGMA-{SIGMA.PTRANSPOSE}.{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA})]^(-1)[" + sigmaPInverseMatrixRowIndex + "][" + sigmaPInverseMatrixColumnIndex + "] =>" +
  479.                     FormatUtil.FormatDouble (sigmaPInverseMatrix[sigmaPInverseMatrixRowIndex][sigmaPInverseMatrixColumnIndex], 1, 6, 1.)
  480.                 );
  481.             }
  482.         }

  483.         System.out.println();

  484.         double[] sigmaPInverseDotPiHatArray = Matrix.Product (
  485.             sigmaPInverseMatrix,
  486.             piHatArray
  487.         );

  488.         for (int sigmaPInverseDotPiHatArrayIndex = 0;
  489.             sigmaPInverseDotPiHatArrayIndex < sigmaPInverseDotPiHatArray.length;
  490.             ++sigmaPInverseDotPiHatArrayIndex)
  491.         {
  492.             sigmaPInverseDotPiHatArray[sigmaPInverseDotPiHatArrayIndex] /= inputDELTA;

  493.             System.out.println (
  494.                 "\t[SIGMA+TAU.(SIGMA-{SIGMA.PTRANSPOSE}.{P.SIGMA.PTRANSPOSE+OMEGA}^(-1).{P.SIGMA})]^(-1).PIHAT[" + sigmaPInverseDotPiHatArrayIndex + "] =>" +
  495.                 FormatUtil.FormatDouble (sigmaPInverseDotPiHatArray[sigmaPInverseDotPiHatArrayIndex], 1, 1, 100.) + "%"
  496.             );
  497.         }

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

  499.         System.out.println ("\t|  EQUILIBRIUM   ||");

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

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

  502.         for (int piArrayIndex = 0; piArrayIndex < piArray.length; ++piArrayIndex)
  503.         {
  504.             System.out.println (
  505.                 "\t| [" + sovereignArray[piArrayIndex] + "] =>" +
  506.                 FormatUtil.FormatDouble (piArray[piArrayIndex], 2, 1, 100.) + "% ||"
  507.             );
  508.         }

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

  510.         System.out.println ("\t| BLACK LITERMAN ||");

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

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

  513.         for (int piArrayIndex = 0; piArrayIndex < piHatArray.length; ++piArrayIndex)
  514.         {
  515.             System.out.println (
  516.                 "\t| [" + sovereignArray[piArrayIndex] + "] =>" +
  517.                 FormatUtil.FormatDouble (piHatArray[piArrayIndex], 2, 1, 100.) + "% ||"
  518.             );
  519.         }

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

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

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

  523.         System.out.println ("\t|   EQUILIBRIUM   ||");

  524.         System.out.println ("\t|   ALLOCATION    ||");

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

  526.         for (int inputWArrayIndex = 0; inputWArrayIndex < inputWArray.length; ++inputWArrayIndex)
  527.         {
  528.             System.out.println (
  529.                 "\t| [" + sovereignArray[inputWArrayIndex] + "] => " +
  530.                 FormatUtil.FormatDouble (inputWArray[inputWArrayIndex] / (1. + inputTAU), 2, 1, 100.) + "% ||"
  531.             );
  532.         }

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

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

  535.         System.out.println ("\t| BLACK LITERMAN  ||");

  536.         System.out.println ("\t|    ALLOCATION   ||");

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

  538.         for (int sigmaPInverseDotPiHatArrayIndex = 0;
  539.             sigmaPInverseDotPiHatArrayIndex < sigmaPInverseDotPiHatArray.length;
  540.             ++sigmaPInverseDotPiHatArrayIndex)
  541.         {
  542.             System.out.println (
  543.                 "\t| [" + sovereignArray[sigmaPInverseDotPiHatArrayIndex] + "] => " +
  544.                 FormatUtil.FormatDouble (sigmaPInverseDotPiHatArray[sigmaPInverseDotPiHatArrayIndex], 2, 1, 100.) + "% ||"
  545.             );
  546.         }

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

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

  549.         System.out.println ("\t|  BLACK LITERMAN  ||");

  550.         System.out.println ("\t| ALLOCATION SHIFT ||");

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

  552.         for (int sigmaPInverseDotPiHatArrayIndex = 0;
  553.             sigmaPInverseDotPiHatArrayIndex < sigmaPInverseDotPiHatArray.length;
  554.             ++sigmaPInverseDotPiHatArrayIndex)
  555.         {
  556.             System.out.println (
  557.                 "\t| [" + sovereignArray[sigmaPInverseDotPiHatArrayIndex] + "] => " +
  558.                 FormatUtil.FormatDouble (sigmaPInverseDotPiHatArray[sigmaPInverseDotPiHatArrayIndex] - (inputWArray[sigmaPInverseDotPiHatArrayIndex] / (1. + inputTAU)), 2, 1, 100.) + "%  ||"
  559.             );
  560.         }

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

  562.         EnvManager.TerminateEnv();
  563.     }
  564. }