PathVertexForwardCurves.java

  1. package org.drip.sample.govviemc;

  2. import org.drip.analytics.date.*;
  3. import org.drip.measure.crng.RandomNumberGenerator;
  4. import org.drip.measure.discrete.CorrelatedPathVertexDimension;
  5. import org.drip.measure.dynamics.DiffusionEvaluatorLogarithmic;
  6. import org.drip.measure.process.DiffusionEvolver;
  7. import org.drip.numerical.common.FormatUtil;
  8. import org.drip.service.env.EnvManager;
  9. import org.drip.state.govvie.GovvieCurve;
  10. import org.drip.state.sequence.*;

  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.  *
  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>PathVertexForwardCurves</i> demonstrates the Simulations of the Per-Path Forward Vertex Govvie Yield
  76.  * Curves.
  77.  *  
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  81.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  82.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  83.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/govviemc/README.md">Govvie Curve Monte Carlo Runs</a></li>
  84.  *  </ul>
  85.  * <br><br>
  86.  *
  87.  * @author Lakshmi Krishnamurthy
  88.  */

  89. public class PathVertexForwardCurves {

  90.     public static final void main (
  91.         final String[] astrArgs)
  92.         throws Exception
  93.     {
  94.         EnvManager.InitEnv ("");

  95.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  96.             2017,
  97.             DateUtil.MARCH,
  98.             24
  99.         );

  100.         int iNumPath = 50;
  101.         int iNumVertex = 10;
  102.         double dblTimeWidth = 1.0;
  103.         double dblVolatility = 0.10;
  104.         String strTreasuryCode = "UST";

  105.         String[] astrTenor = new String[] {
  106.             "01Y",
  107.             "02Y",
  108.             "03Y",
  109.             "05Y",
  110.             "07Y",
  111.             "10Y",
  112.             "20Y",
  113.             "30Y"
  114.         };

  115.         double[] adblTreasuryCoupon = new double[] {
  116.             0.0100,
  117.             0.0100,
  118.             0.0125,
  119.             0.0150,
  120.             0.0200,
  121.             0.0225,
  122.             0.0250,
  123.             0.0300
  124.         };

  125.         double[] adblTreasuryYield = new double[] {
  126.             0.0083, //  1Y
  127.             0.0122, //  2Y
  128.             0.0149, //  3Y
  129.             0.0193, //  5Y
  130.             0.0227, //  7Y
  131.             0.0248, // 10Y
  132.             0.0280, // 20Y
  133.             0.0308  // 30Y
  134.         };

  135.         int iNumDimension = astrTenor.length;
  136.         double[][] aadblCorrelation = new double[iNumDimension][iNumDimension];

  137.         for (int i = 0; i < iNumDimension; ++i) {
  138.             for (int j = 0; j < iNumDimension; ++j)
  139.                 aadblCorrelation[i][j] = i == j ? 1. : 0.;
  140.         }

  141.         PathVertexGovvie mcrg = PathVertexGovvie.Standard (
  142.             new GovvieBuilderSettings (
  143.                 dtSpot,
  144.                 strTreasuryCode,
  145.                 astrTenor,
  146.                 adblTreasuryCoupon,
  147.                 adblTreasuryYield
  148.             ),
  149.             new CorrelatedPathVertexDimension (
  150.                 new RandomNumberGenerator(),
  151.                 aadblCorrelation,
  152.                 iNumVertex,
  153.                 iNumPath,
  154.                 false,
  155.                 null
  156.             ),
  157.             new DiffusionEvolver (
  158.                 DiffusionEvaluatorLogarithmic.Standard (
  159.                     0.,
  160.                     dblVolatility
  161.                 )
  162.             )
  163.         );

  164.         GovvieCurve[][] aaGC = mcrg.pathVertex (dblTimeWidth);

  165.         System.out.println();

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

  167.         String strDump = "\t|| ## |";

  168.         for (int iVertex = 0; iVertex < iNumVertex; ++iVertex)
  169.             strDump = strDump + " " + dtSpot.addYears (iVertex) + " |";

  170.         System.out.println (strDump + "|");

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

  172.         for (int iPath = 0; iPath < iNumPath; ++iPath) {
  173.             strDump = "\t||" + FormatUtil.FormatDouble (iPath + 1, 2, 0, 1.) + " |";

  174.             for (int iVertex = 0; iVertex < iNumVertex; ++iVertex)
  175.                 strDump = strDump + "   " + FormatUtil.FormatDouble (aaGC[iPath][iVertex].yield ("5Y"), 1, 3, 100.) + "%   |";

  176.             System.out.println (strDump + "|");
  177.         }

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

  179.         System.out.println();

  180.         EnvManager.TerminateEnv();
  181.     }
  182. }