ForwardGovvieYield.java

  1. package org.drip.sample.intexfeed;

  2. import org.drip.analytics.date.*;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.service.template.LatentMarketStateBuilder;
  6. import org.drip.state.govvie.GovvieCurve;

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

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

  70. /**
  71.  * <i>ForwardGovvieYield</i> generates the Forward Govvie Yields over Monthly Increments with Maturity up to
  72.  * 60Y for different Govvie Tenors.
  73.  *  
  74.  * <br><br>
  75.  *  <ul>
  76.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  77.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  78.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  79.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/intexfeed/README.md">Intex Feed Inputs</a></li>
  80.  *  </ul>
  81.  * <br><br>
  82.  *
  83.  * @author Lakshmi Krishnamurthy
  84.  */

  85. public class ForwardGovvieYield {

  86.     private static final GovvieCurve GovvieCurve (
  87.         final JulianDate dtSpot,
  88.         final String strCode)
  89.         throws Exception
  90.     {
  91.         return LatentMarketStateBuilder.GovvieCurve (
  92.             strCode,
  93.             dtSpot,
  94.             new JulianDate[] {
  95.                 dtSpot,
  96.                 dtSpot,
  97.                 dtSpot,
  98.                 dtSpot,
  99.                 dtSpot,
  100.                 dtSpot,
  101.                 dtSpot,
  102.                 dtSpot
  103.             },
  104.             new JulianDate[] {
  105.                 dtSpot.addTenor ("1Y"),
  106.                 dtSpot.addTenor ("2Y"),
  107.                 dtSpot.addTenor ("3Y"),
  108.                 dtSpot.addTenor ("5Y"),
  109.                 dtSpot.addTenor ("7Y"),
  110.                 dtSpot.addTenor ("10Y"),
  111.                 dtSpot.addTenor ("20Y"),
  112.                 dtSpot.addTenor ("30Y")
  113.             },
  114.             new double[] {
  115.                 0.01219, //  1Y
  116.                 0.01391, //  2Y
  117.                 0.01590, //  3Y
  118.                 0.01937, //  5Y
  119.                 0.02200, //  7Y
  120.                 0.02378, // 10Y
  121.                 0.02677, // 20Y
  122.                 0.02927  // 30Y
  123.             },
  124.             new double[] {
  125.                 0.01219, //  1Y
  126.                 0.01391, //  2Y
  127.                 0.01590, //  3Y
  128.                 0.01937, //  5Y
  129.                 0.02200, //  7Y
  130.                 0.02378, // 10Y
  131.                 0.02677, // 20Y
  132.                 0.02927  // 30Y
  133.             },
  134.             "Yield",
  135.             LatentMarketStateBuilder.SHAPE_PRESERVING
  136.         );
  137.     }

  138.     public static final void main (
  139.         final String[] astrArgs)
  140.         throws Exception
  141.     {
  142.         /*
  143.          * Initialize the Credit Analytics Library
  144.          */

  145.         EnvManager.InitEnv ("");

  146.         int iNumMonth = 720;
  147.         String strCode = "UST";
  148.         String[] astrGovvieTenor = new String[] {
  149.              "1M",
  150.              "3M",
  151.              "6M",
  152.              "1Y",
  153.              "2Y",
  154.              "3Y",
  155.              "5Y",
  156.              "7Y",
  157.             "10Y",
  158.             "20Y",
  159.             "30Y"
  160.         };

  161.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  162.             2017,
  163.             DateUtil.OCTOBER,
  164.             5
  165.         );

  166.         GovvieCurve gc = GovvieCurve (
  167.             dtSpot,
  168.             strCode
  169.         );

  170.         System.out.println ("SpotDate,ForwardGap,ForwardTenor,ForwardStartDate,ForwardEndDate,ForwardYield");

  171.         for (int i = 0; i <= iNumMonth; ++i) {
  172.             JulianDate dtForward = dtSpot.addMonths (i);

  173.             for (int j = 0; j < astrGovvieTenor.length; ++j) {
  174.                 JulianDate dtMaturity = dtForward.addTenor (astrGovvieTenor[j]);

  175.                 System.out.println (
  176.                     dtSpot + "," +
  177.                     j + "," +
  178.                     astrGovvieTenor[j] + "," +
  179.                     dtForward + "," +
  180.                     dtMaturity + "," +
  181.                     FormatUtil.FormatDouble (
  182.                         gc.forwardYield (
  183.                             dtForward.julian(),
  184.                             dtMaturity.julian()
  185.                         ), 1, 8, 100.)
  186.                     + "%"
  187.                 );
  188.             }
  189.         }

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