BrokenDateSwapRate.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>BrokenDateSwapRate</i> generates the Swap 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 BrokenDateSwapRate {

  92.     private static final FixFloatComponent OTCIRS (
  93.         final JulianDate dtSpot,
  94.         final String strCurrency,
  95.         final String strMaturityTenor,
  96.         final double dblCoupon)
  97.     {
  98.         FixedFloatSwapConvention ffsc = IBORFixedFloatContainer.ConventionFromJurisdiction (
  99.             strCurrency,
  100.             "NYC",
  101.             strMaturityTenor,
  102.             "MAIN"
  103.         );

  104.         return ffsc.createFixFloatComponent (
  105.             dtSpot,
  106.             strMaturityTenor,
  107.             dblCoupon,
  108.             0.,
  109.             1.
  110.         );
  111.     }

  112.     private static final MergedDiscountForwardCurve FundingCurve (
  113.         final JulianDate dtSpot,
  114.         final String strCurrency)
  115.         throws Exception
  116.     {
  117.         String[] astrDepositMaturityTenor = new String[] {
  118.             "2D"
  119.         };

  120.         double[] adblDepositQuote = new double[] {
  121.             0.0130411 // 2D
  122.         };

  123.         double[] adblFuturesQuote = new double[] {
  124.             0.01345,    // 98.655
  125.             0.01470,    // 98.530
  126.             0.01575,    // 98.425
  127.             0.01660,    // 98.340
  128.             0.01745,    // 98.255
  129.             0.01845     // 98.155
  130.         };

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

  150.         double[] adblFixFloatQuote = new double[] {
  151.             0.016410, //  2Y
  152.             0.017863, //  3Y
  153.             0.019030, //  4Y
  154.             0.020035, //  5Y
  155.             0.020902, //  6Y
  156.             0.021660, //  7Y
  157.             0.022307, //  8Y
  158.             0.022879, //  9Y
  159.             0.023363, // 10Y
  160.             0.023820, // 11Y
  161.             0.024172, // 12Y
  162.             0.024934, // 15Y
  163.             0.025581, // 20Y
  164.             0.025906, // 25Y
  165.             0.025973, // 30Y
  166.             0.025838, // 40Y
  167.             0.025560  // 50Y
  168.         };

  169.         return LatentMarketStateBuilder.SmoothFundingCurve (
  170.             dtSpot,
  171.             strCurrency,
  172.             astrDepositMaturityTenor,
  173.             adblDepositQuote,
  174.             "ForwardRate",
  175.             adblFuturesQuote,
  176.             "ForwardRate",
  177.             astrFixFloatMaturityTenor,
  178.             adblFixFloatQuote,
  179.             "SwapRate"
  180.         );
  181.     }

  182.     public static final void main (
  183.         final String[] astrArgs)
  184.         throws Exception
  185.     {
  186.         EnvManager.InitEnv ("");

  187.         int iNumMonth = 720;
  188.         String strCurrency = "USD";

  189.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  190.             2017,
  191.             DateUtil.OCTOBER,
  192.             5
  193.         );

  194.         MergedDiscountForwardCurve mdfc = FundingCurve (
  195.             dtSpot,
  196.             strCurrency
  197.         );

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

  199.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  200.             mdfc,
  201.             null,
  202.             null,
  203.             null,
  204.             null,
  205.             null,
  206.             null
  207.         );

  208.         System.out.println ("SpotDate,MaturityTenor,MaturityDate,SwapRate,CleanFixedDV01");

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

  211.             FixFloatComponent ffc = OTCIRS (
  212.                 dtSpot,
  213.                 strCurrency,
  214.                 strMaturityTenor,
  215.                 0.
  216.             );

  217.             Map<String, Double> mapOutput = ffc.value (
  218.                 valParams,
  219.                 null,
  220.                 csqc,
  221.                 null
  222.             );

  223.             double dblSwapRate = mapOutput.get ("SwapRate");

  224.             double dblSwapDV01 = mapOutput.get ("CleanFixedDV01");

  225.             System.out.println (
  226.                 dtSpot + "," +
  227.                 strMaturityTenor + "," +
  228.                 ffc.maturityDate() + "," +
  229.                 FormatUtil.FormatDouble (dblSwapRate, 1, 8, 100.) + "%" + "," +
  230.                 FormatUtil.FormatDouble (dblSwapDV01, 1, 8, 10000.)
  231.             );
  232.         }

  233.         EnvManager.TerminateEnv();
  234.     }
  235. }