ShapePreservingOvernightZeroSmooth.java

  1. package org.drip.sample.overnight;

  2. import java.util.List;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.definition.LatentStateStatic;
  5. import org.drip.analytics.support.*;
  6. import org.drip.function.r1tor1.QuadraticRationalShapeControl;
  7. import org.drip.market.otc.*;
  8. import org.drip.numerical.common.FormatUtil;
  9. import org.drip.param.creator.*;
  10. import org.drip.param.period.*;
  11. import org.drip.param.valuation.*;
  12. import org.drip.product.creator.*;
  13. import org.drip.product.definition.CalibratableComponent;
  14. import org.drip.product.rates.*;
  15. import org.drip.service.env.EnvManager;
  16. import org.drip.spline.basis.*;
  17. import org.drip.spline.params.*;
  18. import org.drip.spline.pchip.LocalMonotoneCkGenerator;
  19. import org.drip.spline.stretch.*;
  20. import org.drip.state.creator.ScenarioDiscountCurveBuilder;
  21. import org.drip.state.discount.*;
  22. import org.drip.state.estimator.*;
  23. import org.drip.state.identifier.*;
  24. import org.drip.state.inference.*;

  25. /*
  26.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  27.  */

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

  72. /**
  73.  * ShapePreservingOvernightZeroSmooth demonstrates the usage of different shape preserving and smoothing
  74.  *  techniques involved in the Overnight curve creation. It shows the following:
  75.  *  - Construct the Array of Cash/OIS Instruments and their Quotes from the given set of parameters.
  76.  *  - Construct the Cash/OIS Instrument Set Stretch Builder.
  77.  *  - Set up the Linear Curve Calibrator using the following parameters:
  78.  *      - Cubic Exponential Mixture Basis Spline Set
  79.  *      - Ck = 2, Segment Curvature Penalty = 2
  80.  *      - Quadratic Rational Shape Controller
  81.  *      - Natural Boundary Setting
  82.  *  - Set up the Global Curve Control parameters as follows:
  83.  *      - Zero Rate Quantification Metric
  84.  *      - Cubic Polynomial Basis Spline Set
  85.  *      - Ck = 2, Segment Curvature Penalty = 2
  86.  *      - Quadratic Rational Shape Controller
  87.  *      - Natural Boundary Setting
  88.  *  - Set up the Local Curve Control parameters as follows:
  89.  *      - C1 Bessel Monotone Smoothener with no spurious extrema elimination and no monotone filter
  90.  *      - Zero Rate Quantification Metric
  91.  *      - Cubic Polynomial Basis Spline Set
  92.  *      - Ck = 2, Segment Curvature Penalty = 2
  93.  *      - Quadratic Rational Shape Controller
  94.  *      - Natural Boundary Setting
  95.  *  - Construct the Shape Preserving OIS Discount Curve by applying the linear curve calibrator to the array of
  96.  *      Cash and OIS Stretches.
  97.  *  - Construct the Globally Smoothened OIS Discount Curve by applying the linear curve calibrator and the Global
  98.  *      Curve Control parameters to the array of Cash and OIS Stretches and the shape preserving discount
  99.  *      curve.
  100.  *  - Construct the Locally Smoothened OIS Discount Curve by applying the linear curve calibrator and the Local
  101.  *      Curve Control parameters to the array of Cash and OIS Stretches and the shape preserving discount
  102.  *      curve.
  103.  *  - Cross-Comparison of the Cash/OIS Calibration Instrument "Rate" metric across the different curve
  104.  *      construction methodologies.
  105.  *  - Cross-Comparison of the OIS Calibration Instrument "Rate" metric across the different curve
  106.  *      construction methodologies for a sequence of bespoke OIS instruments.
  107.  *
  108.  * @author Lakshmi Krishnamurthy
  109.  */

  110. public class ShapePreservingOvernightZeroSmooth {

  111.     private static final FixFloatComponent OTCOISFixFloat (
  112.         final JulianDate dtSpot,
  113.         final String strCurrency,
  114.         final String strMaturityTenor,
  115.         final double dblCoupon)
  116.     {
  117.         FixedFloatSwapConvention ffConv = OvernightFixedFloatContainer.FundConventionFromJurisdiction (
  118.             strCurrency
  119.         );

  120.         return ffConv.createFixFloatComponent (
  121.             dtSpot,
  122.             strMaturityTenor,
  123.             dblCoupon,
  124.             0.,
  125.             1.
  126.         );
  127.     }

  128.     /*
  129.      * Construct the Array of Deposit Instruments from the given set of parameters
  130.      *
  131.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  132.      */

  133.     private static final SingleStreamComponent[] DepositInstrumentsFromMaturityDays (
  134.         final JulianDate dtEffective,
  135.         final String strCurrency,
  136.         final int[] aiDay)
  137.         throws Exception
  138.     {
  139.         SingleStreamComponent[] aDeposit = new SingleStreamComponent[aiDay.length];

  140.         for (int i = 0; i < aiDay.length; ++i)
  141.             aDeposit[i] = SingleStreamComponentBuilder.Deposit (
  142.                 dtEffective,
  143.                 dtEffective.addBusDays (
  144.                     aiDay[i],
  145.                     strCurrency
  146.                 ),
  147.                 OvernightLabel.Create (
  148.                     strCurrency
  149.                 )
  150.             );

  151.         return aDeposit;
  152.     }

  153.     /*
  154.      * Construct the Array of Overnight Index Instruments from the given set of parameters
  155.      *
  156.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  157.      */

  158.     private static final FixFloatComponent[] OISFromMaturityTenor (
  159.         final JulianDate dtSpot,
  160.         final String strCurrency,
  161.         final String[] astrMaturityTenor,
  162.         final double[] adblCoupon)
  163.         throws Exception
  164.     {
  165.         FixFloatComponent[] aOIS = new FixFloatComponent[astrMaturityTenor.length];

  166.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  167.             aOIS[i] = OTCOISFixFloat (
  168.                 dtSpot,
  169.                 strCurrency,
  170.                 astrMaturityTenor[i],
  171.                 adblCoupon[i]
  172.             );

  173.         return aOIS;
  174.     }

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

  183.         UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  184.             2,
  185.             "Act/360",
  186.             false,
  187.             "Act/360",
  188.             false,
  189.             strCurrency,
  190.             false,
  191.             CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  192.         );

  193.         CashSettleParams csp = new CashSettleParams (
  194.             0,
  195.             strCurrency,
  196.             0
  197.         );

  198.         for (int i = 0; i < astrMaturityTenor.length; ++i) {
  199.             java.lang.String strFixedTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
  200.                 astrMaturityTenor[i],
  201.                 "6M"
  202.             ) ? astrMaturityTenor[i] : "6M";

  203.             java.lang.String strFloatingTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
  204.                 astrMaturityTenor[i],
  205.                 "3M"
  206.             ) ? astrMaturityTenor[i] : "3M";

  207.             ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  208.                 "ON",
  209.                 CompositePeriodBuilder.EDGE_DATE_SEQUENCE_OVERNIGHT,
  210.                 null,
  211.                 OvernightLabel.Create (
  212.                     strCurrency
  213.                 ),
  214.                 CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  215.                 0.
  216.             );

  217.             ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  218.                 strFixedTenor,
  219.                 CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  220.                 null,
  221.                 adblCoupon[i],
  222.                 0.,
  223.                 strCurrency
  224.             );

  225.             CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  226.                 4,
  227.                 strFloatingTenor,
  228.                 strCurrency,
  229.                 null,
  230.                 -1.,
  231.                 null,
  232.                 null,
  233.                 null,
  234.                 null
  235.             );

  236.             CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  237.                 2,
  238.                 strFixedTenor,
  239.                 strCurrency,
  240.                 null,
  241.                 1.,
  242.                 null,
  243.                 null,
  244.                 null,
  245.                 null
  246.             );

  247.             List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  248.                 dtEffective,
  249.                 strFixedTenor,
  250.                 astrMaturityTenor[i],
  251.                 null
  252.             );

  253.             List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  254.                 dtEffective,
  255.                 strFloatingTenor,
  256.                 astrMaturityTenor[i],
  257.                 null
  258.             );

  259.             Stream floatingStream = new Stream (
  260.                 CompositePeriodBuilder.FloatingCompositeUnit (
  261.                     lsFloatingStreamEdgeDate,
  262.                     cpsFloating,
  263.                     cfusFloating
  264.                 )
  265.             );

  266.             Stream fixedStream = new Stream (
  267.                 CompositePeriodBuilder.FixedCompositeUnit (
  268.                     lsFixedStreamEdgeDate,
  269.                     cpsFixed,
  270.                     ucasFixed,
  271.                     cfusFixed
  272.                 )
  273.             );

  274.             FixFloatComponent ois = new FixFloatComponent (
  275.                 fixedStream,
  276.                 floatingStream,
  277.                 csp
  278.             );

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

  280.             aOIS[i] = ois;
  281.         }

  282.         return aOIS;
  283.     }

  284.     /*
  285.      * Construct the Array of Overnight Index Future Instruments from the given set of parameters
  286.      *
  287.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  288.      */

  289.     private static final FixFloatComponent[] OISFuturesFromMaturityTenor (
  290.         final JulianDate dtSpot,
  291.         final String strCurrency,
  292.         final String[] astrStartTenor,
  293.         final String[] astrMaturityTenor,
  294.         final double[] adblCoupon)
  295.         throws Exception
  296.     {
  297.         FixFloatComponent[] aOISFutures = new FixFloatComponent[astrMaturityTenor.length];

  298.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  299.             aOISFutures[i] = OTCOISFixFloat (
  300.                 dtSpot.addTenor (astrStartTenor[i]),
  301.                 strCurrency,
  302.                 astrMaturityTenor[i],
  303.                 adblCoupon[i]
  304.             );

  305.         return aOISFutures;
  306.     }

  307.     /*
  308.      * This sample demonstrates the usage of different shape preserving and smoothing techniques involved in
  309.      *  the OIS discount curve creation. It shows the following:
  310.      *  - Construct the Array of Cash/OIS Instruments and their Quotes from the given set of parameters.
  311.      *  - Construct the Cash/OIS Instrument Set Stretch Builder.
  312.      *  - Set up the Linear Curve Calibrator using the following parameters:
  313.      *      - Cubic Exponential Mixture Basis Spline Set
  314.      *      - Ck = 2, Segment Curvature Penalty = 2
  315.      *      - Quadratic Rational Shape Controller
  316.      *      - Natural Boundary Setting
  317.      *  - Set up the Global Curve Control parameters as follows:
  318.      *      - Zero Rate Quantification Metric
  319.      *      - Cubic Polynomial Basis Spline Set
  320.      *      - Ck = 2, Segment Curvature Penalty = 2
  321.      *      - Quadratic Rational Shape Controller
  322.      *      - Natural Boundary Setting
  323.      *  - Set up the Local Curve Control parameters as follows:
  324.      *      - C1 Bessel Monotone Smoothener with no spurious extrema elimination and no monotone filter
  325.      *      - Zero Rate Quantification Metric
  326.      *      - Cubic Polynomial Basis Spline Set
  327.      *      - Ck = 2, Segment Curvature Penalty = 2
  328.      *      - Quadratic Rational Shape Controller
  329.      *      - Natural Boundary Setting
  330.      *  - Construct the Shape Preserving OIS Discount Curve by applying the linear curve calibrator to the array
  331.      *      of Cash and OIS Stretches.
  332.      *  - Construct the Globally Smoothened OIS Discount Curve by applying the linear curve calibrator and the
  333.      *      Global Curve Control parameters to the array of Cash and OIS Stretches and the shape preserving
  334.      *      discount curve.
  335.      *  - Construct the Locally Smoothened OIS Discount Curve by applying the linear curve calibrator and the
  336.      *      Local Curve Control parameters to the array of Cash and OIS Stretches and the shape preserving
  337.      *      discount curve.
  338.      *  - Cross-Comparison of the Cash/OIS Calibration Instrument "Rate" metric across the different curve
  339.      *      construction methodologies.
  340.      *  - Cross-Comparison of the OIS Calibration Instrument "Rate" metric across the different curve
  341.      *      construction methodologies for a sequence of bespoke OIS instruments.
  342.      *
  343.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  344.      */

  345.     private static final void ShapePreservingOISDFZeroSmoothSample (
  346.         final JulianDate dtSpot,
  347.         final String strCurrency)
  348.         throws Exception
  349.     {
  350.         /*
  351.          * Initialize the Credit Analytics Library
  352.          */

  353.         EnvManager.InitEnv ("");

  354.         /*
  355.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  356.          */

  357.         SingleStreamComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  358.             dtSpot,
  359.             strCurrency,
  360.             new int[] {
  361.                 1, 2, 3
  362.             }
  363.         );

  364.         double[] adblDepositQuote = new double[] {
  365.             0.0004, 0.0004, 0.0004       // Deposit
  366.         };

  367.         /*
  368.          * Construct the Deposit Instrument Set Stretch Builder
  369.          */

  370.         LatentStateStretchSpec depositStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  371.             "   DEPOSIT   ",
  372.             aDepositComp,
  373.             "ForwardRate",
  374.             adblDepositQuote
  375.         );

  376.         /*
  377.          * Construct the Array of Short End OIS Instruments and their Quotes from the given set of parameters
  378.          */

  379.         double[] adblShortEndOISQuote = new double[] {
  380.             0.00070,    //   1W
  381.             0.00069,    //   2W
  382.             0.00078,    //   3W
  383.             0.00074     //   1M
  384.         };

  385.         CalibratableComponent[] aShortEndOISComp = OISFromMaturityTenor (
  386.             dtSpot,
  387.             strCurrency,
  388.             new java.lang.String[] {
  389.                 "1W", "2W", "3W", "1M"
  390.             },
  391.             adblShortEndOISQuote
  392.         );

  393.         /*
  394.          * Construct the Short End OIS Instrument Set Stretch Builder
  395.          */

  396.         LatentStateStretchSpec oisShortEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  397.             "SHORT END OIS",
  398.             aShortEndOISComp,
  399.             "SwapRate",
  400.             adblShortEndOISQuote
  401.         );

  402.         /*
  403.          * Construct the Array of OIS Futures Instruments and their Quotes from the given set of parameters
  404.          */

  405.         double[] adblOISFutureQuote = new double[] {
  406.              0.00046,    //   1M x 1M
  407.              0.00016,    //   2M x 1M
  408.             -0.00007,    //   3M x 1M
  409.             -0.00013,    //   4M x 1M
  410.             -0.00014     //   5M x 1M
  411.         };

  412.         CalibratableComponent[] aOISFutureComp = OISFuturesFromMaturityTenor (
  413.             dtSpot,
  414.             strCurrency,
  415.             new java.lang.String[] {
  416.                 "1M", "2M", "3M", "4M", "5M"
  417.             },
  418.             new java.lang.String[] {
  419.                 "1M", "1M", "1M", "1M", "1M"
  420.             },
  421.             adblOISFutureQuote
  422.         );

  423.         /*
  424.          * Construct the OIS Future Instrument Set Stretch Builder
  425.          */

  426.         LatentStateStretchSpec oisFutureStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  427.             " OIS FUTURE  ",
  428.             aOISFutureComp,
  429.             "SwapRate",
  430.             adblOISFutureQuote
  431.         );

  432.         /*
  433.          * Construct the Array of Long End OIS Instruments and their Quotes from the given set of parameters
  434.          */

  435.         double[] adblLongEndOISQuote = new double[] {
  436.             0.00002,    //  15M
  437.             0.00008,    //  18M
  438.             0.00021,    //  21M
  439.             0.00036,    //   2Y
  440.             0.00127,    //   3Y
  441.             0.00274,    //   4Y
  442.             0.00456,    //   5Y
  443.             0.00647,    //   6Y
  444.             0.00827,    //   7Y
  445.             0.00996,    //   8Y
  446.             0.01147,    //   9Y
  447.             0.01280,    //  10Y
  448.             0.01404,    //  11Y
  449.             0.01516,    //  12Y
  450.             0.01764,    //  15Y
  451.             0.01939,    //  20Y
  452.             0.02003,    //  25Y
  453.             0.02038     //  30Y
  454.         };

  455.         CalibratableComponent[] aLongEndOISComp = OISFromMaturityTenor (
  456.             dtSpot,
  457.             strCurrency,
  458.             new java.lang.String[] {
  459.                 "15M", "18M", "21M", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  460.             },
  461.             adblLongEndOISQuote
  462.         );

  463.         /*
  464.          * Construct the Long End OIS Instrument Set Stretch Builder
  465.          */

  466.         LatentStateStretchSpec oisLongEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  467.             "LONG END OIS ",
  468.             aLongEndOISComp,
  469.             "SwapRate",
  470.             adblLongEndOISQuote
  471.         );

  472.         LatentStateStretchSpec[] aStretchSpec = new LatentStateStretchSpec[] {
  473.             depositStretch,
  474.             oisShortEndStretch,
  475.             oisFutureStretch,
  476.             oisLongEndStretch
  477.         };

  478.         /*
  479.          * Set up the Linear Curve Calibrator using the following parameters:
  480.          *  - Cubic Exponential Mixture Basis Spline Set
  481.          *  - Ck = 2, Segment Curvature Penalty = 2
  482.          *  - Quadratic Rational Shape Controller
  483.          *  - Natural Boundary Setting
  484.          */

  485.         LinearLatentStateCalibrator lcc = new LinearLatentStateCalibrator (
  486.             new SegmentCustomBuilderControl (
  487.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_EXPONENTIAL_MIXTURE,
  488.                 new ExponentialMixtureSetParams (
  489.                     new double[] {
  490.                         0.01,
  491.                         0.05,
  492.                         0.25
  493.                     }
  494.                 ),
  495.                 SegmentInelasticDesignControl.Create (
  496.                     2,
  497.                     2
  498.                 ),
  499.                 new ResponseScalingShapeControl (
  500.                     true,
  501.                     new QuadraticRationalShapeControl (0.)
  502.                 ),
  503.                 null
  504.             ),
  505.             BoundarySettings.NaturalStandard(),
  506.             MultiSegmentSequence.CALIBRATE,
  507.             null,
  508.             null
  509.         );

  510.         /*
  511.          * Set up the Local Curve Control parameters as follows:
  512.          *  - C1 Bessel Monotone Smoothener with no spurious extrema elimination and no monotone filter
  513.          *  - Zero Rate Quantification Metric
  514.          *  - Cubic Polynomial Basis Spline Set
  515.          *  - Ck = 2, Segment Curvature Penalty = 2
  516.          *  - Quadratic Rational Shape Controller
  517.          *  - Natural Boundary Setting
  518.          */

  519.         LocalControlCurveParams lccp = new LocalControlCurveParams (
  520.             LocalMonotoneCkGenerator.C1_BESSEL,
  521.             LatentStateStatic.DISCOUNT_QM_ZERO_RATE,
  522.             new SegmentCustomBuilderControl (
  523.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  524.                 new PolynomialFunctionSetParams (4),
  525.                 SegmentInelasticDesignControl.Create (
  526.                     2,
  527.                     2
  528.                 ),
  529.                 new ResponseScalingShapeControl (
  530.                     true,
  531.                     new QuadraticRationalShapeControl (0.)
  532.                 ),
  533.                 null
  534.             ),
  535.             MultiSegmentSequence.CALIBRATE,
  536.             null,
  537.             null,
  538.             false,
  539.             false
  540.         );

  541.         /*
  542.          * Construct the Shape Preserving OIS Discount Curve by applying the linear curve calibrator to the array
  543.          *  of Cash and OIS Stretches.
  544.          */

  545.         MergedDiscountForwardCurve dcShapePreserving = ScenarioDiscountCurveBuilder.ShapePreservingDFBuild (
  546.             strCurrency,
  547.             lcc,
  548.             aStretchSpec,
  549.             new ValuationParams (
  550.                 dtSpot,
  551.                 dtSpot,
  552.                 strCurrency
  553.             ),
  554.             null,
  555.             null,
  556.             null,
  557.             1.
  558.         );

  559.         /*
  560.          * Construct the Globally Smoothened OIS Discount Curve by applying the linear curve calibrator and the
  561.          *  Global Curve Control parameters to the array of Cash and OIS Stretches and the shape preserving
  562.          *  discount curve.
  563.          */

  564.         /* DiscountCurve dcGloballySmooth = ScenarioDiscountCurveBuilder.SmoothingGlobalControlBuild (
  565.             dcShapePreserving,
  566.             lcc,
  567.             gccp,
  568.             aRRS,
  569.             new ValuationParams (dtToday, dtToday, "USD"),
  570.             null,
  571.             null,
  572.             null); */

  573.         /*
  574.          * Construct the Locally Smoothened OIS Discount Curve by applying the linear curve calibrator and the
  575.          *  Local Curve Control parameters to the array of Cash and OIS Stretches and the shape preserving
  576.          *  discount curve.
  577.          */

  578.         MergedDiscountForwardCurve dcLocallySmooth = ScenarioDiscountCurveBuilder.SmoothingLocalControlBuild (
  579.             dcShapePreserving,
  580.             lcc,
  581.             lccp,
  582.             new ValuationParams (
  583.                 dtSpot,
  584.                 dtSpot,
  585.                 strCurrency
  586.             ),
  587.             null,
  588.             null,
  589.             null
  590.         );

  591.         /*
  592.          * Cross-Comparison of the Deposit Calibration Instrument "Rate" metric across the different curve
  593.          *  construction methodologies.
  594.          */

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

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

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

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

  599.         System.out.println ("\t        SHAPE PRESERVING   | SMOOTHING #1  | SMOOTHING #2  |  INPUT QUOTE  ");

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

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

  602.         for (int i = 0; i < aDepositComp.length; ++i)
  603.             System.out.println ("\t[" + aDepositComp[i].maturityDate() + "] = " +
  604.                 FormatUtil.FormatDouble (
  605.                     aDepositComp[i].measureValue (
  606.                         new ValuationParams (dtSpot, dtSpot, strCurrency), null,
  607.                         MarketParamsBuilder.Create (dcShapePreserving, null, null, null, null, null, null),
  608.                         null,
  609.                         "Rate"),
  610.                     1, 6, 1.) + "   |   " +
  611.                 /* FormatUtil.FormatDouble (
  612.                     aDeposit[i].measureValue (
  613.                         new ValuationParams (dtToday, dtToday, "USD"), null,
  614.                         ComponentMarketParamsBuilder.Create (dcGloballySmooth, null, null, null, null, null, null),
  615.                         null,
  616.                         "Rate"),
  617.                     1, 6, 1.) + "   |   " + */
  618.                 FormatUtil.FormatDouble (
  619.                     aDepositComp[i].measureValue (
  620.                         new ValuationParams (dtSpot, dtSpot, strCurrency), null,
  621.                         MarketParamsBuilder.Create (dcLocallySmooth, null, null, null, null, null, null),
  622.                         null,
  623.                         "Rate"),
  624.                     1, 6, 1.) + "   |   " +
  625.                 FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.)
  626.             );

  627.         /*
  628.          * Cross-Comparison of the OIS Calibration Instrument "Rate" metric across the different curve
  629.          *  construction methodologies.
  630.          */

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

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

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

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

  635.         System.out.println ("\t        SHAPE PRESERVING   | SMOOTHING #1  | SMOOTHING #2  |  INPUT QUOTE  ");

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

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

  638.         for (int i = 0; i < aLongEndOISComp.length; ++i)
  639.             System.out.println ("\t[" + aLongEndOISComp[i].maturityDate() + "] = " +
  640.                 FormatUtil.FormatDouble (
  641.                     aLongEndOISComp[i].measureValue (
  642.                         new ValuationParams (dtSpot, dtSpot, strCurrency), null,
  643.                         MarketParamsBuilder.Create (dcShapePreserving, null, null, null, null, null, null),
  644.                         null,
  645.                         "CalibSwapRate"),
  646.                     1, 6, 1.) + "   |   " +
  647.                 /* FormatUtil.FormatDouble (
  648.                     aOISComp[i].measureValue (
  649.                         new ValuationParams (dtToday, dtToday, "USD"), null,
  650.                         ComponentMarketParamsBuilder.Create (dcGloballySmooth, null, null, null, null, null, null),
  651.                         null,
  652.                         "CalibSwapRate"),
  653.                     1, 6, 1.) + "   |   " + */
  654.                 FormatUtil.FormatDouble (
  655.                     aLongEndOISComp[i].measureValue (
  656.                         new ValuationParams (dtSpot, dtSpot, strCurrency), null,
  657.                         MarketParamsBuilder.Create (dcLocallySmooth, null, null, null, null, null, null),
  658.                         null,
  659.                         "CalibSwapRate"),
  660.                     1, 6, 1.) + "   |   " +
  661.                 FormatUtil.FormatDouble (adblLongEndOISQuote[i], 1, 6, 1.)
  662.             );

  663.         /*
  664.          * Cross-Comparison of the OIS Calibration Instrument "Rate" metric across the different curve
  665.          *  construction methodologies for a sequence of bespoke OIS instruments.
  666.          */

  667.         CalibratableComponent[] aCC = OvernightIndexFromMaturityTenor (
  668.             dtSpot,
  669.             new java.lang.String[] {
  670.                 "3Y", "6Y", "9Y", "12Y", "15Y", "18Y", "21Y", "24Y", "27Y", "30Y"
  671.             },
  672.             new double[] {
  673.                 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01
  674.             },
  675.             strCurrency
  676.         );

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

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

  679.         System.out.println ("\t           BESPOKE OIS PAR RATE");

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

  681.         System.out.println ("\t        SHAPE PRESERVING   |  SMOOTHING #1 |  SMOOTHING #2");

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

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

  684.         for (int i = 0; i < aCC.length; ++i)
  685.             System.out.println ("\t[" + aCC[i].maturityDate() + "] = " +
  686.                 FormatUtil.FormatDouble (
  687.                     aCC[i].measureValue (new ValuationParams (dtSpot, dtSpot, strCurrency), null,
  688.                     MarketParamsBuilder.Create (dcShapePreserving, null, null, null, null, null, null),
  689.                     null,
  690.                     "CalibSwapRate"),
  691.                 1, 6, 1.) + "   |   " +
  692.                 /* FormatUtil.FormatDouble (
  693.                     aCC[i].measureValue (new ValuationParams (dtToday, dtToday, "USD"), null,
  694.                     ComponentMarketParamsBuilder.Create (dcGloballySmooth, null, null, null, null, null, null),
  695.                     null,
  696.                     "CalibSwapRate"),
  697.                 1, 6, 1.) + "   |   " + */
  698.                 FormatUtil.FormatDouble (
  699.                     aCC[i].measureValue (new ValuationParams (dtSpot, dtSpot, strCurrency), null,
  700.                     MarketParamsBuilder.Create (dcLocallySmooth, null, null, null, null, null, null),
  701.                     null,
  702.                     "CalibSwapRate"),
  703.                 1, 6, 1.)
  704.             );
  705.     }

  706.     public static final void main (
  707.         final String[] astrArgs)
  708.         throws Exception
  709.     {
  710.         ShapePreservingOISDFZeroSmoothSample (
  711.             DateUtil.Today(),
  712.             "EUR"
  713.         );
  714.     }
  715. }