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

  76. /**
  77.  * <i>ForwardSwapRate</i> generates the Forward Swap Rates over Monthly Increments with Maturity up to 60
  78.  * Years for different Swap Tenors.
  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 ForwardSwapRate {

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

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

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

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

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

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

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

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

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

  186.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  187.             2017,
  188.             DateUtil.OCTOBER,
  189.             5
  190.         );

  191.         int iNumMonth = 720;
  192.         String strCurrency = "USD";
  193.         String[] astrSwapTenor = new String[] {
  194.             "02Y",
  195.             "03Y",
  196.             "04Y",
  197.             "05Y",
  198.             "06Y",
  199.             "07Y",
  200.             "08Y",
  201.             "09Y",
  202.             "10Y",
  203.             "11Y",
  204.             "12Y",
  205.             "15Y",
  206.             "20Y",
  207.             "25Y",
  208.             "30Y",
  209.             "40Y",
  210.             "50Y"
  211.         };

  212.         MergedDiscountForwardCurve mdfc = FundingCurve (
  213.             dtSpot,
  214.             strCurrency
  215.         );

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

  217.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  218.             mdfc,
  219.             null,
  220.             null,
  221.             null,
  222.             null,
  223.             null,
  224.             null
  225.         );

  226.         System.out.println ("SpotDate,ForwardDate,MaturityTenor,MaturityDate,SwapRate,SpotDV01,ForwardDV01");

  227.         for (int i = 0; i <= iNumMonth; ++i) {
  228.             JulianDate dtForward = dtSpot.addMonths (i);

  229.             double dblDFForward = mdfc.df (dtForward);

  230.             for (int j = 0; j < astrSwapTenor.length; ++j) {
  231.                 FixFloatComponent ffc = OTCIRS (
  232.                     dtForward,
  233.                     strCurrency,
  234.                     astrSwapTenor[j]
  235.                 );

  236.                 Map<String, Double> mapOutput = ffc.value (
  237.                     valParams,
  238.                     null,
  239.                     csqc,
  240.                     null
  241.                 );

  242.                 double dblForwardSwapRate = mapOutput.get ("SwapRate");

  243.                 double dblForwardSwapDV01 = mapOutput.get ("CleanFixedDV01");

  244.                 System.out.println (
  245.                     dtSpot + "," +
  246.                     dtForward + "," +
  247.                     astrSwapTenor[j] + "," +
  248.                     ffc.maturityDate() + "," +
  249.                     FormatUtil.FormatDouble (dblForwardSwapRate, 1, 8, 100.) + "%" + "," +
  250.                     FormatUtil.FormatDouble (dblForwardSwapDV01, 1, 8, 10000.) + "," +
  251.                     FormatUtil.FormatDouble (dblForwardSwapDV01 / dblDFForward, 1, 8, 10000.)
  252.                 );
  253.             }
  254.         }

  255.         EnvManager.TerminateEnv();
  256.     }
  257. }