CustomOvernightCurveReconciler.java

  1. package org.drip.sample.overnight;

  2. import org.drip.analytics.date.*;
  3. import org.drip.analytics.definition.Turn;
  4. import org.drip.function.r1tor1.QuadraticRationalShapeControl;
  5. import org.drip.market.otc.*;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.param.creator.*;
  8. import org.drip.param.valuation.*;
  9. import org.drip.product.creator.*;
  10. import org.drip.product.definition.CalibratableComponent;
  11. import org.drip.product.rates.*;
  12. import org.drip.service.env.EnvManager;
  13. import org.drip.spline.basis.PolynomialFunctionSetParams;
  14. import org.drip.spline.params.*;
  15. import org.drip.spline.stretch.*;
  16. import org.drip.state.curve.DiscountFactorDiscountCurve;
  17. import org.drip.state.discount.*;
  18. import org.drip.state.estimator.LatentStateStretchBuilder;
  19. import org.drip.state.identifier.*;
  20. import org.drip.state.inference.*;

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

  24. /*!
  25.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  26.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  27.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  28.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  29.  * Copyright (C) 2014 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.  * CustomOvernightCurveReconciler demonstrates the multi-stretch transition custom Overnight curve
  70.  *  construction, turns application, discount factor extraction, and calibration quote recovery.
  71.  *
  72.  * @author Lakshmi Krishnamurthy
  73.  */

  74. public class CustomOvernightCurveReconciler {

  75.     private static final FixFloatComponent OTCOISFixFloat (
  76.         final JulianDate dtSpot,
  77.         final String strCurrency,
  78.         final String strMaturityTenor,
  79.         final double dblCoupon)
  80.     {
  81.         FixedFloatSwapConvention ffConv = OvernightFixedFloatContainer.FundConventionFromJurisdiction (
  82.             strCurrency
  83.         );

  84.         return ffConv.createFixFloatComponent (
  85.             dtSpot,
  86.             strMaturityTenor,
  87.             dblCoupon,
  88.             0.,
  89.             1.
  90.         );
  91.     }

  92.     /*
  93.      * Construct the Array of Deposit Instruments from the given set of parameters
  94.      *
  95.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  96.      */

  97.     private static final SingleStreamComponent[] DepositInstrumentsFromMaturityDays (
  98.         final JulianDate dtEffective,
  99.         final String strCurrency,
  100.         final int[] aiDay)
  101.         throws Exception
  102.     {
  103.         SingleStreamComponent[] aDeposit = new SingleStreamComponent[aiDay.length];

  104.         for (int i = 0; i < aiDay.length; ++i)
  105.             aDeposit[i] = SingleStreamComponentBuilder.Deposit (
  106.                 dtEffective,
  107.                 dtEffective.addBusDays (
  108.                     aiDay[i],
  109.                     strCurrency
  110.                 ),
  111.                 OvernightLabel.Create (
  112.                     strCurrency
  113.                 )
  114.             );

  115.         return aDeposit;
  116.     }

  117.     /*
  118.      * Construct the Array of Overnight Index Instruments from the given set of parameters
  119.      *
  120.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  121.      */

  122.     private static final FixFloatComponent[] OISFromMaturityTenor (
  123.         final JulianDate dtSpot,
  124.         final String strCurrency,
  125.         final String[] astrMaturityTenor,
  126.         final double[] adblCoupon)
  127.         throws Exception
  128.     {
  129.         FixFloatComponent[] aOIS = new FixFloatComponent[astrMaturityTenor.length];

  130.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  131.             aOIS[i] = OTCOISFixFloat (
  132.                 dtSpot,
  133.                 strCurrency,
  134.                 astrMaturityTenor[i],
  135.                 adblCoupon[i]
  136.             );

  137.         return aOIS;
  138.     }

  139.     /*
  140.      * Construct the Array of Overnight Index Future Instruments from the given set of parameters
  141.      *
  142.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  143.      */

  144.     private static final FixFloatComponent[] OISFuturesFromMaturityTenor (
  145.         final JulianDate dtSpot,
  146.         final String strCurrency,
  147.         final String[] astrStartTenor,
  148.         final String[] astrMaturityTenor,
  149.         final double[] adblCoupon)
  150.         throws Exception
  151.     {
  152.         FixFloatComponent[] aOISFutures = new FixFloatComponent[astrMaturityTenor.length];

  153.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  154.             aOISFutures[i] = OTCOISFixFloat (
  155.                 dtSpot.addTenor (astrStartTenor[i]),
  156.                 strCurrency,
  157.                 astrMaturityTenor[i],
  158.                 adblCoupon[i]
  159.             );

  160.         return aOISFutures;
  161.     }

  162.     /*
  163.      * This sample demonstrates the multi-stretch transition custom discount curve construction, turns
  164.      *  application, discount factor extraction, and calibration quote recovery. It shows the following
  165.      *  steps:
  166.      *  - Setup the linear curve calibrator.
  167.      *  - Setup the Deposit instruments and their quotes for calibration.
  168.      *  - Setup the Deposit instruments stretch latent state representation - this uses the discount factor
  169.      *      quantification metric and the "rate" manifest measure.
  170.      *  - Setup the OIS instruments and their quotes for calibration.
  171.      *  - Setup the OIS instruments stretch latent state representation - this uses the discount factor
  172.      *      quantification metric and the "rate" manifest measure.
  173.      *  - Calibrate over the instrument set to generate a new overlapping latent state span instance.
  174.      *  - Retrieve the "Deposit" stretch from the span.
  175.      *  - Retrieve the "OIS" stretch from the span.
  176.      *  - Create a discount curve instance by converting the overlapping stretch to an exclusive
  177.      *      non-overlapping stretch.
  178.      *  - Compare the discount factors and their monotonicity emitted from the discount curve, the
  179.      *      non-overlapping span, and the "OIS" stretch across the range of tenor predictor ordinates.
  180.      *  - Cross-Recovery of the Deposit Calibration Instrument "Rate" metric across the different curve
  181.      *      construction methodologies.
  182.      *  - Cross-Recovery of the OIS Calibration Instrument "Rate" metric across the different curve
  183.      *      construction methodologies.
  184.      *  - Create a turn list instance and add new turn instances.
  185.      *  - Update the discount curve with the turn list.
  186.      *  - Compare the discount factor implied the discount curve with and without applying the turns
  187.      *      adjustment.
  188.      *
  189.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  190.      */

  191.     private static final void SplineLinearOISDiscountCurve (
  192.         final JulianDate dtSpot,
  193.         final SegmentCustomBuilderControl prbp,
  194.         final String strHeaderComment,
  195.         final String strCurrency)
  196.         throws Exception
  197.     {
  198.         System.out.println ("\n\t----------------------------------------------------------------");

  199.         System.out.println ("\t" + strHeaderComment);

  200.         /*
  201.          * Setup the linear curve calibrator
  202.          */

  203.         LinearLatentStateCalibrator lcc = new LinearLatentStateCalibrator (
  204.             prbp,
  205.             BoundarySettings.NaturalStandard(),
  206.             MultiSegmentSequence.CALIBRATE,
  207.             null,
  208.             null
  209.         );

  210.         /*
  211.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  212.          */

  213.         SingleStreamComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  214.             dtSpot,
  215.             strCurrency,
  216.             new int[] {
  217.                 1, 2, 3
  218.             }
  219.         );

  220.         double[] adblDepositQuote = new double[] {
  221.             0.0004, 0.0004, 0.0004       // Deposit
  222.         };

  223.         /*
  224.          * Construct the Deposit Instrument Set Stretch Builder
  225.          */

  226.         LatentStateStretchSpec depositStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  227.             "   DEPOSIT   ",
  228.             aDepositComp,
  229.             "ForwardRate",
  230.             adblDepositQuote
  231.         );

  232.         /*
  233.          * Construct the Array of Short End OIS Instruments and their Quotes from the given set of parameters
  234.          */

  235.         double[] adblShortEndOISQuote = new double[] {
  236.             0.00070,    //   1W
  237.             0.00069,    //   2W
  238.             0.00078,    //   3W
  239.             0.00074     //   1M
  240.         };

  241.         CalibratableComponent[] aShortEndOISComp = OISFromMaturityTenor (
  242.             dtSpot,
  243.             strCurrency,
  244.             new java.lang.String[] {
  245.                 "1W", "2W", "3W", "1M"
  246.             },
  247.             adblShortEndOISQuote
  248.         );

  249.         /*
  250.          * Construct the Short End OIS Instrument Set Stretch Builder
  251.          */

  252.         LatentStateStretchSpec oisShortEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  253.             "SHORT END OIS",
  254.             aShortEndOISComp,
  255.             "SwapRate",
  256.             adblShortEndOISQuote
  257.         );

  258.         /*
  259.          * Construct the Array of OIS Futures Instruments and their Quotes from the given set of parameters
  260.          */

  261.         double[] adblOISFutureQuote = new double[] {
  262.              0.00046,    //   1M x 1M
  263.              0.00016,    //   2M x 1M
  264.             -0.00007,    //   3M x 1M
  265.             -0.00013,    //   4M x 1M
  266.             -0.00014     //   5M x 1M
  267.         };

  268.         CalibratableComponent[] aOISFutureComp = OISFuturesFromMaturityTenor (
  269.             dtSpot,
  270.             strCurrency,
  271.             new java.lang.String[] {
  272.                 "1M", "2M", "3M", "4M", "5M"
  273.             },
  274.             new java.lang.String[] {
  275.                 "1M", "1M", "1M", "1M", "1M"
  276.             },
  277.             adblOISFutureQuote
  278.         );

  279.         /*
  280.          * Construct the OIS Future Instrument Set Stretch Builder
  281.          */

  282.         LatentStateStretchSpec oisFutureStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  283.             " OIS FUTURE  ",
  284.             aOISFutureComp,
  285.             "SwapRate",
  286.             adblOISFutureQuote
  287.         );

  288.         /*
  289.          * Construct the Array of Long End OIS Instruments and their Quotes from the given set of parameters
  290.          */

  291.         double[] adblLongEndOISQuote = new double[] {
  292.             0.00002,    //  15M
  293.             0.00008,    //  18M
  294.             0.00021,    //  21M
  295.             0.00036,    //   2Y
  296.             0.00127,    //   3Y
  297.             0.00274,    //   4Y
  298.             0.00456,    //   5Y
  299.             0.00647,    //   6Y
  300.             0.00827,    //   7Y
  301.             0.00996,    //   8Y
  302.             0.01147,    //   9Y
  303.             0.01280,    //  10Y
  304.             0.01404,    //  11Y
  305.             0.01516,    //  12Y
  306.             0.01764,    //  15Y
  307.             0.01939,    //  20Y
  308.             0.02003,    //  25Y
  309.             0.02038     //  30Y
  310.         };

  311.         CalibratableComponent[] aLongEndOISComp = OISFromMaturityTenor (
  312.             dtSpot,
  313.             strCurrency,
  314.             new java.lang.String[] {
  315.                 "15M", "18M", "21M", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  316.             },
  317.             adblLongEndOISQuote
  318.         );

  319.         /*
  320.          * Construct the Long End OIS Instrument Set Stretch Builder
  321.          */

  322.         LatentStateStretchSpec oisLongEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  323.             "LONG END OIS ",
  324.             aLongEndOISComp,
  325.             "SwapRate",
  326.             adblLongEndOISQuote
  327.         );

  328.         LatentStateStretchSpec[] aStretchSpec = new LatentStateStretchSpec[] {
  329.             depositStretch,
  330.             oisShortEndStretch,
  331.             oisFutureStretch,
  332.             oisLongEndStretch
  333.         };

  334.         /*
  335.          * Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array
  336.          *  of Deposit and Swap Stretches.
  337.          */

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

  343.         /*
  344.          * Calibrate over the instrument set to generate a new overlapping latent state span instance
  345.          */

  346.         org.drip.spline.grid.OverlappingStretchSpan ors = lcc.calibrateSpan (
  347.             aStretchSpec,
  348.             1.,
  349.             valParams,
  350.             null,
  351.             null,
  352.             null
  353.         );

  354.         /*
  355.          * Retrieve the "Deposit" stretch from the span
  356.          */

  357.         MultiSegmentSequence mssDeposit = ors.getStretch ("   DEPOSIT   ");

  358.         /*
  359.          * Retrieve the OIS Short End stretch from the span
  360.          */

  361.         MultiSegmentSequence mssOISShortEnd = ors.getStretch ("SHORT END OIS");

  362.         /*
  363.          * Retrieve the OIS Future stretch from the span
  364.          */

  365.         MultiSegmentSequence mssOISFuture = ors.getStretch (" OIS FUTURE  ");

  366.         /*
  367.          * Retrieve the OIS Long End stretch from the span
  368.          */

  369.         MultiSegmentSequence mssOISLongEnd = ors.getStretch ("LONG END OIS ");

  370.         /*
  371.          * Create a discount curve instance by converting the overlapping stretch to an exclusive
  372.          *  non-overlapping stretch.
  373.          */

  374.         MergedDiscountForwardCurve dfdc = new DiscountFactorDiscountCurve (
  375.             strCurrency,
  376.             ors
  377.         );

  378.         /*
  379.          * Compare the discount factors and their monotonicity emitted from the discount curve, the
  380.          * non-overlapping span, and the "Deposit" stretch across the range of tenor predictor ordinates.
  381.          */

  382.         System.out.println ("\t----------------------------------------------------------------");

  383.         System.out.println ("\t     DEPOSITS DF           DFDC       STRETCH        LOCAL");

  384.         System.out.println ("\t----------------------------------------------------------------");

  385.         int iDepositWidth = (int) (0.25 * (mssDeposit.getRightPredictorOrdinateEdge() - mssDeposit.getLeftPredictorOrdinateEdge()));

  386.         if (0 == iDepositWidth) iDepositWidth = 1;

  387.         for (int iX = (int) mssDeposit.getLeftPredictorOrdinateEdge(); iX <= (int) mssDeposit.getRightPredictorOrdinateEdge();
  388.             iX += iDepositWidth) {
  389.             try {
  390.                 System.out.println ("\tDEPOSIT [" + new JulianDate (iX) + "] = " +
  391.                     FormatUtil.FormatDouble (dfdc.df (iX), 1, 8, 1.) + " || " +
  392.                         ors.getContainingStretch (iX).name() + " || " +
  393.                             FormatUtil.FormatDouble (mssDeposit.responseValue (iX), 1, 8, 1.) + " | " +
  394.                                 mssDeposit.monotoneType (iX));
  395.             } catch (java.lang.Exception e) {
  396.                 e.printStackTrace();
  397.             }
  398.         }

  399.         /*
  400.          * Compare the discount factors and their monotonicity emitted from the discount curve, the
  401.          * non-overlapping span, and the OIS SHORT END stretch across the range of tenor predictor ordinates.
  402.          */

  403.         System.out.println ("\n\t----------------------------------------------------------------");

  404.         System.out.println ("\tSHORT END OIS DF        DFDC       STRETCH        LOCAL");

  405.         System.out.println ("\t----------------------------------------------------------------");

  406.         double dblShortOISWidth = 0.2 * (mssOISShortEnd.getRightPredictorOrdinateEdge() - mssOISShortEnd.getLeftPredictorOrdinateEdge());

  407.         for (int iX = (int) mssOISShortEnd.getLeftPredictorOrdinateEdge(); iX <= (int) mssOISShortEnd.getRightPredictorOrdinateEdge();
  408.             iX += dblShortOISWidth) {
  409.                 System.out.println ("\tOIS [" + new JulianDate (iX) + "] = " +
  410.                     FormatUtil.FormatDouble (dfdc.df (iX), 1, 8, 1.) + " || " +
  411.                         ors.getContainingStretch (iX).name() + " || " +
  412.                             FormatUtil.FormatDouble (mssOISShortEnd.responseValue (iX), 1, 8, 1.) + " | " +
  413.                                 mssOISShortEnd.monotoneType (iX));
  414.         }

  415.         /*
  416.          * Compare the discount factors and their monotonicity emitted from the discount curve, the
  417.          * non-overlapping span, and the OIS FUTURE stretch across the range of tenor predictor ordinates.
  418.          */

  419.         System.out.println ("\n\t----------------------------------------------------------------");

  420.         System.out.println ("\t OIS FUTURE DF          DFDC       STRETCH        LOCAL");

  421.         System.out.println ("\t----------------------------------------------------------------");

  422.         int iOISFutureWidth = (int) (0.2 * (mssOISFuture.getRightPredictorOrdinateEdge() - mssOISFuture.getLeftPredictorOrdinateEdge()));

  423.         for (int iX = (int) mssOISFuture.getLeftPredictorOrdinateEdge(); iX <= (int) mssOISFuture.getRightPredictorOrdinateEdge();
  424.             iX += iOISFutureWidth) {
  425.                 System.out.println ("\tOIS [" + new JulianDate (iX) + "] = " +
  426.                     FormatUtil.FormatDouble (dfdc.df (iX), 1, 8, 1.) + " || " +
  427.                         ors.getContainingStretch (iX).name() + " || " +
  428.                             FormatUtil.FormatDouble (mssOISFuture.responseValue (iX), 1, 8, 1.) + " | " +
  429.                                 mssOISFuture.monotoneType (iX));
  430.         }

  431.         /*
  432.          * Compare the discount factors and their monotonicity emitted from the discount curve, the
  433.          * non-overlapping span, and the OIS LONG END stretch across the range of tenor predictor ordinates.
  434.          */

  435.         System.out.println ("\n\t----------------------------------------------------------------");

  436.         System.out.println ("\tLONG END OIS DF         DFDC      STRETCH         LOCAL");

  437.         System.out.println ("\t----------------------------------------------------------------");

  438.         for (int iX = (int) mssOISFuture.getLeftPredictorOrdinateEdge(); iX <= (int) mssOISFuture.getRightPredictorOrdinateEdge();
  439.             iX += iOISFutureWidth) {
  440.                 System.out.println ("\tOIS [" + new JulianDate (iX) + "] = " +
  441.                     FormatUtil.FormatDouble (dfdc.df (iX), 1, 8, 1.) + " || " +
  442.                         ors.getContainingStretch (iX).name() + " || " +
  443.                             FormatUtil.FormatDouble (mssOISFuture.responseValue (iX), 1, 8, 1.) + " | " +
  444.                                 mssOISFuture.monotoneType (iX));
  445.         }

  446.         int iLongOISWidth = ((int) mssOISLongEnd.getRightPredictorOrdinateEdge() - (int) mssOISLongEnd.getLeftPredictorOrdinateEdge()) / 10;

  447.         for (int iX = (int) mssOISLongEnd.getLeftPredictorOrdinateEdge() + iLongOISWidth; iX <= (int) mssOISLongEnd.getRightPredictorOrdinateEdge();
  448.             iX += iLongOISWidth) {
  449.                 System.out.println ("\tOIS [" + new JulianDate (iX) + "] = " +
  450.                     FormatUtil.FormatDouble (dfdc.df (iX), 1, 8, 1.) + " || " +
  451.                         ors.getContainingStretch (iX).name() + " || " +
  452.                             FormatUtil.FormatDouble (mssOISLongEnd.responseValue (iX), 1, 8, 1.) + " | " +
  453.                                 mssOISLongEnd.monotoneType (iX));
  454.         }

  455.         System.out.println ("\tOIS [" + dtSpot.addTenor ("60Y") + "] = " +
  456.             FormatUtil.FormatDouble (dfdc.df (dtSpot.addTenor ("60Y")), 1, 8, 1.));

  457.         /*
  458.          * Cross-Recovery of the Deposit Calibration Instrument "Rate" metric across the different curve
  459.          *  construction methodologies.
  460.          */

  461.         System.out.println ("\n\t----------------------------------------------------------------");

  462.         System.out.println ("\t     DEPOSIT INSTRUMENTS CALIBRATION RECOVERY");

  463.         System.out.println ("\t----------------------------------------------------------------");

  464.         for (int i = 0; i < aDepositComp.length; ++i)
  465.             System.out.println ("\t[" + aDepositComp[i].maturityDate() + "] = " +
  466.                 FormatUtil.FormatDouble (aDepositComp[i].measureValue (valParams, null,
  467.                     MarketParamsBuilder.Create (dfdc, null, null, null, null, null, null),
  468.                         null, "Rate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.));

  469.         /*
  470.          * Cross-Recovery of the OIS Short End Calibration Instrument "Rate" metric across the different curve
  471.          *  construction methodologies.
  472.          */

  473.         System.out.println ("\n\t----------------------------------------------------------------");

  474.         System.out.println ("\t      OIS SHORT END INSTRUMENTS CALIBRATION RECOVERY");

  475.         System.out.println ("\t----------------------------------------------------------------");

  476.         for (int i = 0; i < aShortEndOISComp.length; ++i)
  477.             System.out.println ("\t[" + aShortEndOISComp[i].maturityDate() + "] = " +
  478.                 FormatUtil.FormatDouble (aShortEndOISComp[i].measureValue (valParams, null,
  479.                     MarketParamsBuilder.Create (dfdc, null, null, null, null, null, null),
  480.                         null, "SwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblShortEndOISQuote[i], 1, 6, 1.));

  481.         /*
  482.          * Cross-Recovery of the OIS Future Calibration Instrument "Rate" metric across the different curve
  483.          *  construction methodologies.
  484.          */

  485.         System.out.println ("\n\t----------------------------------------------------------------");

  486.         System.out.println ("\t      OIS FUTURES INSTRUMENTS CALIBRATION RECOVERY");

  487.         System.out.println ("\t----------------------------------------------------------------");

  488.         for (int i = 0; i < aOISFutureComp.length; ++i)
  489.             System.out.println ("\t[" + aOISFutureComp[i].maturityDate() + "] = " +
  490.                 FormatUtil.FormatDouble (aOISFutureComp[i].measureValue (valParams, null,
  491.                     MarketParamsBuilder.Create (dfdc, null, null, null, null, null, null),
  492.                         null, "SwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblOISFutureQuote[i], 1, 6, 1.));

  493.         /*
  494.          * Cross-Recovery of the OIS Long End Calibration Instrument "Rate" metric across the different curve
  495.          *  construction methodologies.
  496.          */

  497.         System.out.println ("\n\t----------------------------------------------------------------");

  498.         System.out.println ("\t      OIS LONG END INSTRUMENTS CALIBRATION RECOVERY");

  499.         System.out.println ("\t----------------------------------------------------------------");

  500.         for (int i = 0; i < aLongEndOISComp.length; ++i)
  501.             System.out.println ("\t[" + aLongEndOISComp[i].maturityDate() + "] = " +
  502.                 FormatUtil.FormatDouble (aLongEndOISComp[i].measureValue (valParams, null,
  503.                     MarketParamsBuilder.Create (dfdc, null, null, null, null, null, null),
  504.                         null, "CalibSwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblLongEndOISQuote[i], 1, 6, 1.));

  505.         /*
  506.          * Create a turn list instance and add new turn instances
  507.          */

  508.         TurnListDiscountFactor tldc = new TurnListDiscountFactor();

  509.         tldc.addTurn (
  510.             new Turn (
  511.                 dtSpot.addTenor ("5Y").julian(),
  512.                 dtSpot.addTenor ("40Y").julian(),
  513.                 0.001
  514.             )
  515.         );

  516.         /*
  517.          * Update the discount curve with the turn list.
  518.          */

  519.         dfdc.setTurns (tldc);

  520.         /*
  521.          * Compare the discount factor implied the discount curve with and without applying the turns
  522.          *  adjustment.
  523.          */

  524.         System.out.println ("\n\t-------------------------------");

  525.         System.out.println ("\t  TURNS ADJ DF         DFDC");

  526.         System.out.println ("\t-------------------------------");

  527.         for (int iX = (int) mssOISShortEnd.getLeftPredictorOrdinateEdge(); iX <= (int) mssOISLongEnd.getRightPredictorOrdinateEdge();
  528.             iX += 0.05 * (mssOISLongEnd.getRightPredictorOrdinateEdge() - mssOISShortEnd.getLeftPredictorOrdinateEdge())) {
  529.                 System.out.println ("\tOIS [" + new JulianDate (iX) + "] = " +
  530.                     FormatUtil.FormatDouble (dfdc.df (iX), 1, 8, 1.));
  531.         }
  532.     }

  533.     public static final void main (
  534.         final String[] astrArgs)
  535.         throws Exception
  536.     {
  537.         /*
  538.          * Initialize the Credit Analytics Library
  539.          */

  540.         EnvManager.InitEnv ("");

  541.         /*
  542.          * Construct the segment Custom builder using the following parameters:
  543.          *  - Cubic Exponential Mixture Basis Spline Set
  544.          *  - Ck = 2, Segment Curvature Penalty = 2
  545.          *  - Quadratic Rational Shape Controller
  546.          */

  547.         SegmentCustomBuilderControl prbpPolynomial = new SegmentCustomBuilderControl (
  548.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  549.             new PolynomialFunctionSetParams (4),
  550.             SegmentInelasticDesignControl.Create (
  551.                 2,
  552.                 2
  553.             ),
  554.             new ResponseScalingShapeControl (
  555.                 true,
  556.                 new QuadraticRationalShapeControl (0.)
  557.             ),
  558.             null
  559.         );

  560.         String strCurrency = "EUR";

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

  562.         /*
  563.          * Runs the full spline linear discount curve builder sample using the overnight index discount curve.
  564.          */

  565.         SplineLinearOISDiscountCurve (
  566.             dtToday,
  567.             prbpPolynomial,
  568.             "---- DISCOUNT CURVE WITH OVERNIGHT INDEX ---",
  569.             strCurrency
  570.         );
  571.     }
  572. }