GovvieStateShifted.java

  1. package org.drip.template.statebump;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.param.valuation.ValuationParams;
  6. import org.drip.product.credit.BondComponent;
  7. import org.drip.product.govvie.TreasuryComponent;
  8. import org.drip.service.env.EnvManager;
  9. import org.drip.service.template.*;
  10. import org.drip.state.govvie.GovvieCurve;

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

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

  87. /**
  88.  * <i>GovvieStateShifted</i> demonstrates the Construction and Usage of Tenor Bumped Govvie Curves.
  89.  *
  90.  *  <br><br>
  91.  *  <ul>
  92.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  93.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  94.  *      <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>
  95.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/statebump/README.md">Shifted Latent State Construction Template</a></li>
  96.  *  </ul>
  97.  * <br><br>
  98.  *
  99.  * @author Lakshmi Krishnamurthy
  100.  */

  101. public class GovvieStateShifted {

  102.     public static final void main (
  103.         final String[] astrArgs)
  104.         throws Exception
  105.     {
  106.         EnvManager.InitEnv ("");

  107.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  108.             2017,
  109.             DateUtil.DECEMBER,
  110.             21
  111.         );

  112.         String strCode = "UST";
  113.         double dblBump = 0.0001;
  114.         boolean bIsBumpProportional = false;

  115.         JulianDate[] adtEffective = new JulianDate[] {
  116.             DateUtil.CreateFromYMD (2010, DateUtil.SEPTEMBER, 21),
  117.             DateUtil.CreateFromYMD (2009, DateUtil.JULY, 14),
  118.             DateUtil.CreateFromYMD (2011, DateUtil.MARCH, 8),
  119.             DateUtil.CreateFromYMD (2010, DateUtil.AUGUST, 25),
  120.             DateUtil.CreateFromYMD (2010, DateUtil.DECEMBER, 3)
  121.         };

  122.         JulianDate[] adtMaturity = new JulianDate[] {
  123.             dtSpot.addTenor ("2Y"),
  124.             dtSpot.addTenor ("4Y"),
  125.             dtSpot.addTenor ("5Y"),
  126.             dtSpot.addTenor ("7Y"),
  127.             dtSpot.addTenor ("10Y")
  128.         };

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

  136.         double[] adblYield = new double[] {
  137.             0.0200,
  138.             0.0250,
  139.             0.0300,
  140.             0.0325,
  141.             0.0375
  142.         };

  143.         Map<String, GovvieCurve> mapBumpedGovvieCurve = LatentMarketStateBuilder.BumpedGovvieCurve (
  144.             strCode,
  145.             dtSpot,
  146.             adtEffective,
  147.             adtMaturity,
  148.             adblCoupon,
  149.             adblYield,
  150.             "Yield",
  151.             LatentMarketStateBuilder.SHAPE_PRESERVING,
  152.             dblBump,
  153.             bIsBumpProportional
  154.         );

  155.         TreasuryComponent[] aTreasury = TreasuryBuilder.FromCode (
  156.             strCode,
  157.             adtEffective,
  158.             adtMaturity,
  159.             adblCoupon
  160.         );

  161.         ValuationParams valParams = ValuationParams.Spot (dtSpot.julian());

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

  163.         for (Map.Entry<String, GovvieCurve> meGovvie : mapBumpedGovvieCurve.entrySet()) {
  164.             String strKey = meGovvie.getKey();

  165.             if (!strKey.startsWith ("tsy")) continue;

  166.             System.out.print ("\t|  [" + meGovvie.getKey() + "] => ");

  167.             GovvieCurve gc = meGovvie.getValue();

  168.             for (BondComponent treasury : aTreasury)
  169.                 System.out.print (FormatUtil.FormatDouble (treasury.yieldFromPrice (
  170.                     valParams,
  171.                     null,
  172.                     null,
  173.                     treasury.maturityDate().julian(),
  174.                     1.,
  175.                     treasury.priceFromYield (
  176.                         valParams,
  177.                         null,
  178.                         null,
  179.                         gc.yield (treasury.maturityDate().julian())
  180.                     )
  181.                 ), 1, 4, 1.) + " |"
  182.             );

  183.             System.out.print ("|\n");
  184.         }

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

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

  187.         GovvieCurve gcBase = mapBumpedGovvieCurve.get ("Base");

  188.         GovvieCurve gcBump = mapBumpedGovvieCurve.get ("Bump");

  189.         for (TreasuryComponent treasury : aTreasury)
  190.             System.out.println (
  191.                 "\t| YIELD => " +
  192.                 treasury.maturityDate() + " |" +
  193.                 FormatUtil.FormatDouble (treasury.yieldFromPrice (
  194.                     valParams,
  195.                     null,
  196.                     null,
  197.                     treasury.maturityDate().julian(),
  198.                     1.,
  199.                     treasury.priceFromYield (
  200.                         valParams,
  201.                         null,
  202.                         null,
  203.                         gcBase.yield (treasury.maturityDate().julian())
  204.                     )
  205.                 ), 1, 2, 100.) + "% |" +
  206.                 FormatUtil.FormatDouble (treasury.yieldFromPrice (
  207.                     valParams,
  208.                     null,
  209.                     null,
  210.                     treasury.maturityDate().julian(),
  211.                     1.,
  212.                     treasury.priceFromYield (
  213.                         valParams,
  214.                         null,
  215.                         null,
  216.                         gcBump.yield (treasury.maturityDate().julian())
  217.                     )
  218.                 ), 1, 2, 100.) + "% ||"
  219.             );

  220.         System.out.println ("\t|-------------------------------------||");
  221.     }
  222. }