FloatFloatForwardCurve.java

  1. package org.drip.sample.multicurve;

  2. import java.util.*;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.support.*;
  5. import org.drip.market.otc.*;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.param.creator.*;
  8. import org.drip.param.market.CurveSurfaceQuoteContainer;
  9. import org.drip.param.valuation.*;
  10. import org.drip.product.creator.*;
  11. import org.drip.product.definition.*;
  12. import org.drip.product.rates.*;
  13. import org.drip.service.env.EnvManager;
  14. import org.drip.spline.basis.*;
  15. import org.drip.spline.stretch.MultiSegmentSequenceBuilder;
  16. import org.drip.state.creator.*;
  17. import org.drip.state.discount.*;
  18. import org.drip.state.forward.ForwardCurve;
  19. import org.drip.state.identifier.ForwardLabel;

  20. /*
  21.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  22.  */

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

  68. /**
  69.  * FloatFloatForwardCurve contains the sample demonstrating the full functionality behind creating highly
  70.  *  customized spline based forward curves.
  71.  *
  72.  * The first sample illustrates the creation and usage of the xM-6M Tenor Basis Swap:
  73.  *  - Construct the 6M-xM float-float basis swap.
  74.  *  - Calculate the corresponding starting forward rate off of the discount curve.
  75.  *  - Construct the shape preserving forward curve off of Cubic Polynomial Basis Spline.
  76.  *  - Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  77.  *  - Construct the shape preserving forward curve off of Hyperbolic Tension Based Basis Spline.
  78.  *  - Set the discount curve based component market parameters.
  79.  *  - Set the discount curve + cubic polynomial forward curve based component market parameters.
  80.  *  - Set the discount curve + quartic polynomial forward curve based component market parameters.
  81.  *  - Set the discount curve + hyperbolic tension forward curve based component market parameters.
  82.  *  - Compute the following forward curve metrics for each of cubic polynomial forward, quartic
  83.  *      polynomial forward, and KLK Hyperbolic tension forward curves:
  84.  *      - Reference Basis Par Spread
  85.  *      - Derived Basis Par Spread
  86.  *  - Compare these with a) the forward rate off of the discount curve, b) The LIBOR rate, and c) The
  87.  *      Input Basis Swap Quote.
  88.  *
  89.  * The second sample illustrates how to build and test the forward curves across various tenor basis. It
  90.  *  shows the following steps:
  91.  *  - Construct the Discount Curve using its instruments and quotes.
  92.  *  - Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  93.  *  - Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  94.  *  - Build and run the sampling for the 6M-6M Tenor Basis Swap from its instruments and quotes.
  95.  *  - Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  96.  *
  97.  * @author Lakshmi Krishnamurthy
  98.  */

  99. public class FloatFloatForwardCurve {

  100.     private static final FixFloatComponent OTCFixFloat (
  101.         final JulianDate dtSpot,
  102.         final String strCurrency,
  103.         final String strMaturityTenor,
  104.         final double dblCoupon)
  105.     {
  106.         FixedFloatSwapConvention ffConv = IBORFixedFloatContainer.ConventionFromJurisdiction (
  107.             strCurrency,
  108.             "ALL",
  109.             strMaturityTenor,
  110.             "MAIN"
  111.         );

  112.         return ffConv.createFixFloatComponent (
  113.             dtSpot,
  114.             strMaturityTenor,
  115.             dblCoupon,
  116.             0.,
  117.             1.
  118.         );
  119.     }

  120.     private static final FloatFloatComponent OTCFloatFloat (
  121.         final JulianDate dtSpot,
  122.         final String strCurrency,
  123.         final String strDerivedTenor,
  124.         final String strMaturityTenor,
  125.         final double dblBasis)
  126.     {
  127.         FloatFloatSwapConvention ffConv = IBORFloatFloatContainer.ConventionFromJurisdiction (strCurrency);

  128.         return ffConv.createFloatFloatComponent (
  129.             dtSpot,
  130.             strDerivedTenor,
  131.             strMaturityTenor,
  132.             dblBasis,
  133.             1.
  134.         );
  135.     }

  136.     /*
  137.      * Construct the Array of Deposit Instruments from the given set of parameters
  138.      *
  139.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  140.      */

  141.     private static final CalibratableComponent[] DepositInstrumentsFromMaturityDays (
  142.         final JulianDate dtEffective,
  143.         final int[] aiDay,
  144.         final int iNumFutures,
  145.         final String strCurrency)
  146.         throws Exception
  147.     {
  148.         CalibratableComponent[] aCalibComp = new CalibratableComponent[aiDay.length + iNumFutures];

  149.         for (int i = 0; i < aiDay.length; ++i)
  150.             aCalibComp[i] = SingleStreamComponentBuilder.Deposit (
  151.                 dtEffective,
  152.                 dtEffective.addBusDays (
  153.                     aiDay[i],
  154.                     strCurrency
  155.                 ),
  156.                 ForwardLabel.Create (
  157.                     strCurrency,
  158.                     "3M"
  159.                 )
  160.             );

  161.         CalibratableComponent[] aEDF = SingleStreamComponentBuilder.ForwardRateFuturesPack (
  162.             dtEffective,
  163.             iNumFutures,
  164.             strCurrency
  165.         );

  166.         for (int i = aiDay.length; i < aiDay.length + iNumFutures; ++i)
  167.             aCalibComp[i] = aEDF[i - aiDay.length];

  168.         return aCalibComp;
  169.     }

  170.     /*
  171.      * Construct the Array of Swap Instruments from the given set of parameters
  172.      *
  173.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  174.      */

  175.     private static final CalibratableComponent[] SwapInstrumentsFromMaturityTenor (
  176.         final JulianDate dtSpot,
  177.         final String strCurrency,
  178.         final String[] astrMaturityTenor,
  179.         final double[] adblCoupon)
  180.         throws Exception
  181.     {
  182.         FixFloatComponent[] aIRS = new FixFloatComponent[astrMaturityTenor.length];

  183.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  184.             aIRS[i] = OTCFixFloat (
  185.                 dtSpot,
  186.                 strCurrency,
  187.                 astrMaturityTenor[i],
  188.                 adblCoupon[i]
  189.             );

  190.         return aIRS;
  191.     }

  192.     /*
  193.      * Construct the discount curve using the following steps:
  194.      *  - Construct the array of cash instruments and their quotes.
  195.      *  - Construct the array of swap instruments and their quotes.
  196.      *  - Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  197.      *
  198.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  199.      */

  200.     private static final MergedDiscountForwardCurve MakeDC (
  201.         final JulianDate dtSpot,
  202.         final String strCurrency,
  203.         final double dblBump)
  204.         throws Exception
  205.     {
  206.         /*
  207.          * Construct the array of Deposit instruments and their quotes.
  208.          */

  209.         CalibratableComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  210.             dtSpot,
  211.             new int[] {},
  212.             0,
  213.             strCurrency
  214.         );

  215.         double[] adblDepositQuote = new double[] {}; // Futures

  216.         /*
  217.          * Construct the array of Swap instruments and their quotes.
  218.          */

  219.         double[] adblSwapQuote = new double[] {
  220.             // 0.00092 + dblBump,     //  6M
  221.             0.0009875 + dblBump,   //  9M
  222.             0.00122 + dblBump,     //  1Y
  223.             0.00223 + dblBump,     // 18M
  224.             0.00383 + dblBump,     //  2Y
  225.             0.00827 + dblBump,     //  3Y
  226.             0.01245 + dblBump,     //  4Y
  227.             0.01605 + dblBump,     //  5Y
  228.             0.02597 + dblBump      // 10Y
  229.         };

  230.         String[] astrSwapManifestMeasure = new String[] {
  231.             // "SwapRate",     //  6M
  232.             "SwapRate",     //  9M
  233.             "SwapRate",     //  1Y
  234.             "SwapRate",     // 18M
  235.             "SwapRate",     //  2Y
  236.             "SwapRate",     //  3Y
  237.             "SwapRate",     //  4Y
  238.             "SwapRate",     //  5Y
  239.             "SwapRate"      // 10Y
  240.         };

  241.         CalibratableComponent[] aSwapComp = SwapInstrumentsFromMaturityTenor (
  242.             dtSpot,
  243.             strCurrency,
  244.             // new java.lang.String[] {"6M", "9M", "1Y", "18M", "2Y", "3Y", "4Y", "5Y", "10Y"},
  245.             new java.lang.String[] {
  246.                 "9M", "1Y", "18M", "2Y", "3Y", "4Y", "5Y", "10Y"
  247.             },
  248.             adblSwapQuote
  249.         );

  250.         /*
  251.          * Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  252.          */

  253.         return ScenarioDiscountCurveBuilder.CubicKLKHyperbolicDFRateShapePreserver (
  254.             "KLK_HYPERBOLIC_SHAPE_TEMPLATE",
  255.             new ValuationParams (
  256.                 dtSpot,
  257.                 dtSpot,
  258.                 "USD"
  259.             ),
  260.             aDepositComp,
  261.             adblDepositQuote,
  262.             null,
  263.             aSwapComp,
  264.             adblSwapQuote,
  265.             astrSwapManifestMeasure,
  266.             false
  267.         );
  268.     }

  269.     /*
  270.      * Construct an array of float-float swaps from the corresponding reference (6M) and the derived legs.
  271.      *
  272.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  273.      */

  274.     private static final FloatFloatComponent[] MakexM6MBasisSwap (
  275.         final JulianDate dtSpot,
  276.         final String strCurrency,
  277.         final String[] astrMaturityTenor,
  278.         final int iTenorInMonths)
  279.         throws Exception
  280.     {
  281.         FloatFloatComponent[] aFFC = new FloatFloatComponent[astrMaturityTenor.length];

  282.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  283.             aFFC[i] = OTCFloatFloat (
  284.                 dtSpot,
  285.                 strCurrency,
  286.                 iTenorInMonths + "M",
  287.                 astrMaturityTenor[i],
  288.                 0.
  289.             );

  290.         return aFFC;
  291.     }

  292.     /*
  293.      * This sample illustrates the creation and usage of the xM-6M Tenor Basis Swap. It shows the following:
  294.      *  - Construct the 6M-xM float-float basis swap.
  295.      *  - Calculate the corresponding starting forward rate off of the discount curve.
  296.      *  - Construct the shape preserving forward curve off of Cubic Polynomial Basis Spline.
  297.      *  - Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  298.      *  - Construct the shape preserving forward curve off of Hyperbolic Tension Based Basis Spline.
  299.      *  - Set the discount curve based component market parameters.
  300.      *  - Set the discount curve + cubic polynomial forward curve based component market parameters.
  301.      *  - Set the discount curve + quartic polynomial forward curve based component market parameters.
  302.      *  - Set the discount curve + hyperbolic tension forward curve based component market parameters.
  303.      *  - Compute the following forward curve metrics for each of cubic polynomial forward, quartic
  304.      *      polynomial forward, and KLK Hyperbolic tension forward curves:
  305.      *      - Reference Basis Par Spread
  306.      *      - Derived Basis Par Spread
  307.      *  - Compare these with a) the forward rate off of the discount curve, b) The LIBOR rate, and c) The
  308.      *      Input Basis Swap Quote.
  309.      *
  310.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  311.      */

  312.     private static final Map<String, ForwardCurve> xM6MBasisSample (
  313.         final JulianDate dtSpot,
  314.         final String strCurrency,
  315.         final MergedDiscountForwardCurve dc,
  316.         final int iTenorInMonths,
  317.         final String[] astrxM6MFwdTenor,
  318.         final String strManifestMeasure,
  319.         final double[] adblxM6MBasisSwapQuote)
  320.         throws Exception
  321.     {
  322.         System.out.println ("-----------------------------------------------------------------------------------------------------------------------------");

  323.         System.out.println (" SPL =>              n=3              |              n=4               |              KLK               |         |         |");

  324.         System.out.println ("--------------------------------------------------------------------------------------------------------|  LOG DF |  LIBOR  |");

  325.         System.out.println (" MSR =>  RECALC |  REFEREN |  DERIVED |  RECALC  |  REFEREN |  DERIVED |  RECALC  |  REFEREN |  DERIVED |         |         |");

  326.         System.out.println ("-----------------------------------------------------------------------------------------------------------------------------");

  327.         /*
  328.          * Construct the 6M-xM float-float basis swap.
  329.          */

  330.         FloatFloatComponent[] aFFC = MakexM6MBasisSwap (
  331.             dtSpot,
  332.             strCurrency,
  333.             astrxM6MFwdTenor,
  334.             iTenorInMonths
  335.         );

  336.         String strBasisTenor = iTenorInMonths + "M";

  337.         ValuationParams valParams = new ValuationParams (
  338.             dtSpot,
  339.             dtSpot,
  340.             strCurrency
  341.         );

  342.         /*
  343.          * Calculate the starting forward rate off of the discount curve.
  344.          */

  345.         double dblStartingFwd = dc.forward (
  346.             dtSpot.julian(),
  347.             dtSpot.addTenor (strBasisTenor).julian()
  348.         );

  349.         /*
  350.          * Set the discount curve based component market parameters.
  351.          */

  352.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  353.             dc,
  354.             null,
  355.             null,
  356.             null,
  357.             null,
  358.             null,
  359.             null
  360.         );

  361.         Map<String, ForwardCurve> mapForward = new HashMap<String, ForwardCurve>();

  362.         /*
  363.          * Construct the shape preserving forward curve off of Cubic Polynomial Basis Spline.
  364.          */

  365.         ForwardCurve fcxMCubic = ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  366.             "CUBIC_FWD" + strBasisTenor,
  367.             ForwardLabel.Create (
  368.                 strCurrency,
  369.                 strBasisTenor
  370.             ),
  371.             valParams,
  372.             null,
  373.             mktParams,
  374.             null,
  375.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  376.             new PolynomialFunctionSetParams (4),
  377.             aFFC,
  378.             strManifestMeasure,
  379.             adblxM6MBasisSwapQuote,
  380.             dblStartingFwd
  381.         );

  382.         mapForward.put (
  383.             "   CUBIC_FWD" + strBasisTenor,
  384.             fcxMCubic
  385.         );

  386.         /*
  387.          * Set the discount curve + cubic polynomial forward curve based component market parameters.
  388.          */

  389.         CurveSurfaceQuoteContainer mktParamsCubicFwd = MarketParamsBuilder.Create (
  390.             dc,
  391.             fcxMCubic,
  392.             null,
  393.             null,
  394.             null,
  395.             null,
  396.             null,
  397.             null
  398.         );

  399.         /*
  400.          * Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  401.          */

  402.         ForwardCurve fcxMQuartic = ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  403.             "QUARTIC_FWD" + strBasisTenor,
  404.             ForwardLabel.Create (
  405.                 strCurrency,
  406.                 strBasisTenor
  407.             ),
  408.             valParams,
  409.             null,
  410.             mktParams,
  411.             null,
  412.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  413.             new PolynomialFunctionSetParams (5),
  414.             aFFC,
  415.             strManifestMeasure,
  416.             adblxM6MBasisSwapQuote,
  417.             dblStartingFwd
  418.         );

  419.         mapForward.put (
  420.             " QUARTIC_FWD" + strBasisTenor,
  421.             fcxMQuartic
  422.         );

  423.         /*
  424.          * Set the discount curve + quartic polynomial forward curve based component market parameters.
  425.          */

  426.         CurveSurfaceQuoteContainer mktParamsQuarticFwd = MarketParamsBuilder.Create (
  427.             dc,
  428.             fcxMQuartic,
  429.             null,
  430.             null,
  431.             null,
  432.             null,
  433.             null,
  434.             null
  435.         );

  436.         /*
  437.          * Construct the shape preserving forward curve off of Hyperbolic Tension Based Basis Spline.
  438.          */

  439.         ForwardCurve fcxMKLKHyper = ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  440.             "KLKHYPER_FWD" + strBasisTenor,
  441.             ForwardLabel.Create (
  442.                 strCurrency,
  443.                 strBasisTenor
  444.             ),
  445.             valParams,
  446.             null,
  447.             mktParams,
  448.             null,
  449.             MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  450.             new ExponentialTensionSetParams (1.),
  451.             aFFC,
  452.             strManifestMeasure,
  453.             adblxM6MBasisSwapQuote,
  454.             dblStartingFwd
  455.         );

  456.         mapForward.put (
  457.             "KLKHYPER_FWD" + strBasisTenor,
  458.             fcxMKLKHyper
  459.         );

  460.         /*
  461.          * Set the discount curve + hyperbolic tension forward curve based component market parameters.
  462.          */

  463.         CurveSurfaceQuoteContainer mktParamsKLKHyperFwd = MarketParamsBuilder.Create (
  464.             dc,
  465.             fcxMKLKHyper,
  466.             null,
  467.             null,
  468.             null,
  469.             null,
  470.             null,
  471.             null
  472.         );

  473.         int i = 0;
  474.         int iFreq = 12 / iTenorInMonths;

  475.         /*
  476.          * Compute the following forward curve metrics for each of cubic polynomial forward, quartic
  477.          *  polynomial forward, and KLK Hyperbolic tension forward curves:
  478.          *  - Reference Basis Par Spread
  479.          *  - Derived Basis Par Spread
  480.          *
  481.          * Further compare these with a) the forward rate off of the discount curve, b) the LIBOR rate, and
  482.          *  c) Input Basis Swap Quote.
  483.          */

  484.         for (String strMaturityTenor : astrxM6MFwdTenor) {
  485.             int iFwdEndDate = dtSpot.addTenor (strMaturityTenor).julian();

  486.             int iFwdStartDate = dtSpot.addTenor (strMaturityTenor).subtractTenor (strBasisTenor).julian();

  487.             FloatFloatComponent ffc = aFFC[i++];

  488.             CaseInsensitiveTreeMap<Double> mapCubicValue = ffc.value (
  489.                 valParams,
  490.                 null,
  491.                 mktParamsCubicFwd,
  492.                 null
  493.             );

  494.             CaseInsensitiveTreeMap<Double> mapQuarticValue = ffc.value (
  495.                 valParams,
  496.                 null,
  497.                 mktParamsQuarticFwd,
  498.                 null
  499.             );

  500.             CaseInsensitiveTreeMap<Double> mapKLKHyperValue = ffc.value (
  501.                 valParams,
  502.                 null,
  503.                 mktParamsKLKHyperFwd,
  504.                 null
  505.             );

  506.             System.out.println (" " + strMaturityTenor + " =>  " +
  507.                 FormatUtil.FormatDouble (fcxMCubic.forward (iFwdEndDate), 2, 2, 100.) + "  |  " +
  508.                 FormatUtil.FormatDouble (mapCubicValue.get ("ReferenceParBasisSpread"), 2, 2, 1.) + "  |  " +
  509.                 FormatUtil.FormatDouble (mapCubicValue.get ("DerivedParBasisSpread"), 2, 2, 1.) + "  |  " +
  510.                 FormatUtil.FormatDouble (fcxMQuartic.forward (iFwdEndDate), 2, 2, 100.) + "  |  " +
  511.                 FormatUtil.FormatDouble (mapQuarticValue.get ("ReferenceParBasisSpread"), 2, 2, 1.) + "  |  " +
  512.                 FormatUtil.FormatDouble (mapQuarticValue.get ("DerivedParBasisSpread"), 2, 2, 1.) + "  |  " +
  513.                 FormatUtil.FormatDouble (fcxMKLKHyper.forward (iFwdEndDate), 2, 2, 100.) + "  |  " +
  514.                 FormatUtil.FormatDouble (mapKLKHyperValue.get ("ReferenceParBasisSpread"), 2, 2, 1.) + "  |  " +
  515.                 FormatUtil.FormatDouble (mapKLKHyperValue.get ("DerivedParBasisSpread"), 2, 2, 1.) + "  |  " +
  516.                 FormatUtil.FormatDouble (iFreq * java.lang.Math.log (dc.df (iFwdStartDate) / dc.df (iFwdEndDate)), 1, 2, 100.) + "  |  " +
  517.                 FormatUtil.FormatDouble (dc.libor (iFwdStartDate, iFwdEndDate), 1, 2, 100.) + "  |  "
  518.             );
  519.         }

  520.         return mapForward;
  521.     }

  522.     /*
  523.      * This sample illustrates how to build and test the forward curves across various tenor basis. It shows
  524.      *  the following steps:
  525.      *  - Construct the Discount Curve using its instruments and quotes.
  526.      *  - Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  527.      *  - Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  528.      *  - Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  529.      *
  530.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  531.      */

  532.     private static final void CustomForwardCurveBuilderSample (
  533.         final String strManifestMeasure)
  534.         throws Exception
  535.     {
  536.         String strCurrency = "USD";

  537.         JulianDate dtToday = DateUtil.Today().addTenor ("0D");

  538.         /*
  539.          * Construct the Discount Curve using its instruments and quotes
  540.          */

  541.         MergedDiscountForwardCurve dc = MakeDC (
  542.             dtToday,
  543.             strCurrency,
  544.             0.
  545.         );

  546.         System.out.println ("\n-----------------------------------------------------------------------------------------------------------------------------");

  547.         System.out.println ("---------------------------------------------------    1M-6M Basis Swap    --------------------------------------------------");

  548.         /*
  549.          * Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  550.          */

  551.         xM6MBasisSample (
  552.             dtToday,
  553.             strCurrency,
  554.             dc,
  555.             1,
  556.             new String[] {
  557.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  558.             },
  559.             strManifestMeasure,
  560.             new double[] {
  561.                 0.00551,    //  1Y
  562.                 0.00387,    //  2Y
  563.                 0.00298,    //  3Y
  564.                 0.00247,    //  4Y
  565.                 0.00211,    //  5Y
  566.                 0.00185,    //  6Y
  567.                 0.00165,    //  7Y
  568.                 0.00150,    //  8Y
  569.                 0.00137,    //  9Y
  570.                 0.00127,    // 10Y
  571.                 0.00119,    // 11Y
  572.                 0.00112,    // 12Y
  573.                 0.00096,    // 15Y
  574.                 0.00079,    // 20Y
  575.                 0.00069,    // 25Y
  576.                 0.00062     // 30Y
  577.                 }
  578.             );

  579.         /*
  580.          * Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  581.          */

  582.         System.out.println ("\n-----------------------------------------------------------------------------------------------------------------------------");

  583.         System.out.println ("---------------------------------------------------    3M-6M Basis Swap    --------------------------------------------------");

  584.         xM6MBasisSample (
  585.             dtToday,
  586.             strCurrency,
  587.             dc,
  588.             3,
  589.             new String[] {
  590.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  591.             },
  592.             strManifestMeasure,
  593.             new double[] {
  594.                 0.00186,    //  1Y
  595.                 0.00127,    //  2Y
  596.                 0.00097,    //  3Y
  597.                 0.00080,    //  4Y
  598.                 0.00067,    //  5Y
  599.                 0.00058,    //  6Y
  600.                 0.00051,    //  7Y
  601.                 0.00046,    //  8Y
  602.                 0.00042,    //  9Y
  603.                 0.00038,    // 10Y
  604.                 0.00035,    // 11Y
  605.                 0.00033,    // 12Y
  606.                 0.00028,    // 15Y
  607.                 0.00022,    // 20Y
  608.                 0.00020,    // 25Y
  609.                 0.00018     // 30Y
  610.                 }
  611.             );

  612.         /*
  613.          * Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  614.          */

  615.         System.out.println ("\n-----------------------------------------------------------------------------------------------------------------------------");

  616.         System.out.println ("---------------------------------------------------   12M-6M Basis Swap    --------------------------------------------------");

  617.         xM6MBasisSample (
  618.             dtToday,
  619.             strCurrency,
  620.             dc,
  621.             12,
  622.             new String[] {
  623.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y",
  624.                 "35Y", "40Y" // Extrapolated
  625.             },
  626.             strManifestMeasure,
  627.             new double[] {
  628.                 -0.00212,    //  1Y
  629.                 -0.00152,    //  2Y
  630.                 -0.00117,    //  3Y
  631.                 -0.00097,    //  4Y
  632.                 -0.00082,    //  5Y
  633.                 -0.00072,    //  6Y
  634.                 -0.00063,    //  7Y
  635.                 -0.00057,    //  8Y
  636.                 -0.00051,    //  9Y
  637.                 -0.00047,    // 10Y
  638.                 -0.00044,    // 11Y
  639.                 -0.00041,    // 12Y
  640.                 -0.00035,    // 15Y
  641.                 -0.00028,    // 20Y
  642.                 -0.00025,    // 25Y
  643.                 -0.00022,    // 30Y
  644.                 -0.00022,    // 35Y Extrapolated
  645.                 -0.00022,    // 40Y Extrapolated
  646.                 }
  647.             );
  648.     }

  649.     public static final void main (
  650.         final String[] astrArgs)
  651.         throws Exception
  652.     {
  653.         /*
  654.          * Initialize the Credit Analytics Library
  655.          */

  656.         EnvManager.InitEnv ("");

  657.         System.out.println ("\n-----------------------------------------------------------------------------------------------------------------------------");

  658.         System.out.println ("-----------------------------------------------------------------------------------------------------------------------------");

  659.         System.out.println ("-----------------------------------------------   BASIS ON THE DERIVED LEG    -----------------------------------------------");

  660.         System.out.println ("-----------------------------------------------------------------------------------------------------------------------------");

  661.         CustomForwardCurveBuilderSample ("DerivedParBasisSpread");

  662.         System.out.println ("\n-----------------------------------------------------------------------------------------------------------------------------");

  663.         System.out.println ("-----------------------------------------------------------------------------------------------------------------------------");

  664.         System.out.println ("----------------------------------------------   BASIS ON THE REFERENCE LEG    ----------------------------------------------");

  665.         System.out.println ("-----------------------------------------------------------------------------------------------------------------------------");

  666.         CustomForwardCurveBuilderSample ("ReferenceParBasisSpread");
  667.     }
  668. }