JurisdictionVenueOptionValuation.java

  1. package org.drip.sample.forwardratefutures;

  2. import java.util.*;

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

  87. /**
  88.  * <i>JurisdictionVenueOptionValuation</i> contains the Demonstration of the Construction and the Valuation
  89.  * of the Options on Standardized LIBOR Futures Contract across Jurisdictions and Venues.
  90.  *  
  91.  * <br><br>
  92.  *  <ul>
  93.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  94.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  95.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  96.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/forwardratefutures/README.md">Forward Rate Futures Analytics</a></li>
  97.  *  </ul>
  98.  * <br><br>
  99.  *
  100.  * @author Lakshmi Krishnamurthy
  101.  */

  102. public class JurisdictionVenueOptionValuation {

  103.     private static final FloatFloatComponent OTCFloatFloat (
  104.         final JulianDate dtSpot,
  105.         final String strCurrency,
  106.         final String strDerivedTenor,
  107.         final String strMaturityTenor,
  108.         final double dblBasis)
  109.     {
  110.         FloatFloatSwapConvention ffConv = IBORFloatFloatContainer.ConventionFromJurisdiction (strCurrency);

  111.         return ffConv.createFloatFloatComponent (
  112.             dtSpot,
  113.             strDerivedTenor,
  114.             strMaturityTenor,
  115.             dblBasis,
  116.             1.
  117.         );
  118.     }

  119.     /*
  120.      * Construct an array of float-float swaps from the corresponding reference (6M) and the derived legs.
  121.      *
  122.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  123.      */

  124.     private static final FloatFloatComponent[] MakexM6MBasisSwap (
  125.         final JulianDate dtSpot,
  126.         final String strCurrency,
  127.         final String[] astrMaturityTenor,
  128.         final int iTenorInMonths)
  129.         throws Exception
  130.     {
  131.         FloatFloatComponent[] aFFC = new FloatFloatComponent[astrMaturityTenor.length];

  132.         for (int i = 0; i < astrMaturityTenor.length; ++i)
  133.             aFFC[i] = OTCFloatFloat (
  134.                 dtSpot,
  135.                 strCurrency,
  136.                 iTenorInMonths + "M",
  137.                 astrMaturityTenor[i],
  138.                 0.
  139.             );

  140.         return aFFC;
  141.     }

  142.     private static final ForwardCurve MakeFC (
  143.         final JulianDate dtSpot,
  144.         final String strCurrency,
  145.         final MergedDiscountForwardCurve dc,
  146.         final int iTenorInMonths,
  147.         final String[] astrxM6MFwdTenor,
  148.         final double[] adblxM6MBasisSwapQuote)
  149.         throws Exception
  150.     {
  151.         /*
  152.          * Construct the 6M-xM float-float basis swap.
  153.          */

  154.         FloatFloatComponent[] aFFC = MakexM6MBasisSwap (
  155.             dtSpot,
  156.             strCurrency,
  157.             astrxM6MFwdTenor,
  158.             iTenorInMonths
  159.         );

  160.         String strBasisTenor = iTenorInMonths + "M";

  161.         ValuationParams valParams = new ValuationParams (
  162.             dtSpot,
  163.             dtSpot,
  164.             strCurrency
  165.         );

  166.         /*
  167.          * Calculate the starting forward rate off of the discount curve.
  168.          */

  169.         double dblStartingFwd = dc.forward (
  170.             dtSpot.julian(),
  171.             dtSpot.addTenor (strBasisTenor).julian()
  172.         );

  173.         /*
  174.          * Set the discount curve based component market parameters.
  175.          */

  176.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  177.             dc,
  178.             null,
  179.             null,
  180.             null,
  181.             null,
  182.             null,
  183.             null
  184.         );

  185.         /*
  186.          * Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
  187.          */

  188.         return ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
  189.             "QUARTIC_FWD" + strBasisTenor,
  190.             ForwardLabel.Create (
  191.                 strCurrency,
  192.                 strBasisTenor
  193.             ),
  194.             valParams,
  195.             null,
  196.             mktParams,
  197.             null,
  198.             MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
  199.             new PolynomialFunctionSetParams (5),
  200.             aFFC,
  201.             "DerivedParBasisSpread",
  202.             adblxM6MBasisSwapQuote,
  203.             dblStartingFwd
  204.         );
  205.     }

  206.     private static final Map<String, ForwardCurve> MakeFC (
  207.         final JulianDate dt,
  208.         final String strCurrency,
  209.         final MergedDiscountForwardCurve dc)
  210.         throws Exception
  211.     {
  212.         Map<String, ForwardCurve> mapFC = new HashMap<String, ForwardCurve>();

  213.         /*
  214.          * Build and run the sampling for the 1M-6M Tenor Basis Swap from its instruments and quotes.
  215.          */

  216.         ForwardCurve fc1M = MakeFC (
  217.             dt,
  218.             strCurrency,
  219.             dc,
  220.             1,
  221.             new String[] {
  222.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  223.             },
  224.             new double[] {
  225.                 0.00551,    //  1Y
  226.                 0.00387,    //  2Y
  227.                 0.00298,    //  3Y
  228.                 0.00247,    //  4Y
  229.                 0.00211,    //  5Y
  230.                 0.00185,    //  6Y
  231.                 0.00165,    //  7Y
  232.                 0.00150,    //  8Y
  233.                 0.00137,    //  9Y
  234.                 0.00127,    // 10Y
  235.                 0.00119,    // 11Y
  236.                 0.00112,    // 12Y
  237.                 0.00096,    // 15Y
  238.                 0.00079,    // 20Y
  239.                 0.00069,    // 25Y
  240.                 0.00062     // 30Y
  241.                 }
  242.             );

  243.         mapFC.put (
  244.             "1M",
  245.             fc1M
  246.         );

  247.         /*
  248.          * Build and run the sampling for the 3M-6M Tenor Basis Swap from its instruments and quotes.
  249.          */

  250.         ForwardCurve fc3M = MakeFC (
  251.             dt,
  252.             strCurrency,
  253.             dc,
  254.             3,
  255.             new String[] {
  256.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
  257.             },
  258.             new double[] {
  259.                 0.00186,    //  1Y
  260.                 0.00127,    //  2Y
  261.                 0.00097,    //  3Y
  262.                 0.00080,    //  4Y
  263.                 0.00067,    //  5Y
  264.                 0.00058,    //  6Y
  265.                 0.00051,    //  7Y
  266.                 0.00046,    //  8Y
  267.                 0.00042,    //  9Y
  268.                 0.00038,    // 10Y
  269.                 0.00035,    // 11Y
  270.                 0.00033,    // 12Y
  271.                 0.00028,    // 15Y
  272.                 0.00022,    // 20Y
  273.                 0.00020,    // 25Y
  274.                 0.00018     // 30Y
  275.                 }
  276.             );

  277.         mapFC.put (
  278.             "3M",
  279.             fc3M
  280.         );

  281.         /*
  282.          * Build and run the sampling for the 12M-6M Tenor Basis Swap from its instruments and quotes.
  283.          */

  284.         ForwardCurve fc12M = MakeFC (
  285.             dt,
  286.             strCurrency,
  287.             dc,
  288.             12,
  289.             new String[] {
  290.                 "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y",
  291.                 "35Y", "40Y" // Extrapolated
  292.             },
  293.             new double[] {
  294.                 -0.00212,    //  1Y
  295.                 -0.00152,    //  2Y
  296.                 -0.00117,    //  3Y
  297.                 -0.00097,    //  4Y
  298.                 -0.00082,    //  5Y
  299.                 -0.00072,    //  6Y
  300.                 -0.00063,    //  7Y
  301.                 -0.00057,    //  8Y
  302.                 -0.00051,    //  9Y
  303.                 -0.00047,    // 10Y
  304.                 -0.00044,    // 11Y
  305.                 -0.00041,    // 12Y
  306.                 -0.00035,    // 15Y
  307.                 -0.00028,    // 20Y
  308.                 -0.00025,    // 25Y
  309.                 -0.00022,    // 30Y
  310.                 -0.00022,    // 35Y Extrapolated
  311.                 -0.00022,    // 40Y Extrapolated
  312.                 }
  313.             );

  314.         mapFC.put (
  315.             "12M",
  316.             fc12M
  317.         );

  318.         return mapFC;
  319.     }

  320.     private static final void SetVolCorrelation (
  321.         final int iValueDate,
  322.         final CurveSurfaceQuoteContainer mktParams,
  323.         final ForwardLabel fri,
  324.         final double dblForwardVol,
  325.         final double dblFundingVol,
  326.         final double dblForwardFundingCorr)
  327.         throws Exception
  328.     {
  329.         FundingLabel fundingLabel = FundingLabel.Standard (fri.currency());

  330.         mktParams.setForwardVolatility (
  331.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  332.                 iValueDate,
  333.                 VolatilityLabel.Standard (fri),
  334.                 fri.currency(),
  335.                 dblForwardVol
  336.             )
  337.         );

  338.         mktParams.setFundingVolatility (
  339.             ScenarioDeterministicVolatilityBuilder.FlatForward (
  340.                 iValueDate,
  341.                 VolatilityLabel.Standard (fundingLabel),
  342.                 fri.currency(),
  343.                 dblFundingVol
  344.             )
  345.         );

  346.         mktParams.setForwardFundingCorrelation (
  347.             fri,
  348.             fundingLabel,
  349.             new FlatUnivariate (dblForwardFundingCorr)
  350.         );
  351.     }

  352.     private static final void FuturesOptionMetrics (
  353.         final String strCurrency,
  354.         final String strTenor,
  355.         final JulianDate dtSpot,
  356.         final String strOptionType,
  357.         final String strExchange)
  358.         throws Exception
  359.     {
  360.         MergedDiscountForwardCurve dcOIS = OvernightIndexCurve.MakeDC (
  361.             dtSpot,
  362.             strCurrency
  363.         );

  364.         ForwardLabel forwardLabel = ForwardLabel.Create (
  365.             strCurrency,
  366.             strTenor
  367.         );

  368.         Map<String, ForwardCurve> mapFC = MakeFC (
  369.             dtSpot,
  370.             strCurrency,
  371.             dcOIS
  372.         );

  373.         ForwardCurve fc = mapFC.get (strTenor);

  374.         JulianDate dtEffective = dtSpot.addTenor ("3M");

  375.         FRAStandardCapFloorlet liborFuturesOption = SingleStreamOptionBuilder.ExchangeTradedFuturesOption (
  376.             dtEffective,
  377.             forwardLabel,
  378.             fc.forward (dtEffective.addTenor (fc.tenor())),
  379.             "ParForward",
  380.             false,
  381.             strOptionType,
  382.             strExchange
  383.         );

  384.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  385.             dcOIS,
  386.             fc,
  387.             null,
  388.             null,
  389.             null,
  390.             null,
  391.             null,
  392.             null
  393.         );

  394.         double dblForwardVol = 0.50;
  395.         double dblFundingVol = 0.50;
  396.         double dblForwardFundingCorr = 0.50;

  397.         SetVolCorrelation (
  398.             dtSpot.julian(),
  399.             mktParams,
  400.             forwardLabel,
  401.             dblForwardVol,
  402.             dblFundingVol,
  403.             dblForwardFundingCorr
  404.         );

  405.         ValuationParams valParams = new ValuationParams (
  406.             dtSpot,
  407.             dtSpot,
  408.             strCurrency
  409.         );

  410.         Map<String, Double> mapOutput = liborFuturesOption.value (
  411.             valParams,
  412.             null,
  413.             mktParams,
  414.             null
  415.         );

  416.         System.out.println ("\t\t" + strExchange + " | " +
  417.             FormatUtil.FormatDouble (mapOutput.get ("ATMFRA"), 1, 4, 100.) + " % | " +
  418.             FormatUtil.FormatDouble (mapOutput.get ("Upfront"), 1, 1, 10000.) + " bp | " +
  419.             forwardLabel.fullyQualifiedName()
  420.         );
  421.     }

  422.     public static final void main (
  423.         final String[] astrArgs)
  424.         throws Exception
  425.     {
  426.         /*
  427.          * Initialize the Credit Analytics Library
  428.          */

  429.         EnvManager.InitEnv ("");

  430.         JulianDate dtToday = DateUtil.Today();

  431.         System.out.println ("\tOutput Order - L -> R:");

  432.         System.out.println ("\t\tExchange\n\t\tATM Par FRA Level (%)\n\t\tOption Upfront (bp)\n\t\tFRA Label");

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

  434.         System.out.println ("\t--------------- MARGIN TYPE OPTION ------------------");

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

  436.         FuturesOptionMetrics (
  437.             "CHF",
  438.             "3M",
  439.             dtToday,
  440.             "MARGIN",
  441.             "LIFFE"
  442.         );

  443.         FuturesOptionMetrics (
  444.             "GBP",
  445.             "3M",
  446.             dtToday,
  447.             "MARGIN",
  448.             "LIFFE"
  449.         );

  450.         /* FuturesOptionMetrics (
  451.             "EUR",
  452.             "3M",
  453.             dtToday,
  454.             "MARGIN",
  455.             "LIFFE"
  456.         ); */

  457.         FuturesOptionMetrics (
  458.             "USD",
  459.             "3M",
  460.             dtToday,
  461.             "MARGIN",
  462.             "LIFFE"
  463.         );

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

  465.         System.out.println ("\t-------------- PREMIUM TYPE OPTION ------------------");

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

  467.         FuturesOptionMetrics (
  468.             "JPY",
  469.             "3M",
  470.             dtToday,
  471.             "PREMIUM",
  472.             "SGX"
  473.         );

  474.         FuturesOptionMetrics (
  475.             "USD",
  476.             "1M",
  477.             dtToday,
  478.             "PREMIUM",
  479.             "CME"
  480.         );

  481.         FuturesOptionMetrics (
  482.             "USD",
  483.             "3M",
  484.             dtToday,
  485.             "PREMIUM",
  486.             "CME"
  487.         );

  488.         FuturesOptionMetrics (
  489.             "USD",
  490.             "3M",
  491.             dtToday,
  492.             "PREMIUM",
  493.             "SGX"
  494.         );

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

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

  497.         EnvManager.TerminateEnv();
  498.     }
  499. }