SWPM_NEW.java

  1. package org.drip.sample.bloomberg;

  2. import java.util.*;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.support.CompositePeriodBuilder;
  5. import org.drip.function.r1tor1.QuadraticRationalShapeControl;
  6. import org.drip.market.otc.*;
  7. import org.drip.numerical.common.FormatUtil;
  8. import org.drip.param.creator.*;
  9. import org.drip.param.market.CurveSurfaceQuoteContainer;
  10. import org.drip.param.period.*;
  11. import org.drip.param.valuation.ValuationParams;
  12. import org.drip.product.creator.SingleStreamComponentBuilder;
  13. import org.drip.product.definition.CalibratableComponent;
  14. import org.drip.product.rates.*;
  15. import org.drip.sample.forward.IBORCurve;
  16. import org.drip.service.env.EnvManager;
  17. import org.drip.spline.basis.PolynomialFunctionSetParams;
  18. import org.drip.spline.params.*;
  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.LatentStateStretchBuilder;
  23. import org.drip.state.forward.ForwardCurve;
  24. import org.drip.state.identifier.*;
  25. import org.drip.state.inference.*;

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

  29. /*!
  30.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  31.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  32.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  33.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  34.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  35.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  36.  * Copyright (C) 2014 Lakshmi Krishnamurthy
  37.  * Copyright (C) 2013 Lakshmi Krishnamurthy
  38.  *
  39.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  40.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  41.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  42.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  43.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  44.  *      and computational support.
  45.  *  
  46.  *      https://lakshmidrip.github.io/DROP/
  47.  *  
  48.  *  DROP is composed of three modules:
  49.  *  
  50.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  51.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  52.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  53.  *
  54.  *  DROP Product Core implements libraries for the following:
  55.  *  - Fixed Income Analytics
  56.  *  - Loan Analytics
  57.  *  - Transaction Cost Analytics
  58.  *
  59.  *  DROP Portfolio Core implements libraries for the following:
  60.  *  - Asset Allocation Analytics
  61.  *  - Asset Liability Management Analytics
  62.  *  - Capital Estimation Analytics
  63.  *  - Exposure Analytics
  64.  *  - Margin Analytics
  65.  *  - XVA Analytics
  66.  *
  67.  *  DROP Computational Core implements libraries for the following:
  68.  *  - Algorithm Support
  69.  *  - Computation Support
  70.  *  - Function Analysis
  71.  *  - Model Validation
  72.  *  - Numerical Analysis
  73.  *  - Numerical Optimizer
  74.  *  - Spline Builder
  75.  *  - Statistical Learning
  76.  *
  77.  *  Documentation for DROP is Spread Over:
  78.  *
  79.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  80.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  81.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  82.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  83.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  84.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  85.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  86.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  87.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  88.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  89.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  90.  *
  91.  *  Licensed under the Apache License, Version 2.0 (the "License");
  92.  *      you may not use this file except in compliance with the License.
  93.  *  
  94.  *  You may obtain a copy of the License at
  95.  *      http://www.apache.org/licenses/LICENSE-2.0
  96.  *  
  97.  *  Unless required by applicable law or agreed to in writing, software
  98.  *      distributed under the License is distributed on an "AS IS" BASIS,
  99.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  100.  *  
  101.  *  See the License for the specific language governing permissions and
  102.  *      limitations under the License.
  103.  */

  104. /**
  105.  * <i>SWPM_NEW</i> contains the sample demonstrating the replication of Bloomberg's Latest SWPM
  106.  * Functionality.
  107.  *  
  108.  * <br><br>
  109.  *  <ul>
  110.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  111.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  112.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  113.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bloomberg/README.md">Bloomberg CDSO CDSW SWPM YAS</a></li>
  114.  *  </ul>
  115.  * <br><br>
  116.  *
  117.  * @author Lakshmi Krishnamurthy
  118.  */

  119. public class SWPM_NEW {

  120.     private static final FixFloatComponent OTCOISFixFloat (
  121.         final JulianDate dtSpot,
  122.         final String strCurrency,
  123.         final String strMaturityTenor,
  124.         final double dblCoupon)
  125.     {
  126.         FixedFloatSwapConvention ffConv = OvernightFixedFloatContainer.FundConventionFromJurisdiction (
  127.             strCurrency
  128.         );

  129.         return ffConv.createFixFloatComponent (
  130.             dtSpot,
  131.             strMaturityTenor,
  132.             dblCoupon,
  133.             0.,
  134.             1.
  135.         );
  136.     }

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

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

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

  160.         return aDeposit;
  161.     }

  162.     /*
  163.      * Construct the Array of Overnight Index Instruments from the given set of parameters
  164.      *
  165.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  166.      */

  167.     private static final FixFloatComponent[] OISFromMaturityTenor (
  168.         final JulianDate dtSpot,
  169.         final String strCurrency,
  170.         final String[] astrMaturityTenor,
  171.         final double[] adblCoupon)
  172.         throws Exception
  173.     {
  174.         FixFloatComponent[] aOIS = new FixFloatComponent[astrMaturityTenor.length];

  175.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  176.             aOIS[i] = OTCOISFixFloat (
  177.                 dtSpot,
  178.                 strCurrency,
  179.                 astrMaturityTenor[i],
  180.                 adblCoupon[i]
  181.             );

  182.         return aOIS;
  183.     }

  184.     private static final FixFloatComponent[] OISFuturesFromMaturityTenor (
  185.         final JulianDate dtSpot,
  186.         final String strCurrency,
  187.         final String[] astrStartTenor,
  188.         final String[] astrMaturityTenor,
  189.         final double[] adblCoupon)
  190.         throws Exception
  191.     {
  192.         FixFloatComponent[] aOISFutures = new FixFloatComponent[astrMaturityTenor.length];

  193.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  194.             aOISFutures[i] = OTCOISFixFloat (
  195.                 dtSpot.addTenor (astrStartTenor[i]),
  196.                 strCurrency,
  197.                 astrMaturityTenor[i],
  198.                 adblCoupon[i]
  199.             );

  200.         return aOISFutures;
  201.     }

  202.     /*
  203.      * Construct the Array of Overnight Index Future Instruments from the given set of parameters
  204.      *
  205.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  206.      */

  207.     private static final MergedDiscountForwardCurve OvernightCurve (
  208.         final JulianDate dtSpot,
  209.         final String strCurrency,
  210.         final String strHeaderComment)
  211.         throws Exception
  212.     {
  213.         System.out.println ("\n\t----------------------------------------------------------------");

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

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

  216.         /*
  217.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  218.          */

  219.         SingleStreamComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  220.             dtSpot,
  221.             strCurrency,
  222.             new int[] {
  223.                 1, 2, 3
  224.             }
  225.         );

  226.         double[] adblDepositQuote = new double[] {
  227.             0.0004, 0.0004, 0.0004       // Deposit
  228.         };

  229.         /*
  230.          * Construct the Deposit Instrument Set Stretch Builder
  231.          */

  232.         LatentStateStretchSpec depositStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  233.             "DEPOSIT",
  234.             aDepositComp,
  235.             "ForwardRate",
  236.             adblDepositQuote
  237.         );

  238.         /*
  239.          * Construct the Array of Short End OIS Instruments and their Quotes from the given set of parameters
  240.          */

  241.         double[] adblShortEndOISQuote = new double[] {
  242.             0.00070,    //   1W
  243.             0.00069,    //   2W
  244.             0.00078,    //   3W
  245.             0.00074     //   1M
  246.         };

  247.         CalibratableComponent[] aShortEndOISComp = OISFromMaturityTenor (
  248.             dtSpot,
  249.             strCurrency,
  250.             new java.lang.String[] {
  251.                 "1W", "2W", "3W", "1M"
  252.             },
  253.             adblShortEndOISQuote
  254.         );

  255.         /*
  256.          * Construct the Short End OIS Instrument Set Stretch Builder
  257.          */

  258.         LatentStateStretchSpec oisShortEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  259.             "OIS_SHORT_END",
  260.             aShortEndOISComp,
  261.             "SwapRate",
  262.             adblShortEndOISQuote
  263.         );

  264.         /*
  265.          * Construct the Array of OIS Futures Instruments and their Quotes from the given set of parameters
  266.          */

  267.         double[] adblOISFutureQuote = new double[] {
  268.              0.00046,    //   1M x 1M
  269.              0.00016,    //   2M x 1M
  270.             -0.00007,    //   3M x 1M
  271.             -0.00013,    //   4M x 1M
  272.             -0.00014     //   5M x 1M
  273.         };

  274.         CalibratableComponent[] aOISFutureComp = OISFuturesFromMaturityTenor (
  275.             dtSpot,
  276.             strCurrency,
  277.             new java.lang.String[] {
  278.                 "1M", "2M", "3M", "4M", "5M"
  279.             },
  280.             new java.lang.String[] {
  281.                 "1M", "1M", "1M", "1M", "1M"
  282.             },
  283.             adblOISFutureQuote
  284.         );

  285.         /*
  286.          * Construct the OIS Future Instrument Set Stretch Builder
  287.          */

  288.         LatentStateStretchSpec oisFutureStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  289.             "OIS_FUTURE",
  290.             aOISFutureComp,
  291.             "SwapRate",
  292.             adblOISFutureQuote
  293.         );

  294.         /*
  295.          * Construct the Array of Long End OIS Instruments and their Quotes from the given set of parameters
  296.          */

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

  317.         CalibratableComponent[] aLongEndOISComp = OISFromMaturityTenor (
  318.             dtSpot,
  319.             strCurrency,
  320.             new java.lang.String[] {
  321.                 "15M", "18M", "21M", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  322.             },
  323.             adblLongEndOISQuote
  324.         );

  325.         /*
  326.          * Construct the Long End OIS Instrument Set Stretch Builder
  327.          */

  328.         LatentStateStretchSpec oisLongEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
  329.             "OIS_LONG_END",
  330.             aLongEndOISComp,
  331.             "SwapRate",
  332.             adblLongEndOISQuote
  333.         );

  334.         LatentStateStretchSpec[] aStretchSpec = new LatentStateStretchSpec[] {
  335.             depositStretch,
  336.             oisShortEndStretch,
  337.             oisFutureStretch,
  338.             oisLongEndStretch
  339.         };

  340.         /*
  341.          * Set up the Linear Curve Calibrator using the following parameters:
  342.          *  - Cubic Exponential Mixture Basis Spline Set
  343.          *  - Ck = 2, Segment Curvature Penalty = 2
  344.          *  - Quadratic Rational Shape Controller
  345.          *  - Natural Boundary Setting
  346.          */

  347.         LinearLatentStateCalibrator lcc = new LinearLatentStateCalibrator (
  348.             new SegmentCustomBuilderControl (
  349.                 MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  350.                 new PolynomialFunctionSetParams (4),
  351.                 SegmentInelasticDesignControl.Create (
  352.                     2,
  353.                     2
  354.                 ),
  355.                 new ResponseScalingShapeControl (
  356.                     true,
  357.                     new QuadraticRationalShapeControl (0.)
  358.                 ),
  359.                 null
  360.             ),
  361.             BoundarySettings.NaturalStandard(),
  362.             MultiSegmentSequence.CALIBRATE,
  363.             null,
  364.             null
  365.         );

  366.         /*
  367.          * Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array
  368.          *  of Deposit and Swap Stretches.
  369.          */

  370.         ValuationParams valParams = new ValuationParams (
  371.             dtSpot,
  372.             dtSpot,
  373.             strCurrency
  374.         );

  375.         MergedDiscountForwardCurve dcOvernight = ScenarioDiscountCurveBuilder.ShapePreservingDFBuild (
  376.             strCurrency,
  377.             lcc,
  378.             aStretchSpec,
  379.             valParams,
  380.             null,
  381.             null,
  382.             null,
  383.             1.
  384.         );

  385.         /*
  386.          * Cross-Comparison of the Deposit Calibration Instrument "Rate" metric across the different curve
  387.          *  construction methodologies.
  388.          */

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

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

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

  392.         for (int i = 0; i < aDepositComp.length; ++i)
  393.             System.out.println ("\t[" + aDepositComp[i].effectiveDate() + " => " + aDepositComp[i].maturityDate() + "] = " +
  394.                 FormatUtil.FormatDouble (aDepositComp[i].measureValue (valParams, null,
  395.                     MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  396.                         null, "Rate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.));

  397.         /*
  398.          * Cross-Comparison of the Short End OIS Calibration Instrument "Rate" metric across the different curve
  399.          *  construction methodologies.
  400.          */

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

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

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

  404.         for (int i = 0; i < aShortEndOISComp.length; ++i)
  405.             System.out.println ("\t[" + aShortEndOISComp[i].effectiveDate() + " => " + aShortEndOISComp[i].maturityDate() + "] = " +
  406.                 FormatUtil.FormatDouble (aShortEndOISComp[i].measureValue (valParams, null,
  407.                     MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  408.                         null, "CalibSwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblShortEndOISQuote[i], 1, 6, 1.) + " | " +
  409.                             FormatUtil.FormatDouble (aShortEndOISComp[i].measureValue (valParams, null,
  410.                                 MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  411.                                     null, "FairPremium"), 1, 6, 1.));

  412.         /*
  413.          * Cross-Comparison of the OIS Future Calibration Instrument "Rate" metric across the different curve
  414.          *  construction methodologies.
  415.          */

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

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

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

  419.         for (int i = 0; i < aOISFutureComp.length; ++i)
  420.             System.out.println ("\t[" + aOISFutureComp[i].effectiveDate() + " => " + aOISFutureComp[i].maturityDate() + "] = " +
  421.                 FormatUtil.FormatDouble (aOISFutureComp[i].measureValue (valParams, null,
  422.                     MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  423.                         null, "SwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblOISFutureQuote[i], 1, 6, 1.) + " | " +
  424.                             FormatUtil.FormatDouble (aOISFutureComp[i].measureValue (valParams, null,
  425.                                 MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  426.                                     null, "FairPremium"), 1, 6, 1.));

  427.         /*
  428.          * Cross-Comparison of the Long End OIS Calibration Instrument "Rate" metric across the different curve
  429.          *  construction methodologies.
  430.          */

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

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

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

  434.         for (int i = 0; i < aLongEndOISComp.length; ++i)
  435.             System.out.println ("\t[" + aLongEndOISComp[i].effectiveDate() + " => " + aLongEndOISComp[i].maturityDate() + "] = " +
  436.                 FormatUtil.FormatDouble (aLongEndOISComp[i].measureValue (valParams, null,
  437.                     MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  438.                         null, "CalibSwapRate"), 1, 6, 1.) + " | " + FormatUtil.FormatDouble (adblLongEndOISQuote[i], 1, 6, 1.) + " | " +
  439.                             FormatUtil.FormatDouble (aLongEndOISComp[i].measureValue (valParams, null,
  440.                                 MarketParamsBuilder.Create (dcOvernight, null, null, null, null, null, null),
  441.                                     null, "FairPremium"), 1, 6, 1.));

  442.         return dcOvernight;
  443.     }

  444.     public static final ForwardCurve MakeForwardCurve (
  445.         final JulianDate dtValue,
  446.         final MergedDiscountForwardCurve dcOvernight,
  447.         final String strForwardTenor)
  448.         throws Exception
  449.     {
  450.         String strCurrency = dcOvernight.currency();

  451.         ForwardLabel fri = ForwardLabel.Create (
  452.             strCurrency,
  453.             strForwardTenor
  454.         );

  455.         SegmentCustomBuilderControl scbcCubic = new SegmentCustomBuilderControl (
  456.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  457.             new PolynomialFunctionSetParams (4),
  458.             SegmentInelasticDesignControl.Create (
  459.                 2,
  460.                 2
  461.             ),
  462.             new ResponseScalingShapeControl (
  463.                 true,
  464.                 new QuadraticRationalShapeControl (0.)
  465.             ),
  466.             null
  467.         );

  468.         /*
  469.          * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
  470.          */

  471.         double[] adblDepositQuote = new double[] {
  472.             0.003565,   // 1D
  473.             0.003858,   // 1W
  474.             0.003840,   // 2W
  475.             0.003922,   // 3W
  476.             0.003869,   // 1M
  477.             0.003698,   // 2M
  478.         };

  479.         String[] astrDepositTenor = new String[] {
  480.             "1D",
  481.             "1W",
  482.             "2W",
  483.             "3W",
  484.             "1M",
  485.             "2M",
  486.         };

  487.         /*
  488.          * Construct the Array of FRAs and their Quotes from the given set of parameters
  489.          */

  490.         double[] adblFRAQuote = new double[] {
  491.             0.003120,   //  0D
  492.             0.002930,   //  1M
  493.             0.002720,   //  2M
  494.             0.002600,   //  3M
  495.             0.002560,   //  4M
  496.             0.002520,   //  5M
  497.             0.002480,   //  6M
  498.             0.002540,   //  7M
  499.             0.002610,   //  8M
  500.             0.002670,   //  9M
  501.             0.002790,   // 10M
  502.             0.002910,   // 11M
  503.             0.003030,   // 12M
  504.             0.003180,   // 13M
  505.             0.003350,   // 14M
  506.             0.003520,   // 15M
  507.             0.003710,   // 16M
  508.             0.003890,   // 17M
  509.             0.004090    // 18M
  510.         };

  511.         String[] astrFRATenor = new String[] {
  512.              "0D",
  513.              "1M",
  514.              "2M",
  515.              "3M",
  516.              "4M",
  517.              "5M",
  518.              "6M",
  519.              "7M",
  520.              "8M",
  521.              "9M",
  522.             "10M",
  523.             "11M",
  524.             "12M",
  525.             "13M",
  526.             "14M",
  527.             "15M",
  528.             "16M",
  529.             "17M",
  530.             "18M"
  531.         };

  532.         /*
  533.          * Construct the Array of Fix-Float Component and their Quotes from the given set of parameters
  534.          */

  535.         double[] adblFixFloatQuote = new double[] {
  536.             0.004240,   //  3Y
  537.             0.005760,   //  4Y          
  538.             0.007620,   //  5Y
  539.             0.009540,   //  6Y
  540.             0.011350,   //  7Y
  541.             0.013030,   //  8Y
  542.             0.014520,   //  9Y
  543.             0.015840,   // 10Y
  544.             0.018090,   // 12Y
  545.             0.020370,   // 15Y
  546.             0.021870,   // 20Y
  547.             0.022340,   // 25Y
  548.             0.022560,   // 30Y
  549.             0.022950,   // 35Y
  550.             0.023480,   // 40Y
  551.             0.024210,   // 50Y
  552.             0.024630    // 60Y
  553.         };

  554.         String[] astrFixFloatTenor = new String[] {
  555.              "3Y",
  556.              "4Y",
  557.              "5Y",
  558.              "6Y",
  559.              "7Y",
  560.              "8Y",
  561.              "9Y",
  562.             "10Y",
  563.             "12Y",
  564.             "15Y",
  565.             "20Y",
  566.             "25Y",
  567.             "30Y",
  568.             "35Y",
  569.             "40Y",
  570.             "50Y",
  571.             "60Y"
  572.         };

  573.         return IBORCurve.CustomIBORBuilderSample (
  574.             dcOvernight,
  575.             null,
  576.             fri,
  577.             scbcCubic,
  578.             astrDepositTenor,
  579.             adblDepositQuote,
  580.             "ForwardRate",
  581.             astrFRATenor,
  582.             adblFRAQuote,
  583.             "ParForwardRate",
  584.             astrFixFloatTenor,
  585.             adblFixFloatQuote,
  586.             "SwapRate",
  587.             null,
  588.             null,
  589.             "DerivedParBasisSpread",
  590.             null,
  591.             null,
  592.             "DerivedParBasisSpread",
  593.             "---- " + strCurrency + "-LIBOR-" + strForwardTenor + " VANILLA CUBIC POLYNOMIAL FORWARD CURVE ---",
  594.             true
  595.         );
  596.     }

  597.     /*
  598.      * Construct an array of fix-float swaps from the fixed reference and the xM floater derived legs.
  599.      *
  600.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  601.      */

  602.     private static final FixFloatComponent FixFloatSwap (
  603.         final JulianDate dtEffective,
  604.         final ForwardLabel fri,
  605.         final String strFixedTenor,
  606.         final String strMaturityTenor,
  607.         final double dblCoupon)
  608.         throws Exception
  609.     {
  610.         String strCurrency = fri.currency();

  611.         int iTenorInMonths = Integer.parseInt (fri.tenor().split ("M")[0]);

  612.         UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  613.             2,
  614.             "Act/360",
  615.             false,
  616.             "Act/360",
  617.             false,
  618.             strCurrency,
  619.             false,
  620.             CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  621.         );

  622.         ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  623.             fri.tenor(),
  624.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  625.             null,
  626.             fri,
  627.             CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  628.             0.
  629.         );

  630.         CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  631.             12 / iTenorInMonths,
  632.             fri.tenor(),
  633.             strCurrency,
  634.             null,
  635.             -1.,
  636.             null,
  637.             null,
  638.             null,
  639.             null
  640.         );

  641.         ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  642.             strFixedTenor,
  643.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  644.             null,
  645.             dblCoupon,
  646.             0.,
  647.             strCurrency
  648.         );

  649.         CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  650.             2,
  651.             strFixedTenor,
  652.             strCurrency,
  653.             null,
  654.             1.,
  655.             null,
  656.             null,
  657.             null,
  658.             null
  659.         );

  660.         List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.BackwardEdgeDates (
  661.             dtEffective,
  662.             dtEffective.addTenor (strMaturityTenor),
  663.             strFixedTenor,
  664.             null,
  665.             CompositePeriodBuilder.SHORT_STUB
  666.         );

  667.         List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  668.             dtEffective,
  669.             fri.tenor(),
  670.             strMaturityTenor,
  671.             null
  672.         );

  673.         Stream floatingStream = new Stream (
  674.             CompositePeriodBuilder.FloatingCompositeUnit (
  675.                 lsFloatingStreamEdgeDate,
  676.                 cpsFloating,
  677.                 cfusFloating
  678.             )
  679.         );

  680.         Stream fixedStream = new Stream (
  681.             CompositePeriodBuilder.FixedCompositeUnit (
  682.                 lsFixedStreamEdgeDate,
  683.                 cpsFixed,
  684.                 ucasFixed,
  685.                 cfusFixed
  686.             )
  687.         );

  688.         FixFloatComponent ffc = new FixFloatComponent (
  689.             fixedStream,
  690.             floatingStream,
  691.             null
  692.         );

  693.         ffc.setPrimaryCode ("FixFloat: " + strMaturityTenor);

  694.         return ffc;
  695.     }

  696.     public static final void main (
  697.         final String[] astrArgs)
  698.         throws Exception
  699.     {
  700.         /*
  701.          * Initialize the Credit Analytics Library
  702.          */

  703.         EnvManager.InitEnv (
  704.             "",
  705.             true
  706.         );

  707.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  708.             2015,
  709.             DateUtil.MAY,
  710.             15
  711.         );

  712.         String strCurrency = "USD";
  713.         String strForwardTenor = "3M";

  714.         MergedDiscountForwardCurve dcOvernight = OvernightCurve (
  715.             dtSpot,
  716.             strCurrency,
  717.             "OVERNIGHT INDEX RUN RECONCILIATION"
  718.         );

  719.         ForwardCurve fc3M = MakeForwardCurve (
  720.             dtSpot,
  721.             dcOvernight,
  722.             strForwardTenor
  723.         );

  724.         JulianDate dtEffective = DateUtil.CreateFromYMD (
  725.             2017,
  726.             DateUtil.SEPTEMBER,
  727.             11
  728.         );

  729.         double dblCoupon = 0.026825;
  730.         String strFixedTenor = "6M";
  731.         String strMaturityTenor = "10Y";

  732.         FixFloatComponent ffcSwap = FixFloatSwap (
  733.             dtEffective,
  734.             fc3M.index(),
  735.             strFixedTenor,
  736.             strMaturityTenor,
  737.             dblCoupon
  738.         );

  739.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  740.             dcOvernight,
  741.             fc3M,
  742.             null,
  743.             null,
  744.             null,
  745.             null,
  746.             null,
  747.             null
  748.         );

  749.         Map<String, Double> mapSwap = ffcSwap.value (
  750.             new ValuationParams (
  751.                 dtSpot,
  752.                 dtSpot,
  753.                 strCurrency
  754.             ),
  755.             null,
  756.             mktParams,
  757.             null
  758.         );

  759.         for (Map.Entry<String, Double> me : mapSwap.entrySet())
  760.             System.out.println ("\t" + me.getKey() + " => " + FormatUtil.FormatDouble (me.getValue(), 1, 8, 1.) + " |");

  761.         EnvManager.TerminateEnv();
  762.     }
  763. }