CMEFixFloat.java

  1. package org.drip.sample.securitysuite;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.support.CaseInsensitiveTreeMap;
  5. import org.drip.market.otc.*;
  6. import org.drip.numerical.common.FormatUtil;
  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. import org.drip.state.forward.ForwardCurve;
  14. import org.drip.state.identifier.ForwardLabel;

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

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

  59. /**
  60.  * CMEFixFloat demonstrates the Analytics Calculation/Reconciliation for the CME Cleared Fix-Float IRS.
  61.  *
  62.  * @author Lakshmi Krishnamurthy
  63.  */

  64. public class CMEFixFloat {

  65.     private static final MergedDiscountForwardCurve OvernightCurve (
  66.         final JulianDate dtSpot,
  67.         final String strCurrency)
  68.         throws Exception
  69.     {
  70.         EnvManager.InitEnv ("");

  71.         String[] astrDepositMaturityTenor = new String[] {
  72.             "1D",
  73.         };

  74.         double[] adblDepositQuote = new double[] {
  75.             0.0116,     // 1D
  76.         };

  77.         String[] astrShortEndOISMaturityTenor = new String[] {
  78.              "1W",
  79.              "2W",
  80.              "3W",
  81.              "1M",
  82.              "2M",
  83.              "3M",
  84.              "4M",
  85.              "5M",
  86.              "6M",
  87.              "9M",
  88.             "12M",
  89.             "18M",
  90.              "2Y",
  91.              "3Y",
  92.              "4Y",
  93.              "5Y",
  94.             "10Y",
  95.         };

  96.         double[] adblShortEndOISQuote = new double[] {
  97.             0.0117,    //   1W
  98.             0.0115,    //   2W
  99.             0.0116,    //   3W
  100.             0.0116,    //   1M
  101.             0.0120,    //   2M
  102.             0.0125,    //   3M
  103.             0.0128,    //   4M
  104.             0.0131,    //   5M
  105.             0.0133,    //   6M
  106.             0.0139,    //   9M
  107.             0.0146,    //  12M
  108.             0.0154,    //  18M
  109.             0.0161,    //   2Y
  110.             0.0171,    //   3Y
  111.             0.0179,    //   4Y
  112.             0.0185,    //   5Y
  113.             0.0206,    //  10Y
  114.         };

  115.         return LatentMarketStateBuilder.SmoothOvernightCurve (
  116.             dtSpot,
  117.             strCurrency,
  118.             astrDepositMaturityTenor,
  119.             adblDepositQuote,
  120.             "Rate",
  121.             astrShortEndOISMaturityTenor,
  122.             adblShortEndOISQuote,
  123.             "SwapRate",
  124.             null,
  125.             null,
  126.             null,
  127.             "SwapRate",
  128.             null,
  129.             null,
  130.             "SwapRate"
  131.         );
  132.     }

  133.     public static final void main (
  134.         final String[] astrArgs)
  135.         throws Exception
  136.     {
  137.         /*
  138.          * Initialize the Credit Analytics Library
  139.          */

  140.         EnvManager.InitEnv ("");

  141.         String strCurrency = "USD";
  142.         String strForwardTenor = "3M";

  143.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  144.             2017,
  145.             DateUtil.SEPTEMBER,
  146.             1
  147.         );

  148.         MergedDiscountForwardCurve dcOvernight = OvernightCurve (
  149.             dtSpot,
  150.             strCurrency
  151.         );

  152.         ForwardLabel forwardLabel = ForwardLabel.Create (
  153.             strCurrency,
  154.             strForwardTenor
  155.         );

  156.         String[] astrDepositMaturityTenor = new String[] {
  157.             "1D",
  158.         };

  159.         double[] adblDepositQuote = new double[] {
  160.             0.013161,   // 1D
  161.         };

  162.         String[] astrFixFloatMaturityTenor = new String[] {
  163.             "02Y",
  164.             "03Y",
  165.             "04Y",
  166.             "05Y",
  167.             "06Y",
  168.             "07Y",
  169.             "08Y",
  170.             "09Y",
  171.             "10Y",
  172.             "11Y",
  173.             "12Y",
  174.             "15Y",
  175.             "20Y",
  176.             "25Y",
  177.             "30Y",
  178.             "40Y",
  179.             "50Y",
  180.         };

  181.         double[] adblFixFloatQuote = new double[] {
  182.             0.015540,   //  2Y
  183.             0.016423,   //  3Y
  184.             0.017209,   //  4Y          
  185.             0.017980,   //  5Y
  186.             0.018743,   //  6Y
  187.             0.019455,   //  7Y
  188.             0.020080,   //  8Y
  189.             0.020651,   //  9Y
  190.             0.021195,   // 10Y
  191.             0.021651,   // 11Y
  192.             0.022065,   // 12Y
  193.             0.022952,   // 15Y
  194.             0.023825,   // 20Y
  195.             0.024175,   // 25Y
  196.             0.024347,   // 30Y
  197.             0.024225,   // 40Y
  198.             0.023968,   // 50Y
  199.         };

  200.         ForwardCurve fc = LatentMarketStateBuilder.ShapePreservingForwardCurve (
  201.             dtSpot,
  202.             forwardLabel,
  203.             astrDepositMaturityTenor,
  204.             adblDepositQuote,
  205.             "ForwardRate",
  206.             null,
  207.             null,
  208.             "ParForwardRate",
  209.             astrFixFloatMaturityTenor,
  210.             adblFixFloatQuote,
  211.             "SwapRate",
  212.             null,
  213.             null,
  214.             "DerivedParBasisSpread",
  215.             null,
  216.             null,
  217.             "DerivedParBasisSpread",
  218.             dcOvernight,
  219.             null
  220.         );

  221.         String strMaturityTenor = "7Y";
  222.         double dblFixedCoupon = 0.021893;

  223.         JulianDate dtEffective = DateUtil.CreateFromYMD (
  224.             2017,
  225.             DateUtil.JULY,
  226.             8
  227.         );

  228.         FixedFloatSwapConvention ffsc = IBORFixedFloatContainer.ConventionFromJurisdiction (
  229.             strCurrency,
  230.             "ALL",
  231.             strMaturityTenor,
  232.             "MAIN"
  233.         );

  234.         FixFloatComponent ffc = ffsc.createFixFloatComponent (
  235.             dtEffective,
  236.             strMaturityTenor,
  237.             dblFixedCoupon,
  238.             0.,
  239.             1.
  240.         );

  241.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  242.         csqc.setFundingState (dcOvernight);

  243.         csqc.setForwardState (fc);

  244.         ValuationParams valParams = new ValuationParams (
  245.             dtSpot,
  246.             dtSpot,
  247.             strCurrency
  248.         );

  249.         CaseInsensitiveTreeMap<Double> mapOutput = ffc.value (
  250.             valParams,
  251.             null,
  252.             csqc,
  253.             null
  254.         );

  255.         for (Map.Entry<String, Double> me : mapOutput.entrySet())
  256.             System.out.println ("\t\t" + me.getKey() + " => " + me.getValue());

  257.         System.out.println();

  258.         System.out.println ("\tClean Price       =>" +
  259.             FormatUtil.FormatDouble (mapOutput.get ("CleanPrice"), 1, 4, 1.)
  260.         );

  261.         System.out.println ("\tDirty Price       =>" +
  262.             FormatUtil.FormatDouble (mapOutput.get ("DirtyPrice"), 1, 4, 1.)
  263.         );

  264.         System.out.println ("\tFixed Stream PV   =>  " +
  265.             FormatUtil.FormatDouble (mapOutput.get ("ReferencePV"), 1, 8, 1.)
  266.         );

  267.         System.out.println ("\tFloat Stream PV   =>  " +
  268.             FormatUtil.FormatDouble (mapOutput.get ("DerivedPV"), 1, 8, 1.)
  269.         );

  270.         System.out.println ("\tFixed Stream PV   =>  " +
  271.             FormatUtil.FormatDouble (mapOutput.get ("ReferencePV"), 1, 8, 1.)
  272.         );

  273.         System.out.println ("\tFixed Stream DV01 =>  " +
  274.             FormatUtil.FormatDouble (mapOutput.get ("ReferenceDV01"), 1, 8, 10000.)
  275.         );

  276.         System.out.println ("\tFloat Stream DV01 =>  " +
  277.             FormatUtil.FormatDouble (mapOutput.get ("DerivedDV01"), 1, 8, 10000.)
  278.         );

  279.         System.out.println ("\tFixing 01         =>  " +
  280.             FormatUtil.FormatDouble (mapOutput.get ("Fixing01"), 1, 8, 10000.)
  281.         );

  282.         System.out.println ("\tClean PV          =>  " +
  283.             FormatUtil.FormatDouble (mapOutput.get ("CleanPV"), 1, 8, 1.)
  284.         );

  285.         System.out.println ("\tDirty PV          =>  " +
  286.             FormatUtil.FormatDouble (mapOutput.get ("DirtyPV"), 1, 8, 1.)
  287.         );

  288.         System.out.println ("\tFixed Accrued     =>  " +
  289.             FormatUtil.FormatDouble (mapOutput.get ("FixedAccrued"), 1, 8, 1.)
  290.         );

  291.         System.out.println ("\tFloat Accrued     =>  " +
  292.             FormatUtil.FormatDouble (mapOutput.get ("FloatAccrued"), 1, 8, 1.)
  293.         );

  294.         System.out.println ("\tAccrued           =>  " +
  295.             FormatUtil.FormatDouble (mapOutput.get ("Accrued"), 1, 8, 1.)
  296.         );

  297.         System.out.println ("\tPar Swap Rate     =>  " +
  298.             FormatUtil.FormatDouble (mapOutput.get ("ParSwapRate"), 1, 4, 100.) + "%"
  299.         );
  300.     }
  301. }