BrokenDateOISRate.java

  1. package org.drip.sample.intexfeed;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.market.otc.*;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.param.creator.MarketParamsBuilder;
  7. import org.drip.param.market.CurveSurfaceQuoteContainer;
  8. import org.drip.param.valuation.ValuationParams;
  9. import org.drip.product.rates.FixFloatComponent;
  10. import org.drip.service.env.EnvManager;
  11. import org.drip.service.template.LatentMarketStateBuilder;
  12. import org.drip.state.discount.MergedDiscountForwardCurve;

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

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

  77. /**
  78.  * <i>BrokenDateOISRate</i> generates the OIS Rate for Monthly Increments in Maturity over 60 Years.
  79.  *  
  80.  * <br><br>
  81.  *  <ul>
  82.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  83.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  84.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  85.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/intexfeed/README.md">Intex Feed Inputs</a></li>
  86.  *  </ul>
  87.  * <br><br>
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class BrokenDateOISRate {

  92.     private static final FixFloatComponent OTCOISFixFloat (
  93.         final JulianDate dtSpot,
  94.         final String strCurrency,
  95.         final String strMaturityTenor)
  96.     {
  97.         FixedFloatSwapConvention ffsc = OvernightFixedFloatContainer.FundConventionFromJurisdiction (
  98.             strCurrency
  99.         );

  100.         return ffsc.createFixFloatComponent (
  101.             dtSpot,
  102.             strMaturityTenor,
  103.             0.,
  104.             0.,
  105.             1.
  106.         );
  107.     }

  108.     private static final MergedDiscountForwardCurve OvernightCurve (
  109.         final JulianDate dtSpot,
  110.         final String strCurrency)
  111.         throws Exception
  112.     {
  113.         String[] astrDepositMaturityTenor = new String[] {
  114.             "1D",
  115.             // "3D"
  116.         };

  117.         double[] adblDepositQuote = new double[] {
  118.             0.0004,     // 1D
  119.             // 0.0004       // 3D
  120.         };

  121.         String[] astrShortEndOISMaturityTenor = new String[] {
  122.             "1W",
  123.             "2W",
  124.             "3W",
  125.             "1M"
  126.         };

  127.         double[] adblShortEndOISQuote = new double[] {
  128.             0.00070,    //   1W
  129.             0.00069,    //   2W
  130.             0.00078,    //   3W
  131.             0.00074     //   1M
  132.         };

  133.         String[] astrOISFuturesEffectiveTenor = new String[] {
  134.             "1M",
  135.             "2M",
  136.             "3M",
  137.             "4M",
  138.             "5M"
  139.         };

  140.         String[] astrOISFuturesMaturityTenor = new String[] {
  141.             "1M",
  142.             "1M",
  143.             "1M",
  144.             "1M",
  145.             "1M"
  146.         };

  147.         double[] adblOISFuturesQuote = new double[] {
  148.              0.00046,    //   1M x 1M
  149.              0.00016,    //   2M x 1M
  150.             -0.00007,    //   3M x 1M
  151.             -0.00013,    //   4M x 1M
  152.             -0.00014     //   5M x 1M
  153.         };

  154.         String[] astrLongEndOISMaturityTenor = new String[] {
  155.             "15M",
  156.             "18M",
  157.             "21M",
  158.             "02Y",
  159.             "03Y",
  160.             "04Y",
  161.             "05Y",
  162.             "06Y",
  163.             "07Y",
  164.             "08Y",
  165.             "09Y",
  166.             "10Y",
  167.             "11Y",
  168.             "12Y",
  169.             "15Y",
  170.             "20Y",
  171.             "25Y",
  172.             "30Y"
  173.         };

  174.         double[] adblLongEndOISQuote = new double[] {
  175.             0.00002,    //  15M
  176.             0.00008,    //  18M
  177.             0.00021,    //  21M
  178.             0.00036,    //   2Y
  179.             0.00127,    //   3Y
  180.             0.00274,    //   4Y
  181.             0.00456,    //   5Y
  182.             0.00647,    //   6Y
  183.             0.00827,    //   7Y
  184.             0.00996,    //   8Y
  185.             0.01147,    //   9Y
  186.             0.01280,    //  10Y
  187.             0.01404,    //  11Y
  188.             0.01516,    //  12Y
  189.             0.01764,    //  15Y
  190.             0.01939,    //  20Y
  191.             0.02003,    //  25Y
  192.             0.02038     //  30Y
  193.         };

  194.         return LatentMarketStateBuilder.SmoothOvernightCurve (
  195.             dtSpot,
  196.             strCurrency,
  197.             astrDepositMaturityTenor,
  198.             adblDepositQuote,
  199.             "Rate",
  200.             astrShortEndOISMaturityTenor,
  201.             adblShortEndOISQuote,
  202.             "SwapRate",
  203.             astrOISFuturesEffectiveTenor,
  204.             astrOISFuturesMaturityTenor,
  205.             adblOISFuturesQuote,
  206.             "SwapRate",
  207.             astrLongEndOISMaturityTenor,
  208.             adblLongEndOISQuote,
  209.             "SwapRate"
  210.         );
  211.     }

  212.     public static final void main (
  213.         final String[] astrArgs)
  214.         throws Exception
  215.     {
  216.         EnvManager.InitEnv ("");

  217.         int iNumMonth = 720;
  218.         String strCurrency = "USD";

  219.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  220.             2017,
  221.             DateUtil.OCTOBER,
  222.             5
  223.         );

  224.         MergedDiscountForwardCurve mdfc = OvernightCurve (
  225.             dtSpot,
  226.             strCurrency
  227.         );

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

  229.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  230.             mdfc,
  231.             null,
  232.             null,
  233.             null,
  234.             null,
  235.             null,
  236.             null
  237.         );

  238.         for (int i = 1; i <= iNumMonth; ++i) {
  239.             String strMaturityTenor = i + "M";

  240.             FixFloatComponent ffc = OTCOISFixFloat (
  241.                 dtSpot,
  242.                 strCurrency,
  243.                 strMaturityTenor
  244.             );

  245.             Map<String, Double> mapOutput = ffc.value (
  246.                 valParams,
  247.                 null,
  248.                 csqc,
  249.                 null
  250.             );

  251.             double dblOISRate = mapOutput.get ("SwapRate");

  252.             double dblOISDV01 = mapOutput.get ("CleanFixedDV01");

  253.             System.out.println (
  254.                 dtSpot + "," +
  255.                 strMaturityTenor + "," +
  256.                 ffc.maturityDate() + "," +
  257.                 FormatUtil.FormatDouble (dblOISRate, 1, 8, 100.) + "%" + "," +
  258.                 FormatUtil.FormatDouble (dblOISDV01, 1, 8, 10000.)
  259.             );
  260.         }

  261.         EnvManager.TerminateEnv();
  262.     }
  263. }