FRAStdCapFloorAnalysis.java

  1. package org.drip.sample.capfloor;

  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.pricer.option.BlackScholesAlgorithm;
  12. import org.drip.product.creator.*;
  13. import org.drip.product.definition.*;
  14. import org.drip.product.fra.FRAStandardCapFloor;
  15. import org.drip.product.params.LastTradingDateSetting;
  16. import org.drip.product.rates.*;
  17. import org.drip.service.env.EnvManager;
  18. import org.drip.spline.basis.PolynomialFunctionSetParams;
  19. import org.drip.spline.stretch.MultiSegmentSequenceBuilder;
  20. import org.drip.state.creator.*;
  21. import org.drip.state.discount.*;
  22. import org.drip.state.forward.ForwardCurve;
  23. import org.drip.state.identifier.*;

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

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

  101. /**
  102.  * <i>FRAStdCapFloorAnalysis</i> contains an analysis if the correlation and volatility impact on a Cap/Floor
  103.  * of the standard FRA.
  104.  *  
  105.  * <br><br>
  106.  *  <ul>
  107.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  108.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  109.  *      <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>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/capfloor/README.md">FRA Standard Cap Floor Valuation</a></li>
  111.  *  </ul>
  112.  * <br><br>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class FRAStdCapFloorAnalysis {

  117.     private static final FixFloatComponent OTCFixFloat (
  118.         final JulianDate dtSpot,
  119.         final String strCurrency,
  120.         final String strMaturityTenor,
  121.         final double dblCoupon)
  122.     {
  123.         FixedFloatSwapConvention ffConv = IBORFixedFloatContainer.ConventionFromJurisdiction (
  124.             strCurrency,
  125.             "ALL",
  126.             strMaturityTenor,
  127.             "MAIN"
  128.         );

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

  137.     private static final FloatFloatComponent OTCFloatFloat (
  138.         final JulianDate dtSpot,
  139.         final String strCurrency,
  140.         final String strDerivedTenor,
  141.         final String strMaturityTenor,
  142.         final double dblBasis)
  143.     {
  144.         FloatFloatSwapConvention ffConv = IBORFloatFloatContainer.ConventionFromJurisdiction (strCurrency);

  145.         return ffConv.createFloatFloatComponent (
  146.             dtSpot,
  147.             strDerivedTenor,
  148.             strMaturityTenor,
  149.             dblBasis,
  150.             1.
  151.         );
  152.     }

  153.     /*
  154.      * Construct the Array of Deposit 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 CalibratableComponent[] DepositInstrumentsFromMaturityDays (
  159.         final JulianDate dtEffective,
  160.         final int[] aiDay,
  161.         final int iNumFuture,
  162.         final String strCurrency)
  163.         throws Exception
  164.     {
  165.         CalibratableComponent[] aCalibComp = new CalibratableComponent[aiDay.length + iNumFuture];

  166.         for (int i = 0; i < aiDay.length; ++i)
  167.             aCalibComp[i] = SingleStreamComponentBuilder.Deposit (
  168.                 dtEffective,
  169.                 dtEffective.addBusDays (
  170.                     aiDay[i],
  171.                     strCurrency
  172.                 ),
  173.                 ForwardLabel.Create (
  174.                     strCurrency,
  175.                     "3M"
  176.                 )
  177.             );

  178.         CalibratableComponent[] aEDF = SingleStreamComponentBuilder.ForwardRateFuturesPack (
  179.             dtEffective,
  180.             iNumFuture,
  181.             strCurrency
  182.         );

  183.         for (int i = aiDay.length; i < aiDay.length + iNumFuture; ++i)
  184.             aCalibComp[i] = aEDF[i - aiDay.length];

  185.         return aCalibComp;
  186.     }

  187.     /*
  188.      * Construct the Array of Swap Instruments from the given set of parameters
  189.      *
  190.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  191.      */

  192.     private static final FixFloatComponent[] SwapInstrumentsFromMaturityTenor (
  193.         final JulianDate dtSpot,
  194.         final String strCurrency,
  195.         final String[] astrMaturityTenor,
  196.         final double[] adblCoupon)
  197.         throws Exception
  198.     {
  199.         FixFloatComponent[] aIRS = new FixFloatComponent[astrMaturityTenor.length];

  200.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  201.             aIRS[i] = OTCFixFloat (
  202.                 dtSpot,
  203.                 strCurrency,
  204.                 astrMaturityTenor[i],
  205.                 adblCoupon[i]
  206.             );

  207.         return aIRS;
  208.     }

  209.     /*
  210.      * Construct the discount curve using the following steps:
  211.      *  - Construct the array of cash instruments and their quotes.
  212.      *  - Construct the array of swap instruments and their quotes.
  213.      *  - Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  214.      *
  215.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  216.      */

  217.     private static final MergedDiscountForwardCurve MakeDC (
  218.         final JulianDate dtSpot,
  219.         final String strCurrency)
  220.         throws Exception
  221.     {
  222.         /*
  223.          * Construct the array of Deposit instruments and their quotes.
  224.          */

  225.         CalibratableComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  226.             dtSpot,
  227.             new int[] {
  228.                 1, 2, 3, 7, 14, 21, 30, 60
  229.             },
  230.             0,
  231.             strCurrency
  232.         );

  233.         double[] adblDepositQuote = new double[] {
  234.             0.01200, 0.01200, 0.01200, 0.01450, 0.01550, 0.01600, 0.01660, 0.01850
  235.         };

  236.         String[] astrDepositManifestMeasure = new String[] {
  237.             "ForwardRate",
  238.             "ForwardRate",
  239.             "ForwardRate",
  240.             "ForwardRate",
  241.             "ForwardRate",
  242.             "ForwardRate",
  243.             "ForwardRate",
  244.             "ForwardRate"
  245.         };

  246.         /*
  247.          * Construct the array of Swap instruments and their quotes.
  248.          */

  249.         double[] adblSwapQuote = new double[] {
  250.             0.02604,    //  4Y
  251.             0.02808,    //  5Y
  252.             0.02983,    //  6Y
  253.             0.03136,    //  7Y
  254.             0.03268,    //  8Y
  255.             0.03383,    //  9Y
  256.             0.03488,    // 10Y
  257.             0.03583,    // 11Y
  258.             0.03668,    // 12Y
  259.             0.03833,    // 15Y
  260.             0.03854,    // 20Y
  261.             0.03672,    // 25Y
  262.             0.03510,    // 30Y
  263.             0.03266,    // 40Y
  264.             0.03145     // 50Y
  265.         };

  266.         String[] astrSwapManifestMeasure = new String[] {
  267.             "SwapRate",    //  4Y
  268.             "SwapRate",    //  5Y
  269.             "SwapRate",    //  6Y
  270.             "SwapRate",    //  7Y
  271.             "SwapRate",    //  8Y
  272.             "SwapRate",    //  9Y
  273.             "SwapRate",    // 10Y
  274.             "SwapRate",    // 11Y
  275.             "SwapRate",    // 12Y
  276.             "SwapRate",    // 15Y
  277.             "SwapRate",    // 20Y
  278.             "SwapRate",    // 25Y
  279.             "SwapRate",    // 30Y
  280.             "SwapRate",    // 40Y
  281.             "SwapRate"     // 50Y
  282.         };

  283.         CalibratableComponent[] aSwapComp = SwapInstrumentsFromMaturityTenor (
  284.             dtSpot,
  285.             strCurrency,
  286.             new java.lang.String[] {
  287.                 "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "40Y", "50Y"
  288.             },
  289.             adblSwapQuote
  290.         );

  291.         /*
  292.          * Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  293.          */

  294.         return ScenarioDiscountCurveBuilder.CubicKLKHyperbolicDFRateShapePreserver (
  295.             "KLK_HYPERBOLIC_SHAPE_TEMPLATE",
  296.             new ValuationParams (
  297.                 dtSpot,
  298.                 dtSpot,
  299.                 "USD"
  300.             ),
  301.             aDepositComp,
  302.             adblDepositQuote,
  303.             astrDepositManifestMeasure,
  304.             aSwapComp,
  305.             adblSwapQuote,
  306.             astrSwapManifestMeasure,
  307.             false
  308.         );
  309.     }

  310.     /*
  311.      * Construct an array of float-float swaps from the corresponding reference (6M) and the derived legs.
  312.      *
  313.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  314.      */

  315.     private static final FloatFloatComponent[] MakexM6MBasisSwap (
  316.         final JulianDate dtSpot,
  317.         final String strCurrency,
  318.         final String[] astrMaturityTenor,
  319.         final int iTenorInMonths)
  320.         throws Exception
  321.     {
  322.         FloatFloatComponent[] aFFC = new FloatFloatComponent[astrMaturityTenor.length];

  323.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  324.             aFFC[i] = OTCFloatFloat (
  325.                 dtSpot,
  326.                 strCurrency,
  327.                 iTenorInMonths + "M",
  328.                 astrMaturityTenor[i],
  329.                 0.
  330.             );

  331.         return aFFC;
  332.     }

  333.     private static final ForwardCurve MakeFC (
  334.         final JulianDate dtSpot,
  335.         final String strCurrency,
  336.         final MergedDiscountForwardCurve dc,
  337.         final int iTenorInMonths,
  338.         final String[] astrxM6MFwdTenor,
  339.         final double[] adblxM6MBasisSwapQuote)
  340.         throws Exception
  341.     {
  342.         /*
  343.          * Construct the 6M-xM float-float basis swap.
  344.          */

  345.         FloatFloatComponent[] aFFC = MakexM6MBasisSwap (
  346.             dtSpot,
  347.             strCurrency,
  348.             astrxM6MFwdTenor,
  349.             iTenorInMonths
  350.         );

  351.         String strBasisTenor = iTenorInMonths + "M";

  352.         ValuationParams valParams = new ValuationParams (
  353.             dtSpot,
  354.             dtSpot,
  355.             strCurrency
  356.         );

  357.         /*
  358.          * Calculate the starting forward rate off of the discount curve.
  359.          */

  360.         double dblStartingFwd = dc.forward (
  361.             dtSpot.julian(),
  362.             dtSpot.addTenor (strBasisTenor).julian()
  363.         );

  364.         /*
  365.          * Set the discount curve based component market parameters.
  366.          */

  367.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  368.             dc,
  369.             null,
  370.             null,
  371.             null,
  372.             null,
  373.             null,
  374.             null
  375.         );

  376.         /*
  377.          * Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  378.          */

  379.         return ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  380.             "QUARTIC_FWD" + strBasisTenor,
  381.             ForwardLabel.Create (
  382.                 strCurrency,
  383.                 strBasisTenor
  384.             ),
  385.             valParams,
  386.             null,
  387.             mktParams,
  388.             null,
  389.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  390.             new PolynomialFunctionSetParams (5),
  391.             aFFC,
  392.             "DerivedParBasisSpread",
  393.             adblxM6MBasisSwapQuote,
  394.             dblStartingFwd
  395.         );
  396.     }

  397.     private static final Map<String, ForwardCurve> MakeFC (
  398.         final JulianDate dt,
  399.         final String strCurrency,
  400.         final MergedDiscountForwardCurve dc)
  401.         throws Exception
  402.     {
  403.         Map<String, ForwardCurve> mapFC = new HashMap<String, ForwardCurve>();

  404.         /*
  405.          * Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  406.          */

  407.         ForwardCurve fc1M = MakeFC (
  408.             dt,
  409.             strCurrency,
  410.             dc,
  411.             1,
  412.             new String[] {
  413.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  414.             },
  415.             new double[] {
  416.                 0.00551,    //  1Y
  417.                 0.00387,    //  2Y
  418.                 0.00298,    //  3Y
  419.                 0.00247,    //  4Y
  420.                 0.00211,    //  5Y
  421.                 0.00185,    //  6Y
  422.                 0.00165,    //  7Y
  423.                 0.00150,    //  8Y
  424.                 0.00137,    //  9Y
  425.                 0.00127,    // 10Y
  426.                 0.00119,    // 11Y
  427.                 0.00112,    // 12Y
  428.                 0.00096,    // 15Y
  429.                 0.00079,    // 20Y
  430.                 0.00069,    // 25Y
  431.                 0.00062     // 30Y
  432.                 }
  433.             );

  434.         mapFC.put (
  435.             "1M",
  436.             fc1M
  437.         );

  438.         /*
  439.          * Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  440.          */

  441.         ForwardCurve fc3M = MakeFC (
  442.             dt,
  443.             strCurrency,
  444.             dc,
  445.             3,
  446.             new String[] {
  447.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  448.             },
  449.             new double[] {
  450.                 0.00186,    //  1Y
  451.                 0.00127,    //  2Y
  452.                 0.00097,    //  3Y
  453.                 0.00080,    //  4Y
  454.                 0.00067,    //  5Y
  455.                 0.00058,    //  6Y
  456.                 0.00051,    //  7Y
  457.                 0.00046,    //  8Y
  458.                 0.00042,    //  9Y
  459.                 0.00038,    // 10Y
  460.                 0.00035,    // 11Y
  461.                 0.00033,    // 12Y
  462.                 0.00028,    // 15Y
  463.                 0.00022,    // 20Y
  464.                 0.00020,    // 25Y
  465.                 0.00018     // 30Y
  466.                 }
  467.             );

  468.         mapFC.put (
  469.             "3M",
  470.             fc3M
  471.         );

  472.         /*
  473.          * Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  474.          */

  475.         ForwardCurve fc12M = MakeFC (
  476.             dt,
  477.             strCurrency,
  478.             dc,
  479.             12,
  480.             new String[] {
  481.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y",
  482.                 "35Y", "40Y" // Extrapolated
  483.             },
  484.             new double[] {
  485.                 -0.00212,    //  1Y
  486.                 -0.00152,    //  2Y
  487.                 -0.00117,    //  3Y
  488.                 -0.00097,    //  4Y
  489.                 -0.00082,    //  5Y
  490.                 -0.00072,    //  6Y
  491.                 -0.00063,    //  7Y
  492.                 -0.00057,    //  8Y
  493.                 -0.00051,    //  9Y
  494.                 -0.00047,    // 10Y
  495.                 -0.00044,    // 11Y
  496.                 -0.00041,    // 12Y
  497.                 -0.00035,    // 15Y
  498.                 -0.00028,    // 20Y
  499.                 -0.00025,    // 25Y
  500.                 -0.00022,    // 30Y
  501.                 -0.00022,    // 35Y Extrapolated
  502.                 -0.00022,    // 40Y Extrapolated
  503.                 }
  504.             );

  505.         mapFC.put (
  506.             "12M",
  507.             fc12M
  508.         );

  509.         return mapFC;
  510.     }

  511.     private static final void SetVolCorrelation (
  512.         final int iValueDate,
  513.         final CurveSurfaceQuoteContainer mktParams,
  514.         final ForwardLabel fri,
  515.         final double dblForwardVol,
  516.         final double dblFundingVol,
  517.         final double dblForwardFundingCorr)
  518.         throws Exception
  519.     {
  520.         FundingLabel fundingLabel = FundingLabel.Standard (fri.currency());

  521.         mktParams.setForwardVolatility (
  522.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  523.                 iValueDate,
  524.                 VolatilityLabel.Standard (fri),
  525.                 fri.currency(),
  526.                 dblForwardVol
  527.             )
  528.         );

  529.         mktParams.setFundingVolatility (
  530.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  531.                 iValueDate,
  532.                 VolatilityLabel.Standard (fundingLabel),
  533.                 fri.currency(),
  534.                 dblFundingVol
  535.             )
  536.         );

  537.         mktParams.setForwardFundingCorrelation (
  538.             fri,
  539.             fundingLabel,
  540.             new FlatUnivariate (dblForwardFundingCorr)
  541.         );
  542.     }

  543.     public static final void main (
  544.         final String[] astrArgs)
  545.         throws Exception
  546.     {
  547.         /*
  548.          * Initialize the Credit Analytics Library
  549.          */

  550.         EnvManager.InitEnv ("");

  551.         double dblStrike = 0.02;
  552.         String strFRATenor = "3M";
  553.         String strCurrency = "USD";
  554.         String strMaturityTenor = "4Y";
  555.         String strManifestMeasure = "QuantoAdjustedParForward";

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

  557.         /*
  558.          * Construct the Discount Curve using its instruments and quotes
  559.          */

  560.         MergedDiscountForwardCurve dc = MakeDC (
  561.             dtToday,
  562.             strCurrency
  563.         );

  564.         Map<String, ForwardCurve> mapFC = MakeFC (
  565.             dtToday,
  566.             strCurrency,
  567.             dc
  568.         );

  569.         ForwardLabel fri = ForwardLabel.Create (
  570.             strCurrency,
  571.             strFRATenor
  572.         );

  573.         JulianDate dtEffective = dtToday.addTenor (strFRATenor);

  574.         ComposableFloatingUnitSetting cfus = new ComposableFloatingUnitSetting (
  575.             strFRATenor,
  576.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_SINGLE,
  577.             null,
  578.             fri,
  579.             CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  580.             0.
  581.         );

  582.         CompositePeriodSetting cps = new CompositePeriodSetting (
  583.             4,
  584.             strFRATenor,
  585.             strCurrency,
  586.             null,
  587.             1.,
  588.             null,
  589.             null,
  590.             null,
  591.             null
  592.         );

  593.         Stream floatStream = new Stream (
  594.             CompositePeriodBuilder.FloatingCompositeUnit (
  595.                 CompositePeriodBuilder.RegularEdgeDates (
  596.                     dtEffective.julian(),
  597.                     strFRATenor,
  598.                     strMaturityTenor,
  599.                     null
  600.                 ),
  601.                 cps,
  602.                 cfus
  603.             )
  604.         );

  605.         FRAStandardCapFloor fraCap = new FRAStandardCapFloor (
  606.             "FRA_CAP",
  607.             floatStream,
  608.             strManifestMeasure,
  609.             true,
  610.             dblStrike,
  611.             new LastTradingDateSetting (
  612.                 LastTradingDateSetting.MID_CURVE_OPTION_QUARTERLY,
  613.                 "",
  614.                 Integer.MIN_VALUE
  615.             ),
  616.             null,
  617.             new BlackScholesAlgorithm()
  618.         );

  619.         FRAStandardCapFloor fraFloor = new FRAStandardCapFloor (
  620.             "FRA_FLOOR",
  621.             floatStream,
  622.             strManifestMeasure,
  623.             false,
  624.             dblStrike,
  625.             new LastTradingDateSetting (
  626.                 LastTradingDateSetting.MID_CURVE_OPTION_QUARTERLY,
  627.                 "",
  628.                 Integer.MIN_VALUE
  629.             ),
  630.             null,
  631.             new BlackScholesAlgorithm()
  632.         );

  633.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  634.             dc,
  635.             mapFC.get (strFRATenor),
  636.             null,
  637.             null,
  638.             null,
  639.             null,
  640.             null,
  641.             null
  642.         );

  643.         ValuationParams valParams = new ValuationParams (
  644.             dtToday,
  645.             dtToday,
  646.             strCurrency
  647.         );

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

  651.         System.out.println ("\tPrinting the Cap/Floor Output in Order (Left -> Right):");

  652.         System.out.println ("\t\tCap Price");

  653.         System.out.println ("\t\tCap Flat Price Vol (%)");

  654.         System.out.println ("\t\tFloor Price");

  655.         System.out.println ("\t\tFloor Flat Price Vol (%)");

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

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

  658.         for (double dblSigmaFwd : adblSigmaFwd) {
  659.             for (double dblSigmaFwd2DomX : adblSigmaFwd2DomX) {
  660.                 for (double dblCorrFwdFwd2DomX : adblCorrFwdFwd2DomX) {
  661.                     SetVolCorrelation (
  662.                         dtToday.julian(),
  663.                         mktParams,
  664.                         fri,
  665.                         dblSigmaFwd,
  666.                         dblSigmaFwd2DomX,
  667.                         dblCorrFwdFwd2DomX
  668.                     );

  669.                     Map<String, Double> mapFRACapOutput = fraCap.value (
  670.                         valParams,
  671.                         null,
  672.                         mktParams,
  673.                         null
  674.                     );

  675.                     Map<String, Double> mapFRAFloorOutput = fraFloor.value (
  676.                         valParams,
  677.                         null,
  678.                         mktParams,
  679.                         null
  680.                     );

  681.                     System.out.println ("\t[" +
  682.                         org.drip.numerical.common.FormatUtil.FormatDouble (dblSigmaFwd, 2, 0, 100.) + "%," +
  683.                         org.drip.numerical.common.FormatUtil.FormatDouble (dblSigmaFwd2DomX, 2, 0, 100.) + "%," +
  684.                         org.drip.numerical.common.FormatUtil.FormatDouble (dblCorrFwdFwd2DomX, 2, 0, 100.) + "%] =" +
  685.                         org.drip.numerical.common.FormatUtil.FormatDouble (mapFRACapOutput.get ("Price"), 1, 4, 1.) + " | " +
  686.                         org.drip.numerical.common.FormatUtil.FormatDouble (mapFRACapOutput.get ("FlatVolatility"), 1, 1, 100.) + "% | " +
  687.                         org.drip.numerical.common.FormatUtil.FormatDouble (mapFRAFloorOutput.get ("Price"), 1, 4, 1.) + " | " +
  688.                         org.drip.numerical.common.FormatUtil.FormatDouble (mapFRAFloorOutput.get ("FlatVolatility"), 1, 1, 100.) + "% || "
  689.                     );
  690.                 }
  691.             }
  692.         }

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

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

  695.         EnvManager.TerminateEnv();
  696.     }
  697. }