OISCurveQuoteSensitivity.java

  1. package org.drip.sample.sensitivity;

  2. import java.util.List;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.support.*;
  5. import org.drip.function.r1tor1.QuadraticRationalShapeControl;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.param.creator.*;
  8. import org.drip.param.period.*;
  9. import org.drip.param.valuation.*;
  10. import org.drip.product.creator.*;
  11. import org.drip.product.rates.*;
  12. import org.drip.service.env.EnvManager;
  13. import org.drip.spline.basis.ExponentialTensionSetParams;
  14. import org.drip.spline.params.*;
  15. import org.drip.spline.stretch.*;
  16. import org.drip.state.creator.ScenarioDiscountCurveBuilder;
  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.  * OISCurveQuoteSensitivity demonstrates the calculation of the OIS discount curve sensitivity to the
  70.  *  calibration instrument quotes. It does the following:
  71.  *  - Construct the Array of Cash/OIS Instruments and their Quotes from the given set of parameters.
  72.  *  - Construct the Cash/OIS Instrument Set Stretch Builder.
  73.  *  - Set up the Linear Curve Calibrator using the following parameters:
  74.  *      - Cubic Exponential Mixture Basis Spline Set
  75.  *      - Ck = 2, Segment Curvature Penalty = 2
  76.  *      - Quadratic Rational Shape Controller
  77.  *      - Natural Boundary Setting
  78.  *  - Construct the Shape Preserving OIS Discount Curve by applying the linear curve calibrator to the array
  79.  *      of Cash and OIS Stretches.
  80.  *  - Cross-Comparison of the Cash/OIS Calibration Instrument "Rate" metric across the different curve
  81.  *      construction methodologies.
  82.  *  - Display of the Cash Instrument Discount Factor Quote Jacobian Sensitivities.
  83.  *  - Display of the OIS Instrument Discount Factor Quote Jacobian Sensitivities.
  84.  *
  85.  * @author Lakshmi Krishnamurthy
  86.  */

  87. public class OISCurveQuoteSensitivity {

  88.     /*
  89.      * Construct the Array of Deposit Instruments from the given set of parameters
  90.      *
  91.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  92.      */

  93.     private static final SingleStreamComponent[] DepositInstrumentsFromMaturityDays (
  94.         final JulianDate dtEffective,
  95.         final String strCurrency,
  96.         final int[] aiDay)
  97.         throws Exception
  98.     {
  99.         SingleStreamComponent[] aDeposit = new SingleStreamComponent[aiDay.length];

  100.         for (int i = 0; i < aiDay.length; ++i)
  101.             aDeposit[i] = SingleStreamComponentBuilder.Deposit (
  102.                 dtEffective,
  103.                 dtEffective.addBusDays (
  104.                     aiDay[i],
  105.                     strCurrency
  106.                 ),
  107.                 OvernightLabel.Create (
  108.                     strCurrency
  109.                 )
  110.             );

  111.         return aDeposit;
  112.     }

  113.     /*
  114.      * Construct the Array of Overnight Index Instruments from the given set of parameters
  115.      *
  116.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  117.      */

  118.     private static final FixFloatComponent[] OvernightIndexFromMaturityTenor (
  119.         final JulianDate dtEffective,
  120.         final String[] astrMaturityTenor,
  121.         final double[] adblCoupon,
  122.         final String strCurrency)
  123.         throws Exception
  124.     {
  125.         FixFloatComponent[] aOIS = new FixFloatComponent[astrMaturityTenor.length];

  126.         UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  127.             2,
  128.             "Act/360",
  129.             false,
  130.             "Act/360",
  131.             false,
  132.             strCurrency,
  133.             false,
  134.             CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  135.         );

  136.         CashSettleParams csp = new CashSettleParams (
  137.             0,
  138.             strCurrency,
  139.             0
  140.         );

  141.         for (int i = 0; i < astrMaturityTenor.length; ++i) {
  142.             java.lang.String strFixedTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
  143.                 astrMaturityTenor[i],
  144.                 "6M"
  145.             ) ? astrMaturityTenor[i] : "6M";

  146.             java.lang.String strFloatingTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
  147.                 astrMaturityTenor[i],
  148.                 "3M"
  149.             ) ? astrMaturityTenor[i] : "3M";

  150.             ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  151.                 "ON",
  152.                 CompositePeriodBuilder.EDGE_DATE_SEQUENCE_OVERNIGHT,
  153.                 null,
  154.                 OvernightLabel.Create (
  155.                     strCurrency
  156.                 ),
  157.                 CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  158.                 0.
  159.             );

  160.             ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  161.                 strFixedTenor,
  162.                 CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  163.                 null,
  164.                 adblCoupon[i],
  165.                 0.,
  166.                 strCurrency
  167.             );

  168.             CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  169.                 4,
  170.                 strFloatingTenor,
  171.                 strCurrency,
  172.                 null,
  173.                 -1.,
  174.                 null,
  175.                 null,
  176.                 null,
  177.                 null
  178.             );

  179.             CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  180.                 2,
  181.                 strFixedTenor,
  182.                 strCurrency,
  183.                 null,
  184.                 1.,
  185.                 null,
  186.                 null,
  187.                 null,
  188.                 null
  189.             );

  190.             List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  191.                 dtEffective,
  192.                 strFixedTenor,
  193.                 astrMaturityTenor[i],
  194.                 null
  195.             );

  196.             List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  197.                 dtEffective,
  198.                 strFloatingTenor,
  199.                 astrMaturityTenor[i],
  200.                 null
  201.             );

  202.             Stream floatingStream = new Stream (
  203.                 CompositePeriodBuilder.FloatingCompositeUnit (
  204.                     lsFloatingStreamEdgeDate,
  205.                     cpsFloating,
  206.                     cfusFloating
  207.                 )
  208.             );

  209.             Stream fixedStream = new Stream (
  210.                 CompositePeriodBuilder.FixedCompositeUnit (
  211.                     lsFixedStreamEdgeDate,
  212.                     cpsFixed,
  213.                     ucasFixed,
  214.                     cfusFixed
  215.                 )
  216.             );

  217.             FixFloatComponent ois = new FixFloatComponent (
  218.                 fixedStream,
  219.                 floatingStream,
  220.                 csp
  221.             );

  222.             ois.setPrimaryCode ("OIS." + astrMaturityTenor[i] + "." + strCurrency);

  223.             aOIS[i] = ois;
  224.         }

  225.         return aOIS;
  226.     }

  227.     /*
  228.      * Construct the Array of Overnight Index Future Instruments from the given set of parameters
  229.      *
  230.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  231.      */

  232.     private static final FixFloatComponent[] OvernightIndexFutureFromMaturityTenor (
  233.         final JulianDate dtSpot,
  234.         final String[] astrStartTenor,
  235.         final String[] astrMaturityTenor,
  236.         final double[] adblCoupon,
  237.         final String strCurrency)
  238.         throws Exception
  239.     {
  240.         FixFloatComponent[] aOIS = new FixFloatComponent[astrStartTenor.length];

  241.         CashSettleParams csp = new CashSettleParams (
  242.             0,
  243.             strCurrency,
  244.             0
  245.         );

  246.         for (int i = 0; i < astrStartTenor.length; ++i) {
  247.             JulianDate dtEffective = dtSpot.addTenor (astrStartTenor[i]);

  248.             java.lang.String strFixedTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
  249.                 astrMaturityTenor[i],
  250.                 "6M"
  251.             ) ? astrMaturityTenor[i] : "6M";

  252.             java.lang.String strFloatingTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
  253.                 astrMaturityTenor[i],
  254.                 "3M"
  255.             ) ? astrMaturityTenor[i] : "3M";

  256.             ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  257.                 strFixedTenor,
  258.                 CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  259.                 null,
  260.                 adblCoupon[i],
  261.                 0.,
  262.                 strCurrency
  263.             );

  264.             UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  265.                 2,
  266.                 "Act/360",
  267.                 false,
  268.                 "Act/360",
  269.                 false,
  270.                 strCurrency,
  271.                 false,
  272.                 CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  273.             );

  274.             ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  275.                 "ON",
  276.                 CompositePeriodBuilder.EDGE_DATE_SEQUENCE_OVERNIGHT,
  277.                 null,
  278.                 OvernightLabel.Create (
  279.                     strCurrency
  280.                 ),
  281.                 CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  282.                 0.
  283.             );

  284.             CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  285.                 4,
  286.                 strFloatingTenor,
  287.                 strCurrency,
  288.                 null,
  289.                 -1.,
  290.                 null,
  291.                 null,
  292.                 null,
  293.                 null
  294.             );

  295.             CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  296.                 2,
  297.                 strFixedTenor,
  298.                 strCurrency,
  299.                 null,
  300.                 1.,
  301.                 null,
  302.                 null,
  303.                 null,
  304.                 null
  305.             );

  306.             List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  307.                 dtEffective,
  308.                 "6M",
  309.                 astrMaturityTenor[i],
  310.                 null
  311.             );

  312.             List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  313.                 dtEffective,
  314.                 "3M",
  315.                 astrMaturityTenor[i],
  316.                 null
  317.             );

  318.             Stream floatingStream = new Stream (
  319.                 CompositePeriodBuilder.FloatingCompositeUnit (
  320.                     lsFloatingStreamEdgeDate,
  321.                     cpsFloating,
  322.                     cfusFloating
  323.                 )
  324.             );

  325.             Stream fixedStream = new Stream (
  326.                 CompositePeriodBuilder.FixedCompositeUnit (
  327.                     lsFixedStreamEdgeDate,
  328.                     cpsFixed,
  329.                     ucasFixed,
  330.                     cfusFixed
  331.                 )
  332.             );

  333.             FixFloatComponent ois = new FixFloatComponent (
  334.                 fixedStream,
  335.                 floatingStream,
  336.                 csp
  337.             );

  338.             ois.setPrimaryCode ("OIS." + astrMaturityTenor[i] + "." + strCurrency);

  339.             aOIS[i] = ois;
  340.         }

  341.         return aOIS;
  342.     }

  343.     /*
  344.      * This sample demonstrates the calculation of the discount curve sensitivity to the calibration
  345.      *  instrument quotes. It does the following:
  346.      *  - Construct the Array of Cash/OIS Instruments and their Quotes from the given set of parameters.
  347.      *  - Construct the Cash/OIS Instrument Set Stretch Builder.
  348.      *  - Set up the Linear Curve Calibrator using the following parameters:
  349.      *      - Cubic Exponential Mixture Basis Spline Set
  350.      *      - Ck = 2, Segment Curvature Penalty = 2
  351.      *      - Quadratic Rational Shape Controller
  352.      *      - Natural Boundary Setting
  353.      *  - Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array
  354.      *      of Cash and OIS Stretches.
  355.      *  - Cross-Comparison of the Cash/OIS Calibration Instrument "Rate" metric across the different curve
  356.      *      construction methodologies.
  357.      *  - Display of the Cash Instrument Discount Factor Quote Jacobian Sensitivities.
  358.      *  - Display of the OIS Instrument Discount Factor Quote Jacobian Sensitivities.
  359.      *
  360.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  361.      */

  362.     private static final void OISCurveQuoteSensitivitySample (
  363.         final JulianDate dtSpot,
  364.         final String strHeaderComment,
  365.         final String strCurrency)
  366.         throws Exception
  367.     {
  368.         System.out.println ("\n\t----------------------------------------------------------------");

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

  370.         /*
  371.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  372.          */

  373.         SingleStreamComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  374.             dtSpot,
  375.             strCurrency,
  376.             new int[] {
  377.                 1, 2, 3
  378.             }
  379.         );

  380.         double[] adblDepositQuote = new double[] {
  381.             0.0004, 0.0004, 0.0004       // Deposit
  382.         };

  383.         /*
  384.          * Setup the Deposit instruments stretch latent state representation - this uses the discount factor
  385.          *  quantification metric and the "rate" manifest measure.
  386.          */

  387.         LatentStateStretchSpec depositStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  388.             "   DEPOSIT   ",
  389.             aDepositComp,
  390.             "ForwardRate",
  391.             adblDepositQuote
  392.         );

  393.         /*
  394.          * Construct the Array of Short End OIS Instruments and their Quotes from the given set of parameters
  395.          */

  396.         double[] adblShortEndOISQuote = new double[] {
  397.             0.00070,    //   1W
  398.             0.00069,    //   2W
  399.             0.00078,    //   3W
  400.             0.00074     //   1M
  401.         };

  402.         FixFloatComponent[] aShortEndOISComp = OvernightIndexFromMaturityTenor (
  403.             dtSpot,
  404.             new java.lang.String[] {
  405.                 "1W", "2W", "3W", "1M"
  406.             },
  407.             adblShortEndOISQuote,
  408.             strCurrency
  409.         );

  410.         /*
  411.          * Construct the Short End OIS Instrument Set Stretch Builder
  412.          */

  413.         LatentStateStretchSpec oisShortEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  414.             "SHORT END OIS",
  415.             aShortEndOISComp,
  416.             "SwapRate",
  417.             adblShortEndOISQuote
  418.         );

  419.         /*
  420.          * Construct the Array of OIS Futures Instruments and their Quotes from the given set of parameters
  421.          */

  422.         double[] adblOISFutureQuote = new double[] {
  423.              0.00046,    //   1M x 1M
  424.              0.00016,    //   2M x 1M
  425.             -0.00007,    //   3M x 1M
  426.             -0.00013,    //   4M x 1M
  427.             -0.00014     //   5M x 1M
  428.         };

  429.         FixFloatComponent[] aOISFutureComp = OvernightIndexFutureFromMaturityTenor (
  430.             dtSpot,
  431.             new java.lang.String[] {
  432.                 "1M", "2M", "3M", "4M", "5M"
  433.             },
  434.             new java.lang.String[] {
  435.                 "1M", "1M", "1M", "1M", "1M"
  436.             },
  437.             adblOISFutureQuote,
  438.             strCurrency
  439.         );

  440.         /*
  441.          * Construct the OIS Future Instrument Set Stretch Builder
  442.          */

  443.         LatentStateStretchSpec oisFutureStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  444.             " OIS FUTURE  ",
  445.             aOISFutureComp,
  446.             "SwapRate",
  447.             adblOISFutureQuote
  448.         );

  449.         /*
  450.          * Construct the Array of Long End OIS Instruments and their Quotes from the given set of parameters
  451.          */

  452.         double[] adblLongEndOISQuote = new double[] {
  453.             0.00002,    //  15M
  454.             0.00008,    //  18M
  455.             0.00021,    //  21M
  456.             0.00036,    //   2Y
  457.             0.00127,    //   3Y
  458.             0.00274,    //   4Y
  459.             0.00456,    //   5Y
  460.             0.00647,    //   6Y
  461.             0.00827,    //   7Y
  462.             0.00996,    //   8Y
  463.             0.01147,    //   9Y
  464.             0.01280,    //  10Y
  465.             0.01404,    //  11Y
  466.             0.01516,    //  12Y
  467.             0.01764,    //  15Y
  468.             0.01939,    //  20Y
  469.             0.02003,    //  25Y
  470.             0.02038     //  30Y
  471.         };

  472.         FixFloatComponent[] aLongEndOISComp = OvernightIndexFromMaturityTenor (
  473.             dtSpot,
  474.             new java.lang.String[] {
  475.                 "15M", "18M", "21M", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  476.             },
  477.             adblLongEndOISQuote,
  478.             strCurrency
  479.         );

  480.         /*
  481.          * Construct the Long End OIS Instrument Set Stretch Builder
  482.          */

  483.         LatentStateStretchSpec oisLongEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  484.             "LONG END OIS ",
  485.             aLongEndOISComp,
  486.             "SwapRate",
  487.             adblLongEndOISQuote
  488.         );

  489.         LatentStateStretchSpec[] aStretchSpec = new LatentStateStretchSpec[] {
  490.             depositStretch,
  491.             oisShortEndStretch,
  492.             oisFutureStretch,
  493.             oisLongEndStretch
  494.         };

  495.         /*
  496.          * Set up the Linear Curve Calibrator using the following Default Segment Control parameters:
  497.          *  - Cubic Exponential Mixture Basis Spline Set
  498.          *  - Ck = 2, Segment Curvature Penalty = 2
  499.          *  - Quadratic Rational Shape Controller
  500.          *  - Prior Quote Sensitivity Control with first derivative tail fade, with FADE ON
  501.          *  - Natural Boundary Setting
  502.          */

  503.         LinearLatentStateCalibrator lcc = new LinearLatentStateCalibrator (
  504.             new SegmentCustomBuilderControl (
  505.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  506.                 new ExponentialTensionSetParams (2.),
  507.                 SegmentInelasticDesignControl.Create (
  508.                     2,
  509.                     2
  510.                 ),
  511.                 new ResponseScalingShapeControl (
  512.                     true,
  513.                     new QuadraticRationalShapeControl (0.)
  514.                 ),
  515.                 new org.drip.spline.params.PreceedingManifestSensitivityControl (
  516.                     true,
  517.                     1,
  518.                     null
  519.                 )
  520.             ),
  521.             BoundarySettings.NaturalStandard(),
  522.             MultiSegmentSequence.CALIBRATE,
  523.             null,
  524.             null
  525.         );

  526.         /*
  527.          * Set up the DEPOSIT Segment Control parameters with the following details:
  528.          *  - Cubic Exponential Mixture Basis Spline Set
  529.          *  - Ck = 2, Segment Curvature Penalty = 2
  530.          *  - Quadratic Rational Shape Controller
  531.          *  - Prior Quote Sensitivity Control with first derivative tail fade, with FADE ON
  532.          *  - Natural Boundary Setting
  533.          */

  534.         lcc.setStretchSegmentBuilderControl (
  535.             depositStretch.name(),
  536.             new SegmentCustomBuilderControl (
  537.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  538.                 new ExponentialTensionSetParams (2.),
  539.                 SegmentInelasticDesignControl.Create (
  540.                     2,
  541.                     2
  542.                 ),
  543.                 new ResponseScalingShapeControl (
  544.                     true,
  545.                     new QuadraticRationalShapeControl (0.)
  546.                 ),
  547.                 new org.drip.spline.params.PreceedingManifestSensitivityControl (
  548.                     true,
  549.                     1,
  550.                     null
  551.                 )
  552.             )
  553.         );

  554.         /*
  555.          * Set up the Short End OIS Segment Control parameters with the following details:
  556.          *  - Cubic Exponential Mixture Basis Spline Set
  557.          *  - Ck = 2, Segment Curvature Penalty = 2
  558.          *  - Quadratic Rational Shape Controller
  559.          *  - Prior Quote Sensitivity Control with first derivative tail fade, with FADE ON
  560.          *  - Natural Boundary Setting
  561.          */

  562.         lcc.setStretchSegmentBuilderControl (
  563.             oisShortEndStretch.name(),
  564.             new SegmentCustomBuilderControl (
  565.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  566.                 new ExponentialTensionSetParams (2.),
  567.                 SegmentInelasticDesignControl.Create (
  568.                     2,
  569.                     2
  570.                 ),
  571.                 new ResponseScalingShapeControl (
  572.                     true,
  573.                     new QuadraticRationalShapeControl (0.)
  574.                 ),
  575.                 new org.drip.spline.params.PreceedingManifestSensitivityControl (
  576.                     true,
  577.                     1,
  578.                     null
  579.                 )
  580.             )
  581.         );

  582.         /*
  583.          * Set up the Long End OIS Segment Control parameters with the following details:
  584.          *  - Cubic Exponential Mixture Basis Spline Set
  585.          *  - Ck = 2, Segment Curvature Penalty = 2
  586.          *  - Quadratic Rational Shape Controller
  587.          *  - Prior Quote Sensitivity Control with first derivative tail fade, with FADE ON
  588.          *  - Natural Boundary Setting
  589.          */

  590.         lcc.setStretchSegmentBuilderControl (
  591.             oisLongEndStretch.name(),
  592.             new SegmentCustomBuilderControl (
  593.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_KLK_HYPERBOLIC_TENSION,
  594.                 new ExponentialTensionSetParams (2.),
  595.                 SegmentInelasticDesignControl.Create (
  596.                     2,
  597.                     2
  598.                 ),
  599.                 new ResponseScalingShapeControl (
  600.                     true,
  601.                     new QuadraticRationalShapeControl (0.)
  602.                 ),
  603.                 new org.drip.spline.params.PreceedingManifestSensitivityControl (
  604.                     true,
  605.                     1,
  606.                     null
  607.                 )
  608.             )
  609.         );

  610.         ValuationParams valParams = new ValuationParams (
  611.             dtSpot,
  612.             dtSpot,
  613.             strCurrency
  614.         );

  615.         /*
  616.          * Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array
  617.          *  of DEPOSIT, OIS SHORT END, and OIS LONG END Stretches.
  618.          */

  619.         MergedDiscountForwardCurve dc = ScenarioDiscountCurveBuilder.ShapePreservingDFBuild (
  620.             strCurrency,
  621.             lcc,
  622.             aStretchSpec,
  623.             valParams,
  624.             null,
  625.             null,
  626.             null,
  627.             1.
  628.         );

  629.         /*
  630.          * Cross-Comparison of the DEPOSIT Calibration Instrument "Rate" metric across the different curve
  631.          *  construction methodologies.
  632.          */

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

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

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

  636.         for (int i = 0; i < aDepositComp.length; ++i)
  637.             System.out.println ("\t[" + aDepositComp[i].maturityDate() + "] = " +
  638.                 FormatUtil.FormatDouble (aDepositComp[i].measureValue (valParams, null,
  639.                     MarketParamsBuilder.Create (dc, null, null, null, null, null, null),
  640.                         null, "Rate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.));

  641.         /*
  642.          * Cross-Comparison of the Short End OIS Calibration Instrument "Rate" metric across the different curve
  643.          *  construction methodologies.
  644.          */

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

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

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

  648.         for (int i = 0; i < aShortEndOISComp.length; ++i)
  649.             System.out.println ("\t[" + aShortEndOISComp[i].maturityDate() + "] = " +
  650.                 FormatUtil.FormatDouble (aShortEndOISComp[i].measureValue (valParams, null,
  651.                     MarketParamsBuilder.Create (dc, null, null, null, null, null, null),
  652.                         null, "CalibSwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblShortEndOISQuote[i], 1, 6, 1.));

  653.         /*
  654.          * Cross-Comparison of the OIS Future Calibration Instrument "Rate" metric across the different curve
  655.          *  construction methodologies.
  656.          */

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

  658.         System.out.println ("\t     OIS FUTURE INSTRUMENTS CALIBRATION RECOVERY");

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

  660.         for (int i = 0; i < aOISFutureComp.length; ++i)
  661.             System.out.println ("\t[" + aOISFutureComp[i].maturityDate() + "] = " +
  662.                 FormatUtil.FormatDouble (aOISFutureComp[i].measureValue (valParams, null,
  663.                     MarketParamsBuilder.Create (dc, null, null, null, null, null, null),
  664.                         null, "SwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblOISFutureQuote[i], 1, 6, 1.));

  665.         /*
  666.          * Cross-Comparison of the Long End OIS Calibration Instrument "Rate" metric across the different curve
  667.          *  construction methodologies.
  668.          */

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

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

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

  672.         for (int i = 0; i < aLongEndOISComp.length; ++i)
  673.             System.out.println ("\t[" + aLongEndOISComp[i].maturityDate() + "] = " +
  674.                 FormatUtil.FormatDouble (aLongEndOISComp[i].measureValue (valParams, null,
  675.                     MarketParamsBuilder.Create (dc, null, null, null, null, null, null),
  676.                         null, "CalibSwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblLongEndOISQuote[i], 1, 6, 1.));

  677.         /*
  678.          * Display of the DEPOSIT Instrument Discount Factor Quote Jacobian Sensitivities.
  679.          */

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

  681.         System.out.println ("\t     DEPOSIT MATURITY DISCOUNT FACTOR JACOBIAN");

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

  683.         for (int i = 0; i < aDepositComp.length; ++i) {
  684.             org.drip.numerical.differentiation.WengertJacobian wj = dc.jackDDFDManifestMeasure (
  685.                 aDepositComp[i].maturityDate(),
  686.                 "PV"
  687.             );

  688.             System.out.println (aDepositComp[i].maturityDate() + " => " + wj.displayString());
  689.         }

  690.         /*
  691.          * Display of the Short End OIS Instrument Discount Factor Quote Jacobian Sensitivities.
  692.          */

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

  694.         System.out.println ("\t     SHORT END OIS MATURITY DISCOUNT FACTOR JACOBIAN");

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

  696.         for (int i = 0; i < aShortEndOISComp.length; ++i) {
  697.             org.drip.numerical.differentiation.WengertJacobian wjDFQuote = dc.jackDDFDManifestMeasure (
  698.                 aShortEndOISComp[i].maturityDate(),
  699.                 "PV"
  700.             );

  701.             System.out.println (aShortEndOISComp[i].maturityDate() + " => " + wjDFQuote.displayString());
  702.         }

  703.         /*
  704.          * Display of the OIS Future Instrument Discount Factor Quote Jacobian Sensitivities.
  705.          */

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

  707.         System.out.println ("\t     OIS FUTURE MATURITY DISCOUNT FACTOR JACOBIAN");

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

  709.         for (int i = 0; i < aOISFutureComp.length; ++i) {
  710.             org.drip.numerical.differentiation.WengertJacobian wjDFQuote = dc.jackDDFDManifestMeasure (
  711.                 aOISFutureComp[i].maturityDate(),
  712.                 "PV"
  713.             );

  714.             System.out.println (aOISFutureComp[i].maturityDate() + " => " + wjDFQuote.displayString());
  715.         }

  716.         /*
  717.          * Display of the Long End OIS Instrument Discount Factor Quote Jacobian Sensitivities.
  718.          */

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

  720.         System.out.println ("\t     LONG END OIS MATURITY DISCOUNT FACTOR JACOBIAN");

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

  722.         for (int i = 0; i < aLongEndOISComp.length; ++i) {
  723.             org.drip.numerical.differentiation.WengertJacobian wjDFQuote = dc.jackDDFDManifestMeasure (
  724.                 aLongEndOISComp[i].maturityDate(),
  725.                 "PV"
  726.             );

  727.             System.out.println (aLongEndOISComp[i].maturityDate() + " => " + wjDFQuote.displayString());
  728.         }
  729.     }

  730.     public static final void main (
  731.         final String[] astrArgs)
  732.         throws Exception
  733.     {
  734.         /*
  735.          * Initialize the Credit Analytics Library
  736.          */

  737.         EnvManager.InitEnv ("");

  738.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  739.             2018,
  740.             DateUtil.MARCH,
  741.             8
  742.         );

  743.         OISCurveQuoteSensitivitySample (
  744.             dtSpot,
  745.             "---- DISCOUNT CURVE WITH OVERNIGHT INDEX ---",
  746.             "EUR"
  747.         );
  748.     }
  749. }