GovvieState.java

  1. package org.drip.template.state;

  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) 2020 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  13.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  14.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  15.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  16.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  17.  *
  18.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  19.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  20.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  21.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  22.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  23.  *      and computational support.
  24.  *  
  25.  *      https://lakshmidrip.github.io/DROP/
  26.  *  
  27.  *  DROP is composed of three modules:
  28.  *  
  29.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  30.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  31.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  32.  *
  33.  *  DROP Product Core implements libraries for the following:
  34.  *  - Fixed Income Analytics
  35.  *  - Loan Analytics
  36.  *  - Transaction Cost Analytics
  37.  *
  38.  *  DROP Portfolio Core implements libraries for the following:
  39.  *  - Asset Allocation Analytics
  40.  *  - Asset Liability Management Analytics
  41.  *  - Capital Estimation Analytics
  42.  *  - Exposure Analytics
  43.  *  - Margin Analytics
  44.  *  - XVA Analytics
  45.  *
  46.  *  DROP Computational Core implements libraries for the following:
  47.  *  - Algorithm Support
  48.  *  - Computation Support
  49.  *  - Function Analysis
  50.  *  - Model Validation
  51.  *  - Numerical Analysis
  52.  *  - Numerical Optimizer
  53.  *  - Spline Builder
  54.  *  - Statistical Learning
  55.  *
  56.  *  Documentation for DROP is Spread Over:
  57.  *
  58.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  59.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  60.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  61.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  62.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  63.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  64.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  65.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  66.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  67.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  68.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  69.  *
  70.  *  Licensed under the Apache License, Version 2.0 (the "License");
  71.  *      you may not use this file except in compliance with the License.
  72.  *  
  73.  *  You may obtain a copy of the License at
  74.  *      http://www.apache.org/licenses/LICENSE-2.0
  75.  *  
  76.  *  Unless required by applicable law or agreed to in writing, software
  77.  *      distributed under the License is distributed on an "AS IS" BASIS,
  78.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  79.  *  
  80.  *  See the License for the specific language governing permissions and
  81.  *      limitations under the License.
  82.  */

  83. /**
  84.  * <i>GovvieState</i> sets up the Calibration and the Construction of the Govvie Latent State and examine the
  85.  * Emitted Metrics.
  86.  *
  87.  *  <br><br>
  88.  *  <ul>
  89.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  90.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  91.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/README.md">Pricing/Risk Templates for Fixed Income Component Products</a></li>
  92.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/state/README.md">Standard Latent State Construction Template</a></li>
  93.  *  </ul>
  94.  * <br><br>
  95.  *
  96.  * @author Lakshmi Krishnamurthy
  97.  */

  98. public class GovvieState {

  99.     public static final void main (
  100.         final String[] astrArgs)
  101.         throws Exception
  102.     {
  103.         EnvManager.InitEnv ("");

  104.         JulianDate dtSpot = DateUtil.Today().addBusDays (
  105.             0,
  106.             "USD"
  107.         );

  108.         String strCode = "UST";

  109.         JulianDate[] adtEffective = new JulianDate[] {
  110.             DateUtil.CreateFromYMD (2010, DateUtil.SEPTEMBER, 21),
  111.             DateUtil.CreateFromYMD (2009, DateUtil.JULY, 14),
  112.             DateUtil.CreateFromYMD (2011, DateUtil.MARCH, 8),
  113.             DateUtil.CreateFromYMD (2010, DateUtil.AUGUST, 25),
  114.             DateUtil.CreateFromYMD (2010, DateUtil.DECEMBER, 3)
  115.         };

  116.         JulianDate[] adtMaturity = new JulianDate[] {
  117.             dtSpot.addTenor ("2Y"),
  118.             dtSpot.addTenor ("4Y"),
  119.             dtSpot.addTenor ("5Y"),
  120.             dtSpot.addTenor ("7Y"),
  121.             dtSpot.addTenor ("10Y")
  122.         };

  123.         double[] adblCoupon = new double[] {
  124.             0.0200,
  125.             0.0250,
  126.             0.0300,
  127.             0.0325,
  128.             0.0375
  129.         };

  130.         double[] adblYield = new double[] {
  131.             0.0200,
  132.             0.0250,
  133.             0.0300,
  134.             0.0325,
  135.             0.0375
  136.         };

  137.         GovvieCurve gc = LatentMarketStateBuilder.ShapePreservingGovvieCurve (
  138.             strCode,
  139.             dtSpot,
  140.             adtEffective,
  141.             adtMaturity,
  142.             adblCoupon,
  143.             adblYield,
  144.             "Yield"
  145.         );

  146.         String strLatentStateLabel = gc.label().fullyQualifiedName();

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

  148.         for (int i = 0; i < adtEffective.length; ++i)
  149.             System.out.println (
  150.                 "\t||  " + strLatentStateLabel + " |  TREASURY  | " +
  151.                 adtMaturity[i] + " | " + FormatUtil.FormatDouble (adblYield[i], 1, 2, 100.) +
  152.                 "% | Yield | " +
  153.                 FormatUtil.FormatDouble (gc.yield (adtMaturity[i]), 1, 2, 100.) +
  154.                 "% | Discount Factor | " +
  155.                 FormatUtil.FormatDouble (gc.df (adtMaturity[i]), 1, 4, 1.) +
  156.                 "  ||"
  157.             );

  158.         System.out.println ("\t||---------------------------------------------------------------------------------------||\n");
  159.     }
  160. }