FixFloatSwapAnalysis.java

  1. package org.drip.sample.multicurve;

  2. import java.util.*;

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

  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.  * FixFloatSwapAnalysis contains an analysis if the correlation and volatility impact on the fix-float Swap.
  70.  *
  71.  * @author Lakshmi Krishnamurthy
  72.  */

  73. public class FixFloatSwapAnalysis {

  74.     private static final FixFloatComponent OTCFixFloat (
  75.         final JulianDate dtSpot,
  76.         final String strCurrency,
  77.         final String strMaturityTenor,
  78.         final double dblCoupon)
  79.     {
  80.         FixedFloatSwapConvention ffConv = IBORFixedFloatContainer.ConventionFromJurisdiction (
  81.             strCurrency,
  82.             "ALL",
  83.             strMaturityTenor,
  84.             "MAIN"
  85.         );

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

  94.     private static final FloatFloatComponent OTCFloatFloat (
  95.         final JulianDate dtSpot,
  96.         final String strCurrency,
  97.         final String strDerivedTenor,
  98.         final String strMaturityTenor,
  99.         final double dblBasis)
  100.     {
  101.         FloatFloatSwapConvention ffConv = IBORFloatFloatContainer.ConventionFromJurisdiction (strCurrency);

  102.         return ffConv.createFloatFloatComponent (
  103.             dtSpot,
  104.             strDerivedTenor,
  105.             strMaturityTenor,
  106.             dblBasis,
  107.             1.
  108.         );
  109.     }

  110.     /*
  111.      * Construct the Array of Deposit Instruments from the given set of parameters
  112.      *
  113.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  114.      */

  115.     private static final CalibratableComponent[] DepositInstrumentsFromMaturityDays (
  116.         final JulianDate dtEffective,
  117.         final int[] aiDay,
  118.         final int iNumFutures,
  119.         final String strCurrency)
  120.         throws Exception
  121.     {
  122.         CalibratableComponent[] aCalibComp = new CalibratableComponent[aiDay.length + iNumFutures];

  123.         for (int i = 0; i < aiDay.length; ++i)
  124.             aCalibComp[i] = SingleStreamComponentBuilder.Deposit (
  125.                 dtEffective,
  126.                 dtEffective.addBusDays (
  127.                     aiDay[i],
  128.                     strCurrency
  129.                 ),
  130.                 ForwardLabel.Create (
  131.                     strCurrency,
  132.                     "3M"
  133.                 )
  134.             );

  135.         CalibratableComponent[] aEDF = SingleStreamComponentBuilder.ForwardRateFuturesPack (
  136.             dtEffective,
  137.             iNumFutures,
  138.             strCurrency
  139.         );

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

  142.         return aCalibComp;
  143.     }

  144.     /*
  145.      * Construct the Array of Swap Instruments from the given set of parameters
  146.      *
  147.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  148.      */

  149.     private static final CalibratableComponent[] SwapInstrumentsFromMaturityTenor (
  150.         final JulianDate dtSpot,
  151.         final String strCurrency,
  152.         final String[] astrMaturityTenor,
  153.         final double[] adblCoupon)
  154.         throws Exception
  155.     {
  156.         FixFloatComponent[] aIRS = new FixFloatComponent[astrMaturityTenor.length];

  157.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  158.             aIRS[i] = OTCFixFloat (
  159.                 dtSpot,
  160.                 strCurrency,
  161.                 astrMaturityTenor[i],
  162.                 adblCoupon[i]
  163.             );

  164.         return aIRS;
  165.     }

  166.     /*
  167.      * Construct the discount curve using the following steps:
  168.      *  - Construct the array of cash instruments and their quotes.
  169.      *  - Construct the array of swap instruments and their quotes.
  170.      *  - Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  171.      *
  172.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  173.      */

  174.     private static final MergedDiscountForwardCurve MakeDC (
  175.         final JulianDate dtSpot,
  176.         final String strCurrency)
  177.         throws Exception
  178.     {
  179.         /*
  180.          * Construct the array of Deposit instruments and their quotes.
  181.          */

  182.         CalibratableComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  183.             dtSpot,
  184.             new int[] {
  185.                 1, 2, 3, 7, 14, 21, 30, 60
  186.             },
  187.             0,
  188.             strCurrency
  189.         );

  190.         double[] adblDepositQuote = new double[] {
  191.             0.01200, 0.01200, 0.01200, 0.01450, 0.01550, 0.01600, 0.01660, 0.01850
  192.         };

  193.         String[] astrDepositManifestMeasure = new String[] {
  194.             "ForwardRate",
  195.             "ForwardRate",
  196.             "ForwardRate",
  197.             "ForwardRate",
  198.             "ForwardRate",
  199.             "ForwardRate",
  200.             "ForwardRate",
  201.             "ForwardRate"
  202.         };

  203.         /*
  204.          * Construct the array of Swap instruments and their quotes.
  205.          */

  206.         double[] adblSwapQuote = new double[] {
  207.             0.02604,    //  4Y
  208.             0.02808,    //  5Y
  209.             0.02983,    //  6Y
  210.             0.03136,    //  7Y
  211.             0.03268,    //  8Y
  212.             0.03383,    //  9Y
  213.             0.03488,    // 10Y
  214.             0.03583,    // 11Y
  215.             0.03668,    // 12Y
  216.             0.03833,    // 15Y
  217.             0.03854,    // 20Y
  218.             0.03672,    // 25Y
  219.             0.03510,    // 30Y
  220.             0.03266,    // 40Y
  221.             0.03145     // 50Y
  222.         };

  223.         String[] astrSwapManifestMeasure = new String[] {
  224.             "SwapRate",    //  4Y
  225.             "SwapRate",    //  5Y
  226.             "SwapRate",    //  6Y
  227.             "SwapRate",    //  7Y
  228.             "SwapRate",    //  8Y
  229.             "SwapRate",    //  9Y
  230.             "SwapRate",    // 10Y
  231.             "SwapRate",    // 11Y
  232.             "SwapRate",    // 12Y
  233.             "SwapRate",    // 15Y
  234.             "SwapRate",    // 20Y
  235.             "SwapRate",    // 25Y
  236.             "SwapRate",    // 30Y
  237.             "SwapRate",    // 40Y
  238.             "SwapRate"     // 50Y
  239.         };

  240.         CalibratableComponent[] aSwapComp = SwapInstrumentsFromMaturityTenor (
  241.             dtSpot,
  242.             strCurrency,
  243.             new java.lang.String[] {
  244.                 "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "40Y", "50Y"
  245.             },
  246.             adblSwapQuote
  247.         );

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

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

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

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

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

  288.         return aFFC;
  289.     }

  290.     private static final ForwardCurve MakeFC (
  291.         final JulianDate dtSpot,
  292.         final String strCurrency,
  293.         final MergedDiscountForwardCurve dc,
  294.         final int iTenorInMonths,
  295.         final String[] astrxM6MFwdTenor,
  296.         final double[] adblxM6MBasisSwapQuote)
  297.         throws Exception
  298.     {
  299.         /*
  300.          * Construct the 6M-xM float-float basis swap.
  301.          */

  302.         FloatFloatComponent[] aFFC = MakexM6MBasisSwap (
  303.             dtSpot,
  304.             strCurrency,
  305.             astrxM6MFwdTenor,
  306.             iTenorInMonths
  307.         );

  308.         String strBasisTenor = iTenorInMonths + "M";

  309.         ValuationParams valParams = new ValuationParams (
  310.             dtSpot,
  311.             dtSpot,
  312.             strCurrency
  313.         );

  314.         /*
  315.          * Calculate the starting forward rate off of the discount curve.
  316.          */

  317.         double dblStartingFwd = dc.forward (
  318.             dtSpot.julian(),
  319.             dtSpot.addTenor (strBasisTenor).julian()
  320.         );

  321.         /*
  322.          * Set the discount curve based component market parameters.
  323.          */

  324.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  325.             dc,
  326.             null,
  327.             null,
  328.             null,
  329.             null,
  330.             null,
  331.             null
  332.         );

  333.         /*
  334.          * Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  335.          */

  336.         return ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  337.             "QUARTIC_FWD" + strBasisTenor,
  338.             ForwardLabel.Create (
  339.                 strCurrency,
  340.                 strBasisTenor
  341.             ),
  342.             valParams,
  343.             null,
  344.             mktParams,
  345.             null,
  346.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  347.             new PolynomialFunctionSetParams (5),
  348.             aFFC,
  349.             "DerivedParBasisSpread",
  350.             adblxM6MBasisSwapQuote,
  351.             dblStartingFwd
  352.         );
  353.     }

  354.     private static final Map<String, ForwardCurve> MakeFC (
  355.         final JulianDate dt,
  356.         final String strCurrency,
  357.         final MergedDiscountForwardCurve dc)
  358.         throws Exception
  359.     {
  360.         Map<String, ForwardCurve> mapFC = new HashMap<String, ForwardCurve>();

  361.         /*
  362.          * Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  363.          */

  364.         ForwardCurve fc1M = MakeFC (
  365.             dt,
  366.             strCurrency,
  367.             dc,
  368.             1,
  369.             new String[] {
  370.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  371.             },
  372.             new double[] {
  373.                 0.00551,    //  1Y
  374.                 0.00387,    //  2Y
  375.                 0.00298,    //  3Y
  376.                 0.00247,    //  4Y
  377.                 0.00211,    //  5Y
  378.                 0.00185,    //  6Y
  379.                 0.00165,    //  7Y
  380.                 0.00150,    //  8Y
  381.                 0.00137,    //  9Y
  382.                 0.00127,    // 10Y
  383.                 0.00119,    // 11Y
  384.                 0.00112,    // 12Y
  385.                 0.00096,    // 15Y
  386.                 0.00079,    // 20Y
  387.                 0.00069,    // 25Y
  388.                 0.00062     // 30Y
  389.                 }
  390.             );

  391.         mapFC.put (
  392.             "1M",
  393.             fc1M
  394.         );

  395.         /*
  396.          * Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  397.          */

  398.         ForwardCurve fc3M = MakeFC (
  399.             dt,
  400.             strCurrency,
  401.             dc,
  402.             3,
  403.             new String[] {
  404.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  405.             },
  406.             new double[] {
  407.                 0.00186,    //  1Y
  408.                 0.00127,    //  2Y
  409.                 0.00097,    //  3Y
  410.                 0.00080,    //  4Y
  411.                 0.00067,    //  5Y
  412.                 0.00058,    //  6Y
  413.                 0.00051,    //  7Y
  414.                 0.00046,    //  8Y
  415.                 0.00042,    //  9Y
  416.                 0.00038,    // 10Y
  417.                 0.00035,    // 11Y
  418.                 0.00033,    // 12Y
  419.                 0.00028,    // 15Y
  420.                 0.00022,    // 20Y
  421.                 0.00020,    // 25Y
  422.                 0.00018     // 30Y
  423.                 }
  424.             );

  425.         mapFC.put (
  426.             "3M",
  427.             fc3M
  428.         );

  429.         /*
  430.          * Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  431.          */

  432.         ForwardCurve fc12M = MakeFC (
  433.             dt,
  434.             strCurrency,
  435.             dc,
  436.             12,
  437.             new String[] {
  438.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y",
  439.                 "35Y", "40Y" // Extrapolated
  440.             },
  441.             new double[] {
  442.                 -0.00212,    //  1Y
  443.                 -0.00152,    //  2Y
  444.                 -0.00117,    //  3Y
  445.                 -0.00097,    //  4Y
  446.                 -0.00082,    //  5Y
  447.                 -0.00072,    //  6Y
  448.                 -0.00063,    //  7Y
  449.                 -0.00057,    //  8Y
  450.                 -0.00051,    //  9Y
  451.                 -0.00047,    // 10Y
  452.                 -0.00044,    // 11Y
  453.                 -0.00041,    // 12Y
  454.                 -0.00035,    // 15Y
  455.                 -0.00028,    // 20Y
  456.                 -0.00025,    // 25Y
  457.                 -0.00022,    // 30Y
  458.                 -0.00022,    // 35Y Extrapolated
  459.                 -0.00022,    // 40Y Extrapolated
  460.                 }
  461.             );

  462.         mapFC.put (
  463.             "12M",
  464.             fc12M
  465.         );

  466.         return mapFC;
  467.     }

  468.     private static final FixFloatComponent CreateIRS (
  469.         final JulianDate dtEffective,
  470.         final String strMaturityTenor,
  471.         final ForwardLabel fri,
  472.         final double dblCoupon,
  473.         final String strCurrency)
  474.         throws Exception
  475.     {
  476.         JulianDate dtMaturity = dtEffective.addTenor (strMaturityTenor);

  477.         int iTenorInMonths = Helper.TenorToMonths (fri.tenor());

  478.         UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  479.             2,
  480.             "Act/360",
  481.             false,
  482.             "Act/360",
  483.             false,
  484.             strCurrency,
  485.             true,
  486.             CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  487.         );

  488.         ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  489.             fri.tenor(),
  490.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  491.             null,
  492.             fri,
  493.             CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  494.             0.
  495.         );

  496.         ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  497.             "6M",
  498.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  499.             null,
  500.             dblCoupon,
  501.             0.,
  502.             strCurrency
  503.         );

  504.         CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  505.             12 / iTenorInMonths,
  506.             fri.tenor(),
  507.             strCurrency,
  508.             null,
  509.             -1.,
  510.             null,
  511.             null,
  512.             null,
  513.             null
  514.         );

  515.         CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  516.             2,
  517.             "6M",
  518.             strCurrency,
  519.             null,
  520.             1.,
  521.             null,
  522.             null,
  523.             null,
  524.             null
  525.         );

  526.         CashSettleParams csp = new CashSettleParams (
  527.             0,
  528.             strCurrency,
  529.             0
  530.         );

  531.         List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  532.             dtEffective,
  533.             "6M",
  534.             strMaturityTenor,
  535.             null
  536.         );

  537.         List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  538.             dtEffective,
  539.             fri.tenor(),
  540.             strMaturityTenor,
  541.             null
  542.         );

  543.         Stream floatingStream = new Stream (
  544.             CompositePeriodBuilder.FloatingCompositeUnit (
  545.                 lsFloatingStreamEdgeDate,
  546.                 cpsFloating,
  547.                 cfusFloating
  548.             )
  549.         );

  550.         Stream fixedStream = new Stream (
  551.             CompositePeriodBuilder.FixedCompositeUnit (
  552.                 lsFixedStreamEdgeDate,
  553.                 cpsFixed,
  554.                 ucasFixed,
  555.                 cfusFixed
  556.             )
  557.         );

  558.         FixFloatComponent irs = new FixFloatComponent (
  559.             fixedStream,
  560.             floatingStream,
  561.             csp
  562.         );

  563.         irs.setPrimaryCode ("IRS." + dtMaturity.toString() + "." + strCurrency);

  564.         return irs;
  565.     }

  566.     private static final double RunWithVolCorrelation (
  567.         final FixFloatComponent irs,
  568.         final ValuationParams valParams,
  569.         final CurveSurfaceQuoteContainer mktParams,
  570.         final ForwardLabel fri,
  571.         final double dblBaselineSwapRate,
  572.         final double dblForwardVol,
  573.         final double dblFundingVol,
  574.         final double dblForwardFundingCorr)
  575.         throws Exception
  576.     {
  577.         FundingLabel fundingLabel = FundingLabel.Standard (fri.currency());

  578.         mktParams.setForwardVolatility (
  579.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  580.                 valParams.valueDate(),
  581.                 VolatilityLabel.Standard (fri),
  582.                 fri.currency(),
  583.                 dblForwardVol
  584.             )
  585.         );

  586.         mktParams.setFundingVolatility (
  587.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  588.                 valParams.valueDate(),
  589.                 VolatilityLabel.Standard (fundingLabel),
  590.                 fri.currency(),
  591.                 dblFundingVol
  592.             )
  593.         );

  594.         mktParams.setForwardFundingCorrelation (
  595.             fri,
  596.             fundingLabel,
  597.             new FlatUnivariate (dblForwardFundingCorr)
  598.         );

  599.         Map<String, Double> mapIRSOutput = irs.value (
  600.             valParams,
  601.             null,
  602.             mktParams,
  603.             null
  604.         );

  605.         double dblSwapRate = mapIRSOutput.get ("SwapRate");

  606.         System.out.println ("\t[" +
  607.             org.drip.numerical.common.FormatUtil.FormatDouble (dblForwardVol, 2, 0, 100.) + "%," +
  608.             org.drip.numerical.common.FormatUtil.FormatDouble (dblFundingVol, 2, 0, 100.) + "%," +
  609.             org.drip.numerical.common.FormatUtil.FormatDouble (dblForwardFundingCorr, 2, 0, 100.) + "%] =" +
  610.             org.drip.numerical.common.FormatUtil.FormatDouble (dblSwapRate, 1, 4, 100.) + "% | " +
  611.             org.drip.numerical.common.FormatUtil.FormatDouble (dblSwapRate - dblBaselineSwapRate, 1, 0, 10000.));

  612.         return dblSwapRate;
  613.     }

  614.     public static final void main (
  615.         final String[] astrArgs)
  616.         throws Exception
  617.     {
  618.         /*
  619.          * Initialize the Credit Analytics Library
  620.          */

  621.         EnvManager.InitEnv ("");

  622.         String strTenor = "3M";
  623.         String strCurrency = "USD";

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

  625.         /*
  626.          * Construct the Discount Curve using its instruments and quotes
  627.          */

  628.         MergedDiscountForwardCurve dc = MakeDC (
  629.             dtToday,
  630.             strCurrency
  631.         );

  632.         Map<String, ForwardCurve> mapFC = MakeFC (
  633.             dtToday,
  634.             strCurrency,
  635.             dc
  636.         );

  637.         ForwardLabel fri = ForwardLabel.Create (
  638.             strCurrency,
  639.             strTenor
  640.         );

  641.         FixFloatComponent irs = CreateIRS (
  642.             dtToday.addTenor (strTenor),
  643.             "5Y",
  644.             fri,
  645.             0.05,
  646.             strCurrency
  647.         );

  648.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  649.             dc,
  650.             mapFC.get (strTenor),
  651.             null,
  652.             null,
  653.             null,
  654.             null,
  655.             null,
  656.             null
  657.         );

  658.         ValuationParams valParams = new ValuationParams (
  659.             dtToday,
  660.             dtToday,
  661.             strCurrency
  662.         );

  663.         double[] adblSigmaFwd = new double[] {0.1, 0.2, 0.3, 0.4, 0.5};
  664.         double[] adblSigmaFwd2DomX = new double[] {0.10, 0.15, 0.20, 0.25, 0.30};
  665.         double[] adblCorrFwdFwd2DomX = new double[] {-0.99, -0.50, 0.00, 0.50, 0.99};

  666.         System.out.println ("\tPrinting the IRS Output in Order (Left -> Right):");

  667.         System.out.println ("\t\tParSwapRate (%)");

  668.         System.out.println ("\t\tDifference (bp)");

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

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

  671.         double dblBaselineSwapRate = RunWithVolCorrelation (
  672.             irs,
  673.             valParams,
  674.             mktParams,
  675.             fri,
  676.             0.,
  677.             0.,
  678.             0.,
  679.             0.
  680.         );

  681.         for (double dblSigmaFwd : adblSigmaFwd) {
  682.             for (double dblSigmaFwd2DomX : adblSigmaFwd2DomX) {
  683.                 for (double dblCorrFwdFwd2DomX : adblCorrFwdFwd2DomX)
  684.                     RunWithVolCorrelation (
  685.                         irs,
  686.                         valParams,
  687.                         mktParams,
  688.                         fri,
  689.                         dblBaselineSwapRate,
  690.                         dblSigmaFwd,
  691.                         dblSigmaFwd2DomX,
  692.                         dblCorrFwdFwd2DomX
  693.                     );
  694.             }
  695.         }
  696.     }
  697. }