UserConfidenceProjectionCalibration.java

  1. package org.drip.sample.idzorek;

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

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

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

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

  102. public class UserConfidenceProjectionCalibration
  103. {

  104.     private static final void IdzorekImpliedProjectionConfidence (
  105.         final BlackLittermanCombinationEngine blackLittermanCombinationEngine,
  106.         final int viewIndex,
  107.         final double[] impliedTiltArray,
  108.         final double projectionUserConfidence)
  109.         throws Exception
  110.     {
  111.         System.out.println ("\t|-----------------------------||");

  112.         System.out.println (
  113.             "\t|            VIEW #" + viewIndex + "          ||"
  114.         );

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

  116.         System.out.println (
  117.             "\t|     CONFIDENCE =>" +
  118.             FormatUtil.FormatDouble (projectionUserConfidence, 2, 2, 100.) + "%    ||"
  119.         );

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

  121.         R1ToR1 tiltDepartureFunction = blackLittermanCombinationEngine.tiltDepartureR1ToR1 (
  122.             impliedTiltArray,
  123.             viewIndex,
  124.             false
  125.         );

  126.         R1ToR1 tiltDepartureFunctionDerivative = blackLittermanCombinationEngine.tiltDepartureR1ToR1 (
  127.             impliedTiltArray,
  128.             viewIndex,
  129.             true
  130.         );

  131.         for (int tiltDepartureIndex = 1;
  132.             tiltDepartureIndex <= 15;
  133.             ++tiltDepartureIndex)
  134.         {
  135.             System.out.println ("\t| " +
  136.                 FormatUtil.FormatDouble (0.01 * tiltDepartureIndex, 2, 2, 100.) + "% | " +
  137.                 FormatUtil.FormatDouble (
  138.                     tiltDepartureFunction.evaluate (
  139.                         0.01 * tiltDepartureIndex
  140.                     ), 2, 2, 100.
  141.                 ) + "% | " +
  142.                 FormatUtil.FormatDouble (
  143.                     tiltDepartureFunctionDerivative.evaluate (
  144.                         0.01 * tiltDepartureIndex
  145.                     ), 2, 2, 100.
  146.                 ) + "% ||"
  147.             );
  148.         }

  149.         System.out.println ("\t|-----------------------------||\n");
  150.     }

  151.     public static final void main (
  152.         final String[] astArgs)
  153.         throws Exception
  154.     {
  155.         EnvManager.InitEnv ("");

  156.         double tau = 0.025;
  157.         double riskAversion = 3.07;
  158.         double riskFreeRate = 0.00;
  159.         String[] assetIDArray = new String[]
  160.         {
  161.             "US BONDS                       ",
  162.             "INTERNATIONAL BONDS            ",
  163.             "US LARGE GROWTH                ",
  164.             "US LARGE VALUE                 ",
  165.             "US SMALL GROWTH                ",
  166.             "US SMALL VALUE                 ",
  167.             "INTERNATIONAL DEVELOPED EQUITY ",
  168.             "INTERNATIONAL EMERGING EQUITY  "
  169.         };
  170.         double[] assetEquilibriumWeightArray = new double[]
  171.         {
  172.             0.1934,
  173.             0.2613,
  174.             0.1209,
  175.             0.1209,
  176.             0.0134,
  177.             0.0134,
  178.             0.2418,
  179.             0.0349
  180.         };
  181.         double[][] assetExcessReturnsCovarianceMatrix = new double[][]
  182.         {
  183.             { 0.001005,  0.001328, -0.000579, -0.000675,  0.000121,  0.000128, -0.000445, -0.000437},
  184.             { 0.001328,  0.007277, -0.001307, -0.000610, -0.002237, -0.000989,  0.001442, -0.001535},
  185.             {-0.000579, -0.001307,  0.059582,  0.027588,  0.063497,  0.023036,  0.032967,  0.048039},
  186.             {-0.000675, -0.000610,  0.027588,  0.029609,  0.026572,  0.021465,  0.020697,  0.029854},
  187.             { 0.000121, -0.002237,  0.063497,  0.026572,  0.102488,  0.042744,  0.039943,  0.065994},
  188.             { 0.000128, -0.000989,  0.023036,  0.021465,  0.042744,  0.032056,  0.019881,  0.032235},
  189.             {-0.000445,  0.001442,  0.032967,  0.020697,  0.039943,  0.019881,  0.028355,  0.035064},
  190.             {-0.000437, -0.001535,  0.048039,  0.029854,  0.065994,  0.032235,  0.035064,  0.079958}
  191.         };
  192.         double[][] assetSpaceViewProjectionMatrix = new double[][]
  193.         {
  194.             {  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00,  0.00},
  195.             { -1.00,  1.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00},
  196.             {  0.00,  0.00,  0.90, -0.90,  0.10, -0.10,  0.00,  0.00}
  197.         };
  198.         double[] projectionExpectedExcessReturnsArray = new double[]
  199.         {
  200.             0.0525,
  201.             0.0025,
  202.             0.0200
  203.         };
  204.         double[] userSpecifiedProjectionConfidenceArray = new double[]
  205.         {
  206.             0.25,
  207.             0.50,
  208.             0.65
  209.         };

  210.         BlackLittermanCombinationEngine blackLittermanCombinationEngine =
  211.             new BlackLittermanCombinationEngine (
  212.                 ForwardReverseHoldingsAllocation.Reverse (
  213.                     Portfolio.Standard (
  214.                         assetIDArray,
  215.                         assetEquilibriumWeightArray
  216.                     ),
  217.                     assetExcessReturnsCovarianceMatrix,
  218.                     riskAversion
  219.                 ),
  220.                 new PriorControlSpecification (
  221.                     true,
  222.                     riskFreeRate,
  223.                     tau
  224.                 ),
  225.                 new ProjectionSpecification (
  226.                     R1MultivariateNormal.Standard (
  227.                         new MultivariateMeta (
  228.                             new String[]
  229.                             {
  230.                                 "PROJECTION #1",
  231.                                 "PROJECTION #2",
  232.                                 "PROJECTION #3"
  233.                             }
  234.                         ),
  235.                         projectionExpectedExcessReturnsArray,
  236.                         ProjectionDistributionLoading.ProjectionCovariance (
  237.                             assetExcessReturnsCovarianceMatrix,
  238.                             assetSpaceViewProjectionMatrix,
  239.                             tau
  240.                         )
  241.                     ),
  242.                     assetSpaceViewProjectionMatrix
  243.                 )
  244.             );

  245.         double[][] projectionTiltArray = blackLittermanCombinationEngine.userConfidenceProjectionTitMatrix (
  246.             userSpecifiedProjectionConfidenceArray
  247.         );

  248.         System.out.println ("\n\n");

  249.         for (int userSpecifiedProjectionConfidenceArrayIndex = 0;
  250.             userSpecifiedProjectionConfidenceArrayIndex < userSpecifiedProjectionConfidenceArray.length;
  251.             ++userSpecifiedProjectionConfidenceArrayIndex)
  252.         {
  253.             IdzorekImpliedProjectionConfidence (
  254.                 blackLittermanCombinationEngine,
  255.                 userSpecifiedProjectionConfidenceArrayIndex,
  256.                 projectionTiltArray[userSpecifiedProjectionConfidenceArrayIndex],
  257.                 userSpecifiedProjectionConfidenceArray[userSpecifiedProjectionConfidenceArrayIndex]
  258.             );
  259.         }

  260.         EnvManager.TerminateEnv();
  261.     }
  262. }