MultiCurvePayerReceiver.java

  1. package org.drip.sample.fixfloatoption;

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

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

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

  89. /**
  90.  * <i>MultiCurvePayerReceiver</i> contains the demonstration of the Multi-Curve Payer/Receiver Fix-Float IRS
  91.  * European Option Sample.
  92.  *  
  93.  * <br><br>
  94.  *  <ul>
  95.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  96.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  97.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  98.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/fixfloatoption/README.md">Fix Float Swap European Option Analytics</a></li>
  99.  *  </ul>
  100.  * <br><br>
  101.  *
  102.  * @author Lakshmi Krishnamurthy
  103.  */

  104. public class MultiCurvePayerReceiver {

  105.     private static final FixFloatComponent OTCFixFloat (
  106.         final JulianDate dtSpot,
  107.         final String strCurrency,
  108.         final String strMaturityTenor,
  109.         final double dblCoupon)
  110.     {
  111.         FixedFloatSwapConvention ffConv = IBORFixedFloatContainer.ConventionFromJurisdiction (
  112.             strCurrency,
  113.             "ALL",
  114.             strMaturityTenor,
  115.             "MAIN"
  116.         );

  117.         return ffConv.createFixFloatComponent (
  118.             dtSpot,
  119.             strMaturityTenor,
  120.             dblCoupon,
  121.             0.,
  122.             1.
  123.         );
  124.     }

  125.     private static final FloatFloatComponent OTCFloatFloat (
  126.         final JulianDate dtSpot,
  127.         final String strCurrency,
  128.         final String strDerivedTenor,
  129.         final String strMaturityTenor,
  130.         final double dblBasis)
  131.     {
  132.         FloatFloatSwapConvention ffConv = IBORFloatFloatContainer.ConventionFromJurisdiction (strCurrency);

  133.         return ffConv.createFloatFloatComponent (
  134.             dtSpot,
  135.             strDerivedTenor,
  136.             strMaturityTenor,
  137.             dblBasis,
  138.             1.
  139.         );
  140.     }

  141.     /*
  142.      * Construct the Array of Deposit Instruments from the given set of parameters
  143.      *
  144.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  145.      */

  146.     private static final CalibratableComponent[] DepositInstrumentsFromMaturityDays (
  147.         final JulianDate dtEffective,
  148.         final int[] aiDay,
  149.         final int iNumFutures,
  150.         final String strCurrency)
  151.         throws Exception
  152.     {
  153.         CalibratableComponent[] aCalibComp = new CalibratableComponent[aiDay.length + iNumFutures];

  154.         for (int i = 0; i < aiDay.length; ++i)
  155.             aCalibComp[i] = SingleStreamComponentBuilder.Deposit (
  156.                 dtEffective,
  157.                 dtEffective.addBusDays (
  158.                     aiDay[i],
  159.                     strCurrency
  160.                 ),
  161.                 ForwardLabel.Create (
  162.                     strCurrency,
  163.                     "3M"
  164.                 )
  165.             );

  166.         CalibratableComponent[] aEDF = SingleStreamComponentBuilder.ForwardRateFuturesPack (
  167.             dtEffective,
  168.             iNumFutures,
  169.             strCurrency
  170.         );

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

  173.         return aCalibComp;
  174.     }

  175.     /*
  176.      * Construct the Array of Swap Instruments from the given set of parameters
  177.      *
  178.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  179.      */

  180.     private static final CalibratableComponent[] SwapInstrumentsFromMaturityTenor (
  181.         final JulianDate dtSpot,
  182.         final String strCurrency,
  183.         final String[] astrMaturityTenor,
  184.         final double[] adblCoupon)
  185.         throws Exception
  186.     {
  187.         FixFloatComponent[] aIRS = new FixFloatComponent[astrMaturityTenor.length];

  188.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  189.             aIRS[i] = OTCFixFloat (
  190.                 dtSpot,
  191.                 strCurrency,
  192.                 astrMaturityTenor[i],
  193.                 adblCoupon[i]
  194.             );

  195.         return aIRS;
  196.     }

  197.     /*
  198.      * Construct the discount curve using the following steps:
  199.      *  - Construct the array of cash instruments and their quotes.
  200.      *  - Construct the array of swap instruments and their quotes.
  201.      *  - Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  202.      *
  203.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  204.      */

  205.     private static final MergedDiscountForwardCurve MakeDC (
  206.         final JulianDate dtSpot,
  207.         final String strCurrency)
  208.         throws Exception
  209.     {
  210.         /*
  211.          * Construct the array of Deposit instruments and their quotes.
  212.          */

  213.         CalibratableComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
  214.             dtSpot,
  215.             new int[] {
  216.                 1, 2, 3, 7, 14, 21, 30, 60
  217.             },
  218.             0,
  219.             strCurrency
  220.         );

  221.         double[] adblDepositQuote = new double[] {
  222.             0.01200, 0.01200, 0.01200, 0.01450, 0.01550, 0.01600, 0.01660, 0.01850
  223.         };

  224.         String[] astrDepositManifestMeasure = new String[] {
  225.             "ForwardRate",
  226.             "ForwardRate",
  227.             "ForwardRate",
  228.             "ForwardRate",
  229.             "ForwardRate",
  230.             "ForwardRate",
  231.             "ForwardRate",
  232.             "ForwardRate"
  233.         };

  234.         /*
  235.          * Construct the array of Swap instruments and their quotes.
  236.          */

  237.         double[] adblSwapQuote = new double[] {
  238.             0.02604,    //  4Y
  239.             0.02808,    //  5Y
  240.             0.02983,    //  6Y
  241.             0.03136,    //  7Y
  242.             0.03268,    //  8Y
  243.             0.03383,    //  9Y
  244.             0.03488,    // 10Y
  245.             0.03583,    // 11Y
  246.             0.03668,    // 12Y
  247.             0.03833,    // 15Y
  248.             0.03854,    // 20Y
  249.             0.03672,    // 25Y
  250.             0.03510,    // 30Y
  251.             0.03266,    // 40Y
  252.             0.03145     // 50Y
  253.         };

  254.         String[] astrSwapManifestMeasure = new String[] {
  255.             "SwapRate",    //  4Y
  256.             "SwapRate",    //  5Y
  257.             "SwapRate",    //  6Y
  258.             "SwapRate",    //  7Y
  259.             "SwapRate",    //  8Y
  260.             "SwapRate",    //  9Y
  261.             "SwapRate",    // 10Y
  262.             "SwapRate",    // 11Y
  263.             "SwapRate",    // 12Y
  264.             "SwapRate",    // 15Y
  265.             "SwapRate",    // 20Y
  266.             "SwapRate",    // 25Y
  267.             "SwapRate",    // 30Y
  268.             "SwapRate",    // 40Y
  269.             "SwapRate"     // 50Y
  270.         };

  271.         CalibratableComponent[] aSwapComp = SwapInstrumentsFromMaturityTenor (
  272.             dtSpot,
  273.             strCurrency,
  274.             new java.lang.String[] {
  275.                 "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "40Y", "50Y"
  276.             },
  277.             adblSwapQuote
  278.         );

  279.         /*
  280.          * Construct a shape preserving and smoothing KLK Hyperbolic Spline from the cash/swap instruments.
  281.          */

  282.         return ScenarioDiscountCurveBuilder.CubicKLKHyperbolicDFRateShapePreserver (
  283.             "KLK_HYPERBOLIC_SHAPE_TEMPLATE",
  284.             new ValuationParams (
  285.                 dtSpot,
  286.                 dtSpot,
  287.                 "USD"
  288.             ),
  289.             aDepositComp,
  290.             adblDepositQuote,
  291.             astrDepositManifestMeasure,
  292.             aSwapComp,
  293.             adblSwapQuote,
  294.             astrSwapManifestMeasure,
  295.             false
  296.         );
  297.     }

  298.     /*
  299.      * Construct an array of float-float swaps from the corresponding reference (6M) and the derived legs.
  300.      *
  301.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  302.      */

  303.     private static final FloatFloatComponent[] MakexM6MBasisSwap (
  304.         final JulianDate dtSpot,
  305.         final String strCurrency,
  306.         final String[] astrMaturityTenor,
  307.         final int iTenorInMonths)
  308.         throws Exception
  309.     {
  310.         FloatFloatComponent[] aFFC = new FloatFloatComponent[astrMaturityTenor.length];

  311.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  312.             aFFC[i] = OTCFloatFloat (
  313.                 dtSpot,
  314.                 strCurrency,
  315.                 iTenorInMonths + "M",
  316.                 astrMaturityTenor[i],
  317.                 0.
  318.             );

  319.         return aFFC;
  320.     }

  321.     private static final ForwardCurve MakeFC (
  322.         final JulianDate dtSpot,
  323.         final String strCurrency,
  324.         final MergedDiscountForwardCurve dc,
  325.         final int iTenorInMonths,
  326.         final String[] astrxM6MFwdTenor,
  327.         final double[] adblxM6MBasisSwapQuote)
  328.         throws Exception
  329.     {
  330.         /*
  331.          * Construct the 6M-xM float-float basis swap.
  332.          */

  333.         FloatFloatComponent[] aFFC = MakexM6MBasisSwap (
  334.             dtSpot,
  335.             strCurrency,
  336.             astrxM6MFwdTenor,
  337.             iTenorInMonths
  338.         );

  339.         String strBasisTenor = iTenorInMonths + "M";

  340.         ValuationParams valParams = new ValuationParams (
  341.             dtSpot,
  342.             dtSpot,
  343.             strCurrency
  344.         );

  345.         /*
  346.          * Calculate the starting forward rate off of the discount curve.
  347.          */

  348.         double dblStartingFwd = dc.forward (
  349.             dtSpot.julian(),
  350.             dtSpot.addTenor (strBasisTenor).julian()
  351.         );

  352.         /*
  353.          * Set the discount curve based component market parameters.
  354.          */

  355.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  356.             dc,
  357.             null,
  358.             null,
  359.             null,
  360.             null,
  361.             null,
  362.             null
  363.         );

  364.         /*
  365.          * Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  366.          */

  367.         return ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  368.             "QUARTIC_FWD" + strBasisTenor,
  369.             ForwardLabel.Create (
  370.                 strCurrency,
  371.                 strBasisTenor
  372.             ),
  373.             valParams,
  374.             null,
  375.             mktParams,
  376.             null,
  377.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  378.             new PolynomialFunctionSetParams (5),
  379.             aFFC,
  380.             "DerivedParBasisSpread",
  381.             adblxM6MBasisSwapQuote,
  382.             dblStartingFwd
  383.         );
  384.     }

  385.     private static final Map<String, ForwardCurve> MakeFC (
  386.         final JulianDate dt,
  387.         final String strCurrency,
  388.         final MergedDiscountForwardCurve dc)
  389.         throws Exception
  390.     {
  391.         Map<String, ForwardCurve> mapFC = new HashMap<String, ForwardCurve> ();

  392.         /*
  393.          * Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  394.          */

  395.         ForwardCurve fc1M = MakeFC (
  396.             dt,
  397.             strCurrency,
  398.             dc,
  399.             1,
  400.             new String[] {
  401.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  402.             },
  403.             new double[] {
  404.                 0.00551,    //  1Y
  405.                 0.00387,    //  2Y
  406.                 0.00298,    //  3Y
  407.                 0.00247,    //  4Y
  408.                 0.00211,    //  5Y
  409.                 0.00185,    //  6Y
  410.                 0.00165,    //  7Y
  411.                 0.00150,    //  8Y
  412.                 0.00137,    //  9Y
  413.                 0.00127,    // 10Y
  414.                 0.00119,    // 11Y
  415.                 0.00112,    // 12Y
  416.                 0.00096,    // 15Y
  417.                 0.00079,    // 20Y
  418.                 0.00069,    // 25Y
  419.                 0.00062     // 30Y
  420.                 }
  421.             );

  422.         mapFC.put (
  423.             "1M",
  424.             fc1M
  425.         );

  426.         /*
  427.          * Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  428.          */

  429.         ForwardCurve fc3M = MakeFC (
  430.             dt,
  431.             strCurrency,
  432.             dc,
  433.             3,
  434.             new String[] {
  435.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  436.             },
  437.             new double[] {
  438.                 0.00186,    //  1Y
  439.                 0.00127,    //  2Y
  440.                 0.00097,    //  3Y
  441.                 0.00080,    //  4Y
  442.                 0.00067,    //  5Y
  443.                 0.00058,    //  6Y
  444.                 0.00051,    //  7Y
  445.                 0.00046,    //  8Y
  446.                 0.00042,    //  9Y
  447.                 0.00038,    // 10Y
  448.                 0.00035,    // 11Y
  449.                 0.00033,    // 12Y
  450.                 0.00028,    // 15Y
  451.                 0.00022,    // 20Y
  452.                 0.00020,    // 25Y
  453.                 0.00018     // 30Y
  454.                 }
  455.             );

  456.         mapFC.put (
  457.             "3M",
  458.             fc3M
  459.         );

  460.         /*
  461.          * Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  462.          */

  463.         ForwardCurve fc12M = MakeFC (
  464.             dt,
  465.             strCurrency,
  466.             dc,
  467.             12,
  468.             new String[] {
  469.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y",
  470.                 "35Y", "40Y" // Extrapolated
  471.             },
  472.             new double[] {
  473.                 -0.00212,    //  1Y
  474.                 -0.00152,    //  2Y
  475.                 -0.00117,    //  3Y
  476.                 -0.00097,    //  4Y
  477.                 -0.00082,    //  5Y
  478.                 -0.00072,    //  6Y
  479.                 -0.00063,    //  7Y
  480.                 -0.00057,    //  8Y
  481.                 -0.00051,    //  9Y
  482.                 -0.00047,    // 10Y
  483.                 -0.00044,    // 11Y
  484.                 -0.00041,    // 12Y
  485.                 -0.00035,    // 15Y
  486.                 -0.00028,    // 20Y
  487.                 -0.00025,    // 25Y
  488.                 -0.00022,    // 30Y
  489.                 -0.00022,    // 35Y Extrapolated
  490.                 -0.00022,    // 40Y Extrapolated
  491.                 }
  492.             );

  493.         mapFC.put (
  494.             "12M",
  495.             fc12M
  496.         );

  497.         return mapFC;
  498.     }

  499.     private static final FixFloatComponent CreateSTIR (
  500.         final JulianDate dtEffective,
  501.         final String strMaturityTenor,
  502.         final ForwardLabel fri,
  503.         final double dblCoupon,
  504.         final String strCurrency)
  505.         throws Exception
  506.     {
  507.         JulianDate dtMaturity = dtEffective.addTenor (strMaturityTenor);

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

  509.         UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  510.             2,
  511.             "Act/360",
  512.             false,
  513.             "Act/360",
  514.             false,
  515.             strCurrency,
  516.             true,
  517.             CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  518.         );

  519.         ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  520.             fri.tenor(),
  521.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  522.             null,
  523.             fri,
  524.             CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  525.             0.
  526.         );

  527.         ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  528.             "6M",
  529.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  530.             null,
  531.             dblCoupon,
  532.             0.,
  533.             strCurrency
  534.         );

  535.         CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  536.             12 / iTenorInMonths,
  537.             fri.tenor(),
  538.             strCurrency,
  539.             null,
  540.             -1.,
  541.             null,
  542.             null,
  543.             null,
  544.             null
  545.         );

  546.         CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  547.             2,
  548.             "6M",
  549.             strCurrency,
  550.             null,
  551.             1.,
  552.             null,
  553.             null,
  554.             null,
  555.             null
  556.         );

  557.         CashSettleParams csp = new CashSettleParams (
  558.             0,
  559.             strCurrency,
  560.             0
  561.         );

  562.         List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  563.             dtEffective,
  564.             "6M",
  565.             strMaturityTenor,
  566.             null
  567.         );

  568.         List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  569.             dtEffective,
  570.             fri.tenor(),
  571.             strMaturityTenor,
  572.             null
  573.         );

  574.         Stream floatingStream = new Stream (
  575.             CompositePeriodBuilder.FloatingCompositeUnit (
  576.                 lsFloatingStreamEdgeDate,
  577.                 cpsFloating,
  578.                 cfusFloating
  579.             )
  580.         );

  581.         Stream fixedStream = new Stream (
  582.             CompositePeriodBuilder.FixedCompositeUnit (
  583.                 lsFixedStreamEdgeDate,
  584.                 cpsFixed,
  585.                 ucasFixed,
  586.                 cfusFixed
  587.             )
  588.         );

  589.         FixFloatComponent irs = new FixFloatComponent (
  590.             fixedStream,
  591.             floatingStream,
  592.             csp
  593.         );

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

  595.         return irs;
  596.     }

  597.     public static final void main (
  598.         final String[] astrArgs)
  599.         throws Exception
  600.     {
  601.         /*
  602.          * Initialize the Credit Analytics Library
  603.          */

  604.         EnvManager.InitEnv ("");

  605.         String strTenor = "3M";
  606.         String strCurrency = "GBP";
  607.         String strManifestMeasure = "SwapRate";
  608.         double dblCustomMetricVolatility = 0.4;
  609.         double dblForwardVolatility = 0.3;
  610.         double dblFundingVolatility = 0.1;
  611.         double dblForwardFundingCorr = 0.2;

  612.         JulianDate dtToday = DateUtil.Today().addTenorAndAdjust (
  613.             "0D",
  614.             strCurrency
  615.         );

  616.         /*
  617.          * Construct the Discount Curve using its instruments and quotes
  618.          */

  619.         MergedDiscountForwardCurve dc = MakeDC (
  620.             dtToday,
  621.             strCurrency
  622.         );

  623.         Map<String, ForwardCurve> mapFC = MakeFC (
  624.             dtToday,
  625.             strCurrency,
  626.             dc
  627.         );

  628.         ForwardLabel fri = ForwardLabel.Create (
  629.             strCurrency,
  630.             strTenor
  631.         );

  632.         JulianDate dtForward = dtToday.addTenor (strTenor);

  633.         FixFloatComponent stir = CreateSTIR (
  634.             dtForward,
  635.             "5Y",
  636.             fri,
  637.             0.05,
  638.             strCurrency
  639.         );

  640.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  641.             dc,
  642.             mapFC.get (strTenor),
  643.             null,
  644.             null,
  645.             null,
  646.             null,
  647.             null,
  648.             null
  649.         );

  650.         ValuationParams valParams = new ValuationParams (
  651.             dtToday,
  652.             dtToday,
  653.             strCurrency
  654.         );

  655.         FundingLabel fundingLabel = FundingLabel.Standard (strCurrency);

  656.         mktParams.setCustomVolatility (
  657.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  658.                 dtToday.julian(),
  659.                 VolatilityLabel.Standard (CustomLabel.Standard (stir.name() + "_" + strManifestMeasure)),
  660.                 strCurrency,
  661.                 dblCustomMetricVolatility
  662.             )
  663.         );

  664.         mktParams.setFundingVolatility (
  665.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  666.                 dtToday.julian(),
  667.                 VolatilityLabel.Standard (fundingLabel),
  668.                 strCurrency,
  669.                 dblFundingVolatility
  670.             )
  671.         );

  672.         mktParams.setForwardVolatility (
  673.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  674.                 dtToday.julian(),
  675.                 VolatilityLabel.Standard (fri),
  676.                 strCurrency,
  677.                 dblForwardVolatility
  678.             )
  679.         );

  680.         mktParams.setForwardFundingCorrelation (
  681.             fri,
  682.             fundingLabel,
  683.             new FlatUnivariate (dblForwardFundingCorr)
  684.         );

  685.         Map<String, Double> mapSTIROutput = stir.value (
  686.             valParams,
  687.             null,
  688.             mktParams,
  689.             null
  690.         );

  691.         double dblStrike = 1.01 * mapSTIROutput.get (strManifestMeasure);

  692.         FixFloatEuropeanOption stirReceiver = new FixFloatEuropeanOption (
  693.             stir.name() + "::RECEIVER_OPT",
  694.             stir,
  695.             strManifestMeasure,
  696.             true,
  697.             dblStrike,
  698.             1.,
  699.             new LastTradingDateSetting (
  700.                 LastTradingDateSetting.MID_CURVE_OPTION_QUARTERLY,
  701.                 "",
  702.                 Integer.MIN_VALUE
  703.             ),
  704.             null
  705.         );

  706.         Map<String, Double> mapSTIRReceiverOutput = stirReceiver.value (
  707.             valParams,
  708.             null,
  709.             mktParams,
  710.             null
  711.         );

  712.         for (Map.Entry<String, Double> me : mapSTIRReceiverOutput.entrySet())
  713.             System.out.println ("\t" + me.getKey() + " => " + me.getValue());

  714.         System.out.println ("\n------------------------------------------------------------------");

  715.         System.out.println ("------------------------------------------------------------------\n");

  716.         FixFloatEuropeanOption stirPayer = new FixFloatEuropeanOption (
  717.             stir.name() + "::PAYER_OPT",
  718.             stir,
  719.             strManifestMeasure,
  720.             false,
  721.             dblStrike,
  722.             1.,
  723.             new LastTradingDateSetting (
  724.                 LastTradingDateSetting.MID_CURVE_OPTION_QUARTERLY,
  725.                 "",
  726.                 Integer.MIN_VALUE
  727.             ),
  728.             null
  729.         );

  730.         Map<String, Double> mapSTIRPayerOutput = stirPayer.value (
  731.             valParams,
  732.             null,
  733.             mktParams,
  734.             null
  735.         );

  736.         for (Map.Entry<String, Double> me : mapSTIRPayerOutput.entrySet())
  737.             System.out.println ("\t" + me.getKey() + " => " + me.getValue());

  738.         EnvManager.TerminateEnv();
  739.     }
  740. }