PathDateForwardCurves.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>PathDateForwardCurves</i> demonstrates the Simulations of the Per-Path Forward Vertex Date 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 PathDateForwardCurves {

  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.         double dblVolatility = 0.10;
  102.         String strTreasuryCode = "UST";

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

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

  123.         double[] adblTreasuryYield = new double[] {
  124.             0.0083, //  1Y
  125.             0.0122, //  2Y
  126.             0.0149, //  3Y
  127.             0.0193, //  5Y
  128.             0.0227, //  7Y
  129.             0.0248, // 10Y
  130.             0.0280, // 20Y
  131.             0.0308  // 30Y
  132.         };
  133.         int[] aiEventDate = new int[] {
  134.             DateUtil.CreateFromYMD (2020, 12,  1).julian(),
  135.             DateUtil.CreateFromYMD (2022, 12,  1).julian(),
  136.             DateUtil.CreateFromYMD (2024, 12,  1).julian(),
  137.             DateUtil.CreateFromYMD (2026, 12,  1).julian(),
  138.             DateUtil.CreateFromYMD (2028, 12,  1).julian(),
  139.             DateUtil.CreateFromYMD (2030, 12,  1).julian(),
  140.             DateUtil.CreateFromYMD (2032, 12,  1).julian(),
  141.             DateUtil.CreateFromYMD (2034, 12,  1).julian(),
  142.             DateUtil.CreateFromYMD (2036, 12,  1).julian(),
  143.             DateUtil.CreateFromYMD (2038, 12,  1).julian(),
  144.         };

  145.         int iNumVertex = aiEventDate.length;
  146.         int iNumDimension = astrTenor.length;
  147.         double[][] aadblCorrelation = new double[iNumDimension][iNumDimension];

  148.         for (int i = 0; i < iNumDimension; ++i) {
  149.             for (int j = 0; j < iNumDimension; ++j)
  150.                 aadblCorrelation[i][j] = i == j ? 1. : 0.;
  151.         }

  152.         PathVertexGovvie mcrg = PathVertexGovvie.Standard (
  153.             new GovvieBuilderSettings (
  154.                 dtSpot,
  155.                 strTreasuryCode,
  156.                 astrTenor,
  157.                 adblTreasuryCoupon,
  158.                 adblTreasuryYield
  159.             ),
  160.             new CorrelatedPathVertexDimension (
  161.                 new RandomNumberGenerator(),
  162.                 aadblCorrelation,
  163.                 iNumVertex,
  164.                 iNumPath,
  165.                 false,
  166.                 null
  167.             ),
  168.             new DiffusionEvolver (
  169.                 DiffusionEvaluatorLogarithmic.Standard (
  170.                     0.,
  171.                     dblVolatility
  172.                 )
  173.             )
  174.         );

  175.         GovvieCurve[][] aaGC = mcrg.pathVertex (aiEventDate);

  176.         System.out.println();

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

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

  179.         for (int iVertex = 0; iVertex < iNumVertex; ++iVertex)
  180.             strDump = strDump + " " + new JulianDate (aiEventDate[iVertex]) + " |";

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

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

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

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

  187.             System.out.println (strDump + "|");
  188.         }

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

  190.         System.out.println();

  191.         EnvManager.TerminateEnv();
  192.     }
  193. }