FV1.java

  1. package org.drip.sample.treasuryfuturesapi;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.service.product.TreasuryFuturesAPI;

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

  9. /*!
  10.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  13.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  14.  *
  15.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  16.  *      libraries targeting analysts and developers
  17.  *      https://lakshmidrip.github.io/DRIP/
  18.  *  
  19.  *  DRIP is composed of four main libraries:
  20.  *  
  21.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  22.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  23.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  24.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  25.  *
  26.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  27.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  28.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  29.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  30.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  31.  *
  32.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  33.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  34.  *
  35.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  36.  *
  37.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  38.  *
  39.  *  Licensed under the Apache License, Version 2.0 (the "License");
  40.  *      you may not use this file except in compliance with the License.
  41.  *  
  42.  *  You may obtain a copy of the License at
  43.  *      http://www.apache.org/licenses/LICENSE-2.0
  44.  *  
  45.  *  Unless required by applicable law or agreed to in writing, software
  46.  *      distributed under the License is distributed on an "AS IS" BASIS,
  47.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  48.  *  
  49.  *  See the License for the specific language governing permissions and
  50.  *      limitations under the License.
  51.  */

  52. /**
  53.  * FV1 demonstrates the Invocation and Examination of the FV1 5Y UST Treasury Futures.
  54.  *
  55.  * @author Lakshmi Krishnamurthy
  56.  */

  57. public class FV1 {

  58.     public static final void main (
  59.         final String[] args)
  60.         throws Exception
  61.     {
  62.         EnvManager.InitEnv ("");

  63.         int[] aiFuturesComponentTreasuryEffectiveDate = new int[] {
  64.             DateUtil.CreateFromYMD (2014, DateUtil.FEBRUARY,  28).julian(), // 912828J5
  65.             DateUtil.CreateFromYMD (2014, DateUtil.MARCH,     31).julian(), // 912828J8
  66.             DateUtil.CreateFromYMD (2014, DateUtil.APRIL,     30).julian(), // 912828K5
  67.             DateUtil.CreateFromYMD (2014, DateUtil.MAY,       31).julian(), // 912828XE
  68.             DateUtil.CreateFromYMD (2014, DateUtil.JUNE,      30).julian(), // 912828XH
  69.             DateUtil.CreateFromYMD (2014, DateUtil.JULY,      31).julian(), // 912828XM
  70.             DateUtil.CreateFromYMD (2014, DateUtil.AUGUST,    31).julian(), // 912828L3
  71.             DateUtil.CreateFromYMD (2014, DateUtil.SEPTEMBER, 30).julian(), // 912828L6
  72.             DateUtil.CreateFromYMD (2014, DateUtil.OCTOBER,   31).julian()  // 912828L9
  73.         };

  74.         int[] aiFuturesComponentTreasuryMaturityDate = new int[] {
  75.             DateUtil.CreateFromYMD (2020, DateUtil.FEBRUARY,  28).julian(), // 912828J5
  76.             DateUtil.CreateFromYMD (2020, DateUtil.MARCH,     31).julian(), // 912828J8
  77.             DateUtil.CreateFromYMD (2020, DateUtil.APRIL,     30).julian(), // 912828K5
  78.             DateUtil.CreateFromYMD (2020, DateUtil.MAY,       31).julian(), // 912828XE
  79.             DateUtil.CreateFromYMD (2020, DateUtil.JUNE,      30).julian(), // 912828XH
  80.             DateUtil.CreateFromYMD (2020, DateUtil.JULY,      31).julian(), // 912828XM
  81.             DateUtil.CreateFromYMD (2020, DateUtil.AUGUST,    31).julian(), // 912828L3
  82.             DateUtil.CreateFromYMD (2020, DateUtil.SEPTEMBER, 30).julian(), // 912828L6
  83.             DateUtil.CreateFromYMD (2020, DateUtil.OCTOBER,   31).julian()  // 912828L9
  84.         };

  85.         double[] adblFuturesComponentTreasuryCoupon = new double[] {
  86.             0.01375, // 912828J5
  87.             0.01375, // 912828J8
  88.             0.01375, // 912828K5
  89.             0.01500, // 912828XE
  90.             0.01625, // 912828XH
  91.             0.01625, // 912828XM
  92.             0.01375, // 912828L3
  93.             0.01375, // 912828L6
  94.             0.01375  // 912828L9
  95.         };

  96.         double[] adblFuturesComponentConversionFactor = new double[] {
  97.             0.8317, // 912828J5
  98.             0.8287, // 912828J8
  99.             0.8258, // 912828K5
  100.             0.8276, // 912828XE
  101.             0.8297, // 912828XH
  102.             0.8269, // 912828XM
  103.             0.8141, // 912828L3
  104.             0.8113, // 912828L6
  105.             0.8084  // 912828L9
  106.         };

  107.         int iSpotDate = DateUtil.CreateFromYMD (
  108.             2015,
  109.             DateUtil.NOVEMBER,
  110.             18
  111.         ).julian();

  112.         String[] astrFundingCurveDepositTenor = new String[] {
  113.             "2D",
  114.             "1W",
  115.             "1M",
  116.             "2M",
  117.             "3M"
  118.         };

  119.         double[] adblFundingCurveDepositQuote = new double[] {
  120.             0.00195, // 2D
  121.             0.00176, // 1W
  122.             0.00301, // 1M
  123.             0.00401, // 2M
  124.             0.00492  // 3M
  125.         };

  126.         String strFundingCurveDepositMeasure = "ForwardRate";

  127.         double[] adblFundingCurveFuturesQuote = new double[] {
  128.             0.00609,
  129.             0.00687
  130.         };

  131.         String strFundingCurveFuturesMeasure = "ForwardRate";

  132.         String[] astrFundingCurveFixFloatTenor = new String[] {
  133.             "01Y",
  134.             "02Y",
  135.             "03Y",
  136.             "04Y",
  137.             "05Y",
  138.             "06Y",
  139.             "07Y",
  140.             "08Y",
  141.             "09Y",
  142.             "10Y",
  143.             "11Y",
  144.             "12Y",
  145.             "15Y",
  146.             "20Y",
  147.             "25Y",
  148.             "30Y",
  149.             "40Y",
  150.             "50Y"
  151.         };

  152.         double[] adblFundingCurveFixFloatQuote = new double[] {
  153.             0.00762, //  1Y
  154.             0.01055, //  2Y
  155.             0.01300, //  3Y
  156.             0.01495, //  4Y
  157.             0.01651, //  5Y
  158.             0.01787, //  6Y
  159.             0.01904, //  7Y
  160.             0.02005, //  8Y
  161.             0.02090, //  9Y
  162.             0.02166, // 10Y
  163.             0.02231, // 11Y
  164.             0.02289, // 12Y
  165.             0.02414, // 15Y
  166.             0.02570, // 20Y
  167.             0.02594, // 25Y
  168.             0.02627, // 30Y
  169.             0.02648, // 40Y
  170.             0.02632  // 50Y
  171.         };

  172.         String strFundingFixFloatMeasure = "SwapRate";

  173.         int[] aiGovvieCurveTreasuryEffectiveDate = new int[] {
  174.             iSpotDate,
  175.             iSpotDate,
  176.             iSpotDate,
  177.             iSpotDate,
  178.             iSpotDate,
  179.             iSpotDate,
  180.             iSpotDate
  181.         };

  182.         int[] aiGovvieCurveTreasuryMaturityDate = new int[] {
  183.             new JulianDate (iSpotDate).addTenor ("1Y").julian(),
  184.             new JulianDate (iSpotDate).addTenor ("2Y").julian(),
  185.             new JulianDate (iSpotDate).addTenor ("3Y").julian(),
  186.             new JulianDate (iSpotDate).addTenor ("5Y").julian(),
  187.             new JulianDate (iSpotDate).addTenor ("7Y").julian(),
  188.             new JulianDate (iSpotDate).addTenor ("10Y").julian(),
  189.             new JulianDate (iSpotDate).addTenor ("30Y").julian()
  190.         };

  191.         double[] adblGovvieCurveTreasuryCoupon = new double[] {
  192.             0.0100,
  193.             0.0100,
  194.             0.0125,
  195.             0.0150,
  196.             0.0200,
  197.             0.0225,
  198.             0.0300
  199.         };

  200.         double[] adblGovvieCurveTreasuryYield = new double[] {
  201.             0.00692,
  202.             0.00945,
  203.             0.01257,
  204.             0.01678,
  205.             0.02025,
  206.             0.02235,
  207.             0.02972
  208.         };

  209.         String strGovvieCurveTreasuryMeasure = "Yield";

  210.         double[] adblFuturesComponentTreasuryPrice = new double[] {
  211.              0.99909375, // 912828J5
  212.              0.99900000, // 912828J8
  213.              0.99890625, // 912828K5
  214.              0.99943750, // 912828XE
  215.              0.99984375, // 912828XH
  216.              0.99978125, // 912828XM
  217.              0.99862500, // 912828L3
  218.              0.99850000, // 912828L6
  219.              0.99853125  // 912828L9
  220.         };

  221.         Map<String, Double> mapTreasuryFutures = TreasuryFuturesAPI.ValuationMetrics (
  222.             "FV1",
  223.             aiFuturesComponentTreasuryEffectiveDate,
  224.             aiFuturesComponentTreasuryMaturityDate,
  225.             adblFuturesComponentTreasuryCoupon,
  226.             adblFuturesComponentConversionFactor,
  227.             iSpotDate,
  228.             astrFundingCurveDepositTenor,
  229.             adblFundingCurveDepositQuote,
  230.             strFundingCurveDepositMeasure,
  231.             adblFundingCurveFuturesQuote,
  232.             strFundingCurveFuturesMeasure,
  233.             astrFundingCurveFixFloatTenor,
  234.             adblFundingCurveFixFloatQuote,
  235.             strFundingFixFloatMeasure,
  236.             aiGovvieCurveTreasuryEffectiveDate,
  237.             aiGovvieCurveTreasuryMaturityDate,
  238.             adblGovvieCurveTreasuryCoupon,
  239.             adblGovvieCurveTreasuryYield,
  240.             strGovvieCurveTreasuryMeasure,
  241.             adblFuturesComponentTreasuryPrice
  242.         );

  243.         for (Map.Entry<String, Double> me : mapTreasuryFutures.entrySet())
  244.             System.out.println ("\t" + me.getKey() + " => " + me.getValue());
  245.     }
  246. }