MultiCurveFRAMarketAnalysis.java

  1. package org.drip.sample.fra;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.function.r1tor1.*;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.param.creator.MarketParamsBuilder;
  7. import org.drip.param.market.CurveSurfaceQuoteContainer;
  8. import org.drip.param.valuation.ValuationParams;
  9. import org.drip.product.creator.SingleStreamComponentBuilder;
  10. import org.drip.product.fra.FRAMarketComponent;
  11. import org.drip.sample.forward.*;
  12. import org.drip.service.env.EnvManager;
  13. import org.drip.state.discount.*;
  14. import org.drip.state.forward.ForwardCurve;
  15. import org.drip.state.identifier.*;
  16. import org.drip.state.nonlinear.FlatForwardVolatilityCurve;
  17. import org.drip.state.volatility.VolatilityCurve;

  18. /*
  19.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  20.  */

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

  84. /**
  85.  * <i>MultiCurveFRAMarketAnalysis</i> contains an analysis of the correlation and volatility impact on the
  86.  * Market FRA.
  87.  *  
  88.  * <br><br>
  89.  *  <ul>
  90.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  91.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  92.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  93.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/fra/README.md">FRA Analytics</a></li>
  94.  *  </ul>
  95.  * <br><br>
  96.  *
  97.  * @author Lakshmi Krishnamurthy
  98.  */

  99. public class MultiCurveFRAMarketAnalysis {
  100.     static class FRAMktConvexityCorrection {
  101.         double _dblParMktFwd = Double.NaN;
  102.         double _dblParStdFwd = Double.NaN;
  103.         double _dblConvexityCorrection = Double.NaN;

  104.         FRAMktConvexityCorrection (
  105.             final double dblParMktFwd,
  106.             final double dblParStdFwd,
  107.             final double dblConvexityCorrection)
  108.         {
  109.             _dblParMktFwd = dblParMktFwd;
  110.             _dblParStdFwd = dblParStdFwd;
  111.             _dblConvexityCorrection = dblConvexityCorrection;
  112.         }
  113.     }

  114.     private static final VolatilityCurve ATMVolatilityCurve (
  115.         final JulianDate dtEpoch,
  116.         final VolatilityLabel label,
  117.         final String strCurrency,
  118.         final String[] astrTenor,
  119.         final double[] adblVolatility)
  120.         throws Exception
  121.     {
  122.         int[] iPillarDate = new int[astrTenor.length];

  123.         for (int i = 0; i < iPillarDate.length; ++i)
  124.             iPillarDate[i] = dtEpoch.addTenor (astrTenor[i]).julian();

  125.         return new FlatForwardVolatilityCurve (
  126.             dtEpoch.julian(),
  127.             label,
  128.             strCurrency,
  129.             iPillarDate,
  130.             adblVolatility
  131.         );
  132.     }

  133.     public static final FRAMktConvexityCorrection FRAMktMetric (
  134.         final JulianDate dtValue,
  135.         final MergedDiscountForwardCurve dcEONIA,
  136.         final ForwardCurve fcEURIBOR6M,
  137.         final String strForwardStartTenor,
  138.         final VolatilityCurve vcEONIA,
  139.         final VolatilityCurve vcEURIBOR6M,
  140.         final double dblEONIAEURIBOR6MCorrelation)
  141.         throws Exception
  142.     {
  143.         String strTenor = "6M";
  144.         String strCurrency = "USD";

  145.         ForwardLabel fri = ForwardLabel.Create (
  146.             strCurrency,
  147.             strTenor
  148.         );

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

  150.         JulianDate dtForwardStart = dtValue.addTenor (strForwardStartTenor);

  151.         FRAMarketComponent fra = SingleStreamComponentBuilder.FRAMarket (
  152.             dtForwardStart,
  153.             fri,
  154.             0.006
  155.         );

  156.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  157.             dcEONIA,
  158.             fcEURIBOR6M,
  159.             null,
  160.             null,
  161.             null,
  162.             null,
  163.             null,
  164.             null
  165.         );

  166.         ValuationParams valParams = new ValuationParams (
  167.             dtValue,
  168.             dtValue,
  169.             strCurrency
  170.         );

  171.         mktParams.setForwardVolatility (vcEURIBOR6M);

  172.         mktParams.setFundingVolatility (vcEONIA);

  173.         mktParams.setForwardFundingCorrelation (
  174.             fri,
  175.             fundingLabel,
  176.             new FlatUnivariate (dblEONIAEURIBOR6MCorrelation)
  177.         );

  178.         Map<String, Double> mapFRAOutput = fra.value (
  179.             valParams,
  180.             null,
  181.             mktParams,
  182.             null
  183.         );

  184.         return new FRAMktConvexityCorrection (
  185.             mapFRAOutput.get ("shiftedlognormalparmarketfra"),
  186.             mapFRAOutput.get ("parstandardfra"),
  187.             mapFRAOutput.get ("shiftedlognormalconvexitycorrection")
  188.         );
  189.     }

  190.     public static final void main (
  191.         final String[] astrArgs)
  192.         throws Exception
  193.     {
  194.         /*
  195.          * Initialize the Credit Analytics Library
  196.          */

  197.         EnvManager.InitEnv ("");

  198.         String strTenor = "6M";
  199.         String strCurrency = "USD";

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

  201.         MergedDiscountForwardCurve dcEONIA = OvernightIndexCurve.MakeDC (
  202.             dtToday,
  203.             strCurrency
  204.         );

  205.         ForwardCurve fcEURIBOR6M = IBOR6MQuarticPolyVanilla.Make6MForward (
  206.             dtToday,
  207.             strCurrency,
  208.             strTenor
  209.         );

  210.         String[] astrForwardStartTenor = {
  211.             "6M",
  212.             "1Y",
  213.             "2Y",
  214.             "3Y",
  215.             "4Y",
  216.             "5Y",
  217.             "6Y",
  218.             "7Y",
  219.             "8Y",
  220.             "9Y"
  221.         };

  222.         double[] adblVolatility = new double[] {
  223.             0.5946, // 6M
  224.             0.5311, // 1Y
  225.             0.3307, // 2Y
  226.             0.2929, // 3Y
  227.             0.2433, // 4Y
  228.             0.2013, // 5Y
  229.             0.1855, // 6Y
  230.             0.1789, // 7Y
  231.             0.1655, // 8Y
  232.             0.1574  // 9Y
  233.         };

  234.         double dblEONIAEURIBOR6MCorrelation = 0.8;

  235.         VolatilityCurve vcEONIA = ATMVolatilityCurve (
  236.             dtToday,
  237.             VolatilityLabel.Standard (FundingLabel.Standard (strCurrency)),
  238.             strCurrency,
  239.             astrForwardStartTenor,
  240.             adblVolatility
  241.         );

  242.         VolatilityCurve vEURIBOR6M = ATMVolatilityCurve (
  243.             dtToday,
  244.             VolatilityLabel.Standard (
  245.                 ForwardLabel.Create (
  246.                     strCurrency,
  247.                     strTenor
  248.                 )
  249.             ),
  250.             strCurrency,
  251.             astrForwardStartTenor,
  252.             adblVolatility
  253.         );

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

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

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

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

  258.         System.out.println ("\tTNR =>   MKT   |   STD   |  CONV ");

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

  260.         for (String strForwardStartTenor : astrForwardStartTenor) {
  261.             FRAMktConvexityCorrection fraMktMetric = FRAMktMetric (
  262.                 dtToday,
  263.                 dcEONIA,
  264.                 fcEURIBOR6M,
  265.                 strForwardStartTenor,
  266.                 vcEONIA,
  267.                 vEURIBOR6M,
  268.                 dblEONIAEURIBOR6MCorrelation
  269.             );

  270.             System.out.println (
  271.                 "\t " + strForwardStartTenor + " => " +
  272.                 FormatUtil.FormatDouble (fraMktMetric._dblParMktFwd, 1, 3, 100.) + "% | " +
  273.                 FormatUtil.FormatDouble (fraMktMetric._dblParStdFwd, 1, 3, 100.) + "% | " +
  274.                 FormatUtil.FormatDouble (fraMktMetric._dblConvexityCorrection, 1, 2, 10000.)
  275.             );
  276.         }

  277.         EnvManager.TerminateEnv();
  278.     }
  279. }