US1_30Y.java

  1. package org.drip.template.ust;

  2. import org.drip.analytics.date.*;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.product.definition.Bond;
  5. import org.drip.product.govvie.TreasuryFutures;
  6. import org.drip.service.env.EnvManager;
  7. import org.drip.service.template.ExchangeInstrumentBuilder;

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

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

  84. /**
  85.  * <i>US1_30Y</i> demonstrates the Details behind the Implementation and the Pricing of the 30Y US1 UST
  86.  * Futures Contract.
  87.  *
  88.  *  <br><br>
  89.  *  <ul>
  90.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  91.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  92.  *      <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>
  93.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/ust/README.md">Standard UST Suite Construction Template</a></li>
  94.  *  </ul>
  95.  * <br><br>
  96.  *
  97.  * @author Lakshmi Krishnamurthy
  98.  */

  99. public class US1_30Y {

  100.     private static final String DeliveryMonths (
  101.         final TreasuryFutures tsyFutures)
  102.     {
  103.         int[] aiDeliveryMonth = tsyFutures.deliveryMonths();

  104.         String strDeliveryMonths = "";
  105.         int iNumDeliveryMonth = null == aiDeliveryMonth ? 0 : aiDeliveryMonth.length;

  106.         if (0 != iNumDeliveryMonth) {
  107.             for (int i = 0; i < iNumDeliveryMonth; ++i) {
  108.                 if (0 == i)
  109.                     strDeliveryMonths += "{";
  110.                 else
  111.                     strDeliveryMonths += ",";

  112.                 strDeliveryMonths += DateUtil.MonthChar (aiDeliveryMonth[i]);
  113.             }

  114.             strDeliveryMonths += "}";
  115.         }

  116.         return strDeliveryMonths;
  117.     }

  118.     public static final void main (
  119.         final String[] astrArgs)
  120.         throws Exception
  121.     {
  122.         EnvManager.InitEnv ("");

  123.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  124.             2015,
  125.             DateUtil.NOVEMBER,
  126.             18
  127.         );

  128.         TreasuryFutures us1 = ExchangeInstrumentBuilder.TreasuryFutures (
  129.             dtSpot,
  130.             "UST",
  131.             new org.drip.analytics.date.JulianDate[] {
  132.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY, 15), // 912810FT
  133.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,      15), // 912810PU
  134.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY, 15), // 912810PT
  135.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,      15), // 912810PX
  136.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY, 15), // 912810PW
  137.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,   15), // 912810QC
  138.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY, 15), // 912810QE
  139.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,      15), // 912810QB
  140.                 DateUtil.CreateFromYMD (2014, DateUtil.NOVEMBER, 15), // 912810QD
  141.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,      15), // 912810QH
  142.                 DateUtil.CreateFromYMD (2014, DateUtil.NOVEMBER, 15), // 912810QL
  143.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,   15), // 912810QK
  144.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY, 15)  // 912810QA
  145.             },
  146.             new org.drip.analytics.date.JulianDate[] {
  147.                 DateUtil.CreateFromYMD (2036, DateUtil.FEBRUARY, 15), // 912810FT
  148.                 DateUtil.CreateFromYMD (2037, DateUtil.MAY,      15), // 912810PU
  149.                 DateUtil.CreateFromYMD (2037, DateUtil.FEBRUARY, 15), // 912810PT
  150.                 DateUtil.CreateFromYMD (2038, DateUtil.MAY,      15), // 912810PX
  151.                 DateUtil.CreateFromYMD (2038, DateUtil.FEBRUARY, 15), // 912810PW
  152.                 DateUtil.CreateFromYMD (2039, DateUtil.AUGUST,   15), // 912810QC
  153.                 DateUtil.CreateFromYMD (2040, DateUtil.FEBRUARY, 15), // 912810QE
  154.                 DateUtil.CreateFromYMD (2039, DateUtil.MAY,      15), // 912810QB
  155.                 DateUtil.CreateFromYMD (2039, DateUtil.NOVEMBER, 15), // 912810QD
  156.                 DateUtil.CreateFromYMD (2040, DateUtil.MAY,      15), // 912810QH
  157.                 DateUtil.CreateFromYMD (2040, DateUtil.NOVEMBER, 15), // 912810QL
  158.                 DateUtil.CreateFromYMD (2040, DateUtil.AUGUST,   15), // 912810QK
  159.                 DateUtil.CreateFromYMD (2039, DateUtil.FEBRUARY, 15)  // 912810QA
  160.             },
  161.             new double[] {
  162.                 0.04500, // 912810FT
  163.                 0.05000, // 912810PU
  164.                 0.04750, // 912810PT
  165.                 0.04500, // 912810PX
  166.                 0.04375, // 912810PW
  167.                 0.04500, // 912810QC
  168.                 0.04625, // 912810QE
  169.                 0.04250, // 912810QB
  170.                 0.04375, // 912810QD
  171.                 0.04375, // 912810QH
  172.                 0.04250, // 912810QL
  173.                 0.03875, // 912810QK
  174.                 0.03500  // 912810QA
  175.             },
  176.             new double[] {
  177.                 0.8266, // 912810FT
  178.                 0.8807, // 912810PU
  179.                 0.8519, // 912810PT
  180.                 0.8170, // 912810PX
  181.                 0.8029, // 912810PW
  182.                 0.8123, // 912810QC
  183.                 0.8263, // 912810QE
  184.                 0.7820, // 912810QB
  185.                 0.7956, // 912810QD
  186.                 0.7939, // 912810QH
  187.                 0.7758, // 912810QL
  188.                 0.7290, // 912810QK
  189.                 0.6903, // 912810QA
  190.             },
  191.             "TREASURY",
  192.             "BOND",
  193.             "30Y"
  194.         );

  195.         double dblFuturesPrice = 153.750000;

  196.         double[] adblCleanPrice = new double[] {
  197.             1.2765625, // 912810FT
  198.             1.3643750, // 912810PU
  199.             1.3203125, // 912810PT
  200.             1.2775000, // 912810PX
  201.             1.2556250, // 912810PW
  202.             1.2731250, // 912810QC
  203.             1.2956250, // 912810QE
  204.             1.2287500, // 912810QB
  205.             1.2506250, // 912810QD
  206.             1.2506250, // 912810QH
  207.             1.2281250, // 912810QL
  208.             1.1603125, // 912810QK
  209.             1.1009375  // 912810QA
  210.         };

  211.         Bond bondCTD = us1.cheapestToDeliverYield (
  212.             dtSpot.julian(),
  213.             adblCleanPrice
  214.         ).bond();

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

  216.         System.out.println ("\t|      Futures Type      : " + us1.type() + "                            ||");

  217.         System.out.println ("\t|      Deliverable Grade : " + us1.minimumMaturity() + " -> " + us1.maximumMaturity() + "                     ||");

  218.         System.out.println ("\t|      Reference Coupon  : " + FormatUtil.FormatDouble (us1.referenceCoupon(), 1, 2, 100.) + "%                         ||");

  219.         System.out.println ("\t|      Contract Size     : " + FormatUtil.FormatDouble (us1.notionalValue(), 1, 2, 1.) + "                     ||");

  220.         System.out.println ("\t|      Tick Size         : " + FormatUtil.FormatDouble (us1.minimumPriceMovement(), 1, 6, 1.) + "                      ||");

  221.         System.out.println ("\t|      Tick Value        : " + FormatUtil.FormatDouble (us1.tickValue(), 1, 2, 1.) + "                       ||");

  222.         System.out.println ("\t|      Delivery Months   : " + DeliveryMonths (us1) + " ||");

  223.         System.out.println ("\t|      Last Trading Lag  : " + us1.lastTradingDayLag() + " Business Days Prior Expiry   ||");

  224.         System.out.println ("\t|      Futures Price     : " + FormatUtil.FormatDouble (dblFuturesPrice, 2, 5, 1.) + "                     ||");

  225.         System.out.println ("\t|      Contract Value    : " + FormatUtil.FormatDouble (0.01 * us1.notionalValue() * dblFuturesPrice, 1, 2, 1.) + "                     ||");

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

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

  228.         System.out.println ("\t|                                              ||");

  229.         for (int i = 0; i < us1.basket().length; ++i)
  230.             System.out.println ("\t|\t" + us1.basket()[i].name() + " => " + FormatUtil.FormatDouble (adblCleanPrice[i], 2, 5, 1.) + "   ||");

  231.         System.out.println ("\t|                                              ||");

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

  233.         System.out.println ("\t| Cheapest to Deliver: " + bondCTD.name() + "  ||");

  234.         System.out.println ("\t|----------------------------------------------||");
  235.     }
  236. }