PortfolioAndBenchmarkMetrics.java

  1. package org.drip.sample.idzorek;

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

  74. /**
  75.  * <i>PortfolioAndBenchmarkMetrics</i> demonstrates the Prior-Posterior Portfolio Statistics using the
  76.  * Black-Litterman Model augmented with the Idzorek Model. The References are:
  77.  *  
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          He. G., and R. Litterman (1999): The Intuition behind the Black-Litterman Model Portfolios,
  82.  *              Goldman Sachs Asset Management
  83.  *      </li>
  84.  *      <li>
  85.  *          Idzorek, T. (2005): A Step-by-Step Guide to the Black-Litterman Model: Incorporating User
  86.  *              Specified Confidence Levels, Ibbotson Associates, Chicago
  87.  *      </li>
  88.  *  </ul>
  89.  *  
  90.  * <br><br>
  91.  *  <ul>
  92.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  93.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AssetAllocationAnalyticsLibrary.md">Asset Allocation Analytics Library</a></li>
  94.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  95.  *      <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>
  96.  *  </ul>
  97.  * <br><br>
  98.  *
  99.  * @author Lakshmi Krishnamurthy
  100.  */

  101. public class PortfolioAndBenchmarkMetrics
  102. {

  103.     public static final void main (
  104.         final String[] argumentArray)
  105.         throws Exception
  106.     {
  107.         EnvManager.InitEnv ("");

  108.         double tau = 0.025;
  109.         double riskAversion = 3.07;
  110.         double riskFreeRate = 0.00;
  111.         String[] assetIDArray = new String[]
  112.         {
  113.             "US BONDS                       ",
  114.             "INTERNATIONAL BONDS            ",
  115.             "US LARGE GROWTH                ",
  116.             "US LARGE VALUE                 ",
  117.             "US SMALL GROWTH                ",
  118.             "US SMALL VALUE                 ",
  119.             "INTERNATIONAL DEVELOPED EQUITY ",
  120.             "INTERNATIONAL EMERGING EQUITY  "
  121.         };
  122.         double[] assetEquilibriumWeightArray = new double[]
  123.         {
  124.             0.1934,
  125.             0.2613,
  126.             0.1209,
  127.             0.1209,
  128.             0.0134,
  129.             0.0134,
  130.             0.2418,
  131.             0.0349
  132.         };
  133.         double[][] assetExcessReturnsCovarianceMatrix = new double[][]
  134.         {
  135.             { 0.001005,  0.001328, -0.000579, -0.000675,  0.000121,  0.000128, -0.000445, -0.000437},
  136.             { 0.001328,  0.007277, -0.001307, -0.000610, -0.002237, -0.000989,  0.001442, -0.001535},
  137.             {-0.000579, -0.001307,  0.059582,  0.027588,  0.063497,  0.023036,  0.032967,  0.048039},
  138.             {-0.000675, -0.000610,  0.027588,  0.029609,  0.026572,  0.021465,  0.020697,  0.029854},
  139.             { 0.000121, -0.002237,  0.063497,  0.026572,  0.102488,  0.042744,  0.039943,  0.065994},
  140.             { 0.000128, -0.000989,  0.023036,  0.021465,  0.042744,  0.032056,  0.019881,  0.032235},
  141.             {-0.000445,  0.001442,  0.032967,  0.020697,  0.039943,  0.019881,  0.028355,  0.035064},
  142.             {-0.000437, -0.001535,  0.048039,  0.029854,  0.065994,  0.032235,  0.035064,  0.079958}
  143.         };
  144.         double[][] assetSpaceViewProjectionMatrix = new double[][]
  145.         {
  146.             {  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00,  0.00},
  147.             { -1.00,  1.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00},
  148.             {  0.00,  0.00,  0.90, -0.90,  0.10, -0.10,  0.00,  0.00}
  149.         };
  150.         double[] projectionExpectedExcessReturnsArray = new double[]
  151.         {
  152.             0.0525,
  153.             0.0025,
  154.             0.0200
  155.         };

  156.         double[][] projectionExcessReturnsCovarianceMatrix =
  157.             ProjectionDistributionLoading.ProjectionCovariance (
  158.                 assetExcessReturnsCovarianceMatrix,
  159.                 assetSpaceViewProjectionMatrix,
  160.                 tau
  161.             );

  162.         R1MultivariateNormal viewDistribution = R1MultivariateNormal.Standard (
  163.             new MultivariateMeta (
  164.                 new String[]
  165.                 {
  166.                     "PROJECTION #1",
  167.                     "PROJECTION #2",
  168.                     "PROJECTION #3"
  169.                 }
  170.             ),
  171.             projectionExpectedExcessReturnsArray,
  172.             projectionExcessReturnsCovarianceMatrix
  173.         );

  174.         R1MultivariateConvolutionMetrics jointPosteriorMetrics = new BlackLittermanCombinationEngine (
  175.             ForwardReverseHoldingsAllocation.Reverse (
  176.                 Portfolio.Standard (
  177.                     assetIDArray,
  178.                     assetEquilibriumWeightArray
  179.                 ),
  180.                 assetExcessReturnsCovarianceMatrix,
  181.                 riskAversion
  182.             ),
  183.             new PriorControlSpecification (
  184.                 false,
  185.                 riskFreeRate,
  186.                 tau
  187.             ),
  188.             new ProjectionSpecification (
  189.                 viewDistribution,
  190.                 assetSpaceViewProjectionMatrix
  191.             )
  192.         ).customConfidenceRun().jointPosteriorMetrics();

  193.         R1MultivariateNormal jointDistribution = (R1MultivariateNormal) jointPosteriorMetrics.joint();

  194.         ForwardReverseHoldingsAllocation priorForwardReverseOptimizationOutput =
  195.             ForwardReverseHoldingsAllocation.Reverse (
  196.                 Portfolio.Standard (
  197.                     assetIDArray,
  198.                     assetEquilibriumWeightArray
  199.                 ),
  200.                 assetExcessReturnsCovarianceMatrix,
  201.                 riskAversion
  202.             );

  203.         PortfolioMetrics optimalPriorPortfolioMetrics =
  204.             priorForwardReverseOptimizationOutput.optimalMetrics();

  205.         ForwardReverseHoldingsAllocation posteriorForwardReverseOptimizationOutput =
  206.             ForwardReverseHoldingsAllocation.Forward (
  207.                 assetIDArray,
  208.                 jointDistribution.mean(),
  209.                 assetExcessReturnsCovarianceMatrix,
  210.                 riskAversion
  211.             );

  212.         PortfolioMetrics optimalPosteriorPortfolioMetrics =
  213.             posteriorForwardReverseOptimizationOutput.optimalMetrics();

  214.         PortfolioBenchmarkMetrics posteriorPortfolioBenchmarkMetrics =
  215.             posteriorForwardReverseOptimizationOutput.benchmarkMetrics (
  216.                 optimalPriorPortfolioMetrics
  217.             );

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

  219.         System.out.println ("\t| EXCESS RETURN MEAN               => " +
  220.             FormatUtil.FormatDouble (
  221.                 optimalPriorPortfolioMetrics.excessReturnsMean(), 1, 3, 100.
  222.             ) + "%  | " +
  223.             FormatUtil.FormatDouble (
  224.                 optimalPosteriorPortfolioMetrics.excessReturnsMean(), 1, 3, 100.
  225.             ) + "%  ||"
  226.         );

  227.         System.out.println ("\t| EXCESS RETURN VARIANCE           => " +
  228.             FormatUtil.FormatDouble (
  229.                 optimalPriorPortfolioMetrics.excessReturnsVariance(), 1, 5, 1.
  230.             ) + " | " +
  231.             FormatUtil.FormatDouble (
  232.                 optimalPosteriorPortfolioMetrics.excessReturnsVariance(), 1, 5, 1.
  233.             ) + " ||"
  234.         );

  235.         System.out.println ("\t| EXCESS RETURN STANDARD DEVIATION => " +
  236.             FormatUtil.FormatDouble (
  237.                 optimalPriorPortfolioMetrics.excessReturnsStandardDeviation(), 1, 3, 100.
  238.             ) + "%  |" +
  239.             FormatUtil.FormatDouble (
  240.                 optimalPosteriorPortfolioMetrics.excessReturnsStandardDeviation(), 2, 3, 100.
  241.             ) + "%  ||"
  242.         );

  243.         System.out.println ("\t| BETA                             => " +
  244.             FormatUtil.FormatDouble (
  245.                 priorForwardReverseOptimizationOutput.benchmarkMetrics (
  246.                     optimalPriorPortfolioMetrics
  247.                 ).beta(), 1, 5, 1.
  248.             ) + " | " +
  249.             FormatUtil.FormatDouble (posteriorPortfolioBenchmarkMetrics.beta(), 1, 5, 1.) + " ||"
  250.         );

  251.         System.out.println ("\t| ACTIVE BETA                      => " +
  252.             FormatUtil.FormatDouble (0., 1, 5, 1.) + " | " +
  253.             FormatUtil.FormatDouble (posteriorPortfolioBenchmarkMetrics.activeBeta(), 1, 5, 1.) + " ||"
  254.         );

  255.         System.out.println ("\t| RESIDUAL RETURN                  => " +
  256.             FormatUtil.FormatDouble (0., 1, 3, 100.) + "%  | " +
  257.             FormatUtil.FormatDouble (posteriorPortfolioBenchmarkMetrics.residualReturn(), 1, 3, 100.)
  258.                 + "%  ||"
  259.         );

  260.         System.out.println ("\t| RESIDUAL RISK                    => " +
  261.             FormatUtil.FormatDouble (0., 1, 3, 100.) + "%  | " +
  262.             FormatUtil.FormatDouble (posteriorPortfolioBenchmarkMetrics.residualRisk(), 1, 3, 100.) + "%  ||"
  263.         );

  264.         System.out.println ("\t| ACTIVE RETURN                    => " +
  265.             FormatUtil.FormatDouble (0., 1, 3, 100.) + "%  | " +
  266.             FormatUtil.FormatDouble (posteriorPortfolioBenchmarkMetrics.activeReturn(), 1, 3, 100.) + "%  ||"
  267.         );

  268.         System.out.println ("\t| ACTIVE RISK                      => " +
  269.             FormatUtil.FormatDouble (0., 1, 3, 100.) + "%  | " +
  270.             FormatUtil.FormatDouble (posteriorPortfolioBenchmarkMetrics.activeRisk(), 1, 3, 100.) + "%  ||"
  271.         );

  272.         System.out.println ("\t| SHARPE RATIO                     => " +
  273.             FormatUtil.FormatDouble (optimalPriorPortfolioMetrics.sharpeRatio(), 1, 5, 1.) + " | " +
  274.             FormatUtil.FormatDouble (optimalPosteriorPortfolioMetrics.sharpeRatio(), 1, 5, 1.) + " ||"
  275.         );

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

  277.         EnvManager.TerminateEnv();
  278.     }
  279. }