FV1_05Y.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>FV1_05Y</i> demonstrates the Details behind the Implementation and the Pricing of the 5Y FV1 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 FV1_05Y {

  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 fv1 = ExchangeInstrumentBuilder.TreasuryFutures (
  129.             dtSpot,
  130.             "UST",
  131.             new org.drip.analytics.date.JulianDate[] {
  132.                 DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY,  28), // 912828J5
  133.                 DateUtil.CreateFromYMD (2014, DateUtil.MARCH,     31), // 912828J8
  134.                 DateUtil.CreateFromYMD (2014, DateUtil.APRIL,     30), // 912828K5
  135.                 DateUtil.CreateFromYMD (2014, DateUtil.MAY,       31), // 912828XE
  136.                 DateUtil.CreateFromYMD (2014, DateUtil.JUNE,      30), // 912828XH
  137.                 DateUtil.CreateFromYMD (2014, DateUtil.JULY,      31), // 912828XM
  138.                 DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    31), // 912828L3
  139.                 DateUtil.CreateFromYMD (2014, DateUtil.SEPTEMBER, 30), // 912828L6
  140.                 DateUtil.CreateFromYMD (2014, DateUtil.OCTOBER,   31)  // 912828L9
  141.             },
  142.             new org.drip.analytics.date.JulianDate[] {
  143.                 DateUtil.CreateFromYMD (2020, DateUtil.FEBRUARY,  28), // 912828J5
  144.                 DateUtil.CreateFromYMD (2020, DateUtil.MARCH,     31), // 912828J8
  145.                 DateUtil.CreateFromYMD (2020, DateUtil.APRIL,     30), // 912828K5
  146.                 DateUtil.CreateFromYMD (2020, DateUtil.MAY,       31), // 912828XE
  147.                 DateUtil.CreateFromYMD (2020, DateUtil.JUNE,      30), // 912828XH
  148.                 DateUtil.CreateFromYMD (2020, DateUtil.JULY,      31), // 912828XM
  149.                 DateUtil.CreateFromYMD (2020, DateUtil.AUGUST,    31), // 912828L3
  150.                 DateUtil.CreateFromYMD (2020, DateUtil.SEPTEMBER, 30), // 912828L6
  151.                 DateUtil.CreateFromYMD (2020, DateUtil.OCTOBER,   31)  // 912828L9
  152.             },
  153.             new double[] {
  154.                 0.01375, // 912828J5
  155.                 0.01375, // 912828J8
  156.                 0.01375, // 912828K5
  157.                 0.01500, // 912828XE
  158.                 0.01625, // 912828XH
  159.                 0.01625, // 912828XM
  160.                 0.01375, // 912828L3
  161.                 0.01375, // 912828L6
  162.                 0.01375  // 912828L9
  163.             },
  164.             new double[] {
  165.                 0.8317, // 912828J5
  166.                 0.8287, // 912828J8
  167.                 0.8258, // 912828K5
  168.                 0.8276, // 912828XE
  169.                 0.8297, // 912828XH
  170.                 0.8269, // 912828XM
  171.                 0.8141, // 912828L3
  172.                 0.8113, // 912828L6
  173.                 0.8084  // 912828L9
  174.             },
  175.             "TREASURY",
  176.             "NOTE",
  177.             "5Y"
  178.         );

  179.         double dblFuturesPrice = 119.00000;

  180.         double[] adblCleanPrice = new double[] {
  181.              0.99909375, // 912828J5
  182.              0.99900000, // 912828J8
  183.              0.99890625, // 912828K5
  184.              0.99943750, // 912828XE
  185.              0.99984375, // 912828XH
  186.              0.99978125, // 912828XM
  187.              0.99862500, // 912828L3
  188.              0.99850000, // 912828L6
  189.              0.99853125  // 912828L9
  190.         };

  191.         Bond bondCTD = fv1.cheapestToDeliverYield (
  192.             dtSpot.julian(),
  193.             adblCleanPrice
  194.         ).bond();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  214.         System.out.println ("\t|---------------------------------------------||");
  215.     }
  216. }