TY1_10Y.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>TY1_10Y</i> demonstrates the Details behind the Implementation and the Pricing of the 10Y TY1 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 TY1_10Y {

  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 ty1 = ExchangeInstrumentBuilder.TreasuryFutures (
  129.             dtSpot,
  130.             "UST",
  131.             new org.drip.analytics.date.JulianDate[] {
  132.                 DateUtil.CreateFromYMD (2014, DateUtil.JUNE,      30), // 912828XG
  133.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    31), // 912828L2
  134.                 DateUtil.CreateFromYMD (2014, DateUtil.JULY,      31), // 912828XQ
  135.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    15), // 912828TJ
  136.                 DateUtil.CreateFromYMD (2014, DateUtil.OCTOBER,   31), // 912828M4
  137.                 DateUtil.CreateFromYMD (2014, DateUtil.SEPTEMBER, 30), // 912828L5
  138.                 DateUtil.CreateFromYMD (2014, DateUtil.NOVEMBER,  15), // 912828TY
  139.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY,  15), // 912828UN
  140.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,       15), // 912828VB
  141.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    15), // 912828VS
  142.                 DateUtil.CreateFromYMD (2014, DateUtil.NOVEMBER,  15), // 912828WE
  143.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY,  15), // 912828B6
  144.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,       15), // 912828WJ
  145.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    15), // 912828D5
  146.                 DateUtil.CreateFromYMD (2014, DateUtil.NOVEMBER,  15), // 912828G3
  147.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY,  15), // 912828J2
  148.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,       15), // 912828XB
  149.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    15), // 912828K7
  150.                 DateUtil.CreateFromYMD (2014, DateUtil.NOVEMBER,  15)  // 912828M5
  151.             },
  152.             new org.drip.analytics.date.JulianDate[] {
  153.                 DateUtil.CreateFromYMD (2022, DateUtil.JUNE,      30), // 912828XG
  154.                 DateUtil.CreateFromYMD (2022, DateUtil.AUGUST,    31), // 912828L2
  155.                 DateUtil.CreateFromYMD (2022, DateUtil.JULY,      31), // 912828XQ
  156.                 DateUtil.CreateFromYMD (2022, DateUtil.AUGUST,    15), // 912828TJ
  157.                 DateUtil.CreateFromYMD (2022, DateUtil.OCTOBER,   31), // 912828M4
  158.                 DateUtil.CreateFromYMD (2022, DateUtil.SEPTEMBER, 30), // 912828L5
  159.                 DateUtil.CreateFromYMD (2022, DateUtil.NOVEMBER,  15), // 912828TY
  160.                 DateUtil.CreateFromYMD (2023, DateUtil.FEBRUARY,  15), // 912828UN
  161.                 DateUtil.CreateFromYMD (2023, DateUtil.MAY,       15), // 912828VB
  162.                 DateUtil.CreateFromYMD (2023, DateUtil.AUGUST,    15), // 912828VS
  163.                 DateUtil.CreateFromYMD (2023, DateUtil.NOVEMBER,  15), // 912828WE
  164.                 DateUtil.CreateFromYMD (2024, DateUtil.FEBRUARY,  15), // 912828B6
  165.                 DateUtil.CreateFromYMD (2024, DateUtil.MAY,       15), // 912828WJ
  166.                 DateUtil.CreateFromYMD (2024, DateUtil.AUGUST,    15), // 912828D5
  167.                 DateUtil.CreateFromYMD (2024, DateUtil.NOVEMBER,  15), // 912828G3
  168.                 DateUtil.CreateFromYMD (2025, DateUtil.FEBRUARY,  15), // 912828J2
  169.                 DateUtil.CreateFromYMD (2025, DateUtil.MAY,       15), // 912828XB
  170.                 DateUtil.CreateFromYMD (2025, DateUtil.AUGUST,    15), // 912828K7
  171.                 DateUtil.CreateFromYMD (2025, DateUtil.NOVEMBER,  15)  // 912828M5
  172.             },
  173.             new double[] {
  174.                 0.02125, // 912828XG
  175.                 0.01875, // 912828L2
  176.                 0.02000, // 912828XQ
  177.                 0.01625, // 912828TJ
  178.                 0.01875, // 912828M4
  179.                 0.01875, // 912828L5
  180.                 0.01625, // 912828TY
  181.                 0.02000, // 912828UN
  182.                 0.01750, // 912828VB
  183.                 0.02500, // 912828VS
  184.                 0.02750, // 912828WE
  185.                 0.02750, // 912828B6
  186.                 0.02500, // 912828WJ
  187.                 0.02375, // 912828D5
  188.                 0.02250, // 912828G3
  189.                 0.02000, // 912828J2
  190.                 0.02125, // 912828XB
  191.                 0.02000, // 912828K7
  192.                 0.02125  // 912828M5
  193.             },
  194.             new double[] {
  195.                 0.7939, // 912828XG
  196.                 0.7807, // 912828L2
  197.                 0.7873, // 912828XQ
  198.                 0.7674, // 912828TJ
  199.                 0.7738, // 912828M4
  200.                 0.7669, // 912828L5
  201.                 0.7600, // 912828TY
  202.                 0.7741, // 912828UN
  203.                 0.7531, // 912828VB
  204.                 0.7911, // 912828VS
  205.                 0.8009, // 912828WE
  206.                 0.7959, // 912828B6
  207.                 0.7748, // 912828WJ
  208.                 0.7614, // 912828D5
  209.                 0.7475, // 912828G3
  210.                 0.7249, // 912828J2
  211.                 0.7279, // 912828XB
  212.                 0.7135, // 912828K7
  213.                 0.7262  // 912828M5
  214.             },
  215.             "TREASURY",
  216.             "NOTE",
  217.             "10Y"
  218.         );

  219.         double dblFuturesPrice = 126.578125;

  220.         double[] adblCleanPrice = new double[] {
  221.             1.0071875, // 912828XG
  222.             0.9903125, // 912828L2
  223.             0.9990625, // 912828XQ
  224.             0.9756250, // 912828TJ
  225.             0.9893750, // 912828M4
  226.             0.9818750, // 912828L5
  227.             0.9734375, // 912828TY
  228.             0.9968750, // 912828UN
  229.             0.9756250, // 912828VB
  230.             1.0281250, // 912828VS
  231.             1.0459375, // 912828WE
  232.             1.0443750, // 912828B6
  233.             1.0231250, // 912828WJ
  234.             1.0128125, // 912828D5
  235.             0.9996875, // 912828G3
  236.             0.9768750, // 912828J2
  237.             0.9865625, // 912828XB
  238.             0.9750000, // 912828K7
  239.             0.9978125  // 912828M5
  240.         };

  241.         Bond bondCTD = ty1.cheapestToDeliverYield (
  242.             dtSpot.julian(),
  243.             adblCleanPrice
  244.         ).bond();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  264.         System.out.println ("\t|---------------------------------------------||");
  265.     }
  266. }