ZeroStrikeCallOption.java

  1. package org.drip.sample.piterbarg2010;

  2. import org.drip.analytics.date.*;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.service.template.LatentMarketStateBuilder;
  6. import org.drip.state.discount.*;

  7. /*
  8.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  9.  */

  10. /*!
  11.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  15.  *      libraries targeting analysts and developers
  16.  *      https://lakshmidrip.github.io/DRIP/
  17.  *  
  18.  *  DRIP is composed of four main libraries:
  19.  *  
  20.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  21.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  22.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  23.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  24.  *
  25.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  26.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  27.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  28.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  29.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  30.  *
  31.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  32.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  33.  *
  34.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  35.  *
  36.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  37.  *
  38.  *  Licensed under the Apache License, Version 2.0 (the "License");
  39.  *      you may not use this file except in compliance with the License.
  40.  *  
  41.  *  You may obtain a copy of the License at
  42.  *      http://www.apache.org/licenses/LICENSE-2.0
  43.  *  
  44.  *  Unless required by applicable law or agreed to in writing, software
  45.  *      distributed under the License is distributed on an "AS IS" BASIS,
  46.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  47.  *  
  48.  *  See the License for the specific language governing permissions and
  49.  *      limitations under the License.
  50.  */

  51. /**
  52.  * ZeroStrikeCallOption examines the Impact of Funding and Collateralization on a "Zero Strike Call", i.e.,
  53.  *  the Futures Contract on an Asset with Non-Zero Value. The References are:
  54.  *  
  55.  *  - Barden, P. (2009): Equity Forward Prices in the Presence of Funding Spreads, ICBI Conference, Rome.
  56.  *  
  57.  *  - Burgard, C., and M. Kjaer (2009): Modeling and successful Management of Credit Counter-party Risk of
  58.  *      Derivative Portfolios, ICBI Conference, Rome.
  59.  *  
  60.  *  - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90.
  61.  *  
  62.  *  - Johannes, M., and S. Sundaresan (2007): Pricing Collateralized Swaps, Journal of Finance 62 383-410.
  63.  *
  64.  *  - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
  65.  *      21 (2) 97-102.
  66.  *
  67.  * @author Lakshmi Krishnamurthy
  68.  */

  69. public class ZeroStrikeCallOption {

  70.     private static final DiscountCurve OvernightCurve (
  71.         final String strCurrency,
  72.         final JulianDate dtSpot)
  73.         throws Exception
  74.     {
  75.         String[] astrDepositMaturityTenor = new String[] {
  76.             "1D",
  77.             // "2D",
  78.             // "3D"
  79.         };

  80.         double[] adblDepositQuote = new double[] {
  81.             0.0004,     // 1D
  82.             // 0.0004,      // 2D
  83.             // 0.0004       // 3D
  84.         };

  85.         String[] astrShortEndOISMaturityTenor = new String[] {
  86.             "1W",
  87.             "2W",
  88.             "3W",
  89.             "1M"
  90.         };

  91.         double[] adblShortEndOISQuote = new double[] {
  92.             0.00070,    //   1W
  93.             0.00069,    //   2W
  94.             0.00078,    //   3W
  95.             0.00074     //   1M
  96.         };

  97.         String[] astrOISFuturesEffectiveTenor = new String[] {
  98.             "1M",
  99.             "2M",
  100.             "3M",
  101.             "4M",
  102.             "5M"
  103.         };

  104.         String[] astrOISFuturesMaturityTenor = new String[] {
  105.             "1M",
  106.             "1M",
  107.             "1M",
  108.             "1M",
  109.             "1M"
  110.         };

  111.         double[] adblOISFuturesQuote = new double[] {
  112.              0.00046,    //   1M x 1M
  113.              0.00016,    //   2M x 1M
  114.             -0.00007,    //   3M x 1M
  115.             -0.00013,    //   4M x 1M
  116.             -0.00014     //   5M x 1M
  117.         };

  118.         String[] astrLongEndOISMaturityTenor = new String[] {
  119.             "15M",
  120.             "18M",
  121.             "21M",
  122.             "02Y",
  123.             "03Y",
  124.             "04Y",
  125.             "05Y",
  126.             "06Y",
  127.             "07Y",
  128.             "08Y",
  129.             "09Y",
  130.             "10Y",
  131.             "11Y",
  132.             "12Y",
  133.             "15Y",
  134.             "20Y",
  135.             "25Y",
  136.             "30Y"
  137.         };

  138.         double[] adblLongEndOISQuote = new double[] {
  139.             0.00002,    //  15M
  140.             0.00008,    //  18M
  141.             0.00021,    //  21M
  142.             0.00036,    //   2Y
  143.             0.00127,    //   3Y
  144.             0.00274,    //   4Y
  145.             0.00456,    //   5Y
  146.             0.00647,    //   6Y
  147.             0.00827,    //   7Y
  148.             0.00996,    //   8Y
  149.             0.01147,    //   9Y
  150.             0.01280,    //  10Y
  151.             0.01404,    //  11Y
  152.             0.01516,    //  12Y
  153.             0.01764,    //  15Y
  154.             0.01939,    //  20Y
  155.             0.02003,    //  25Y
  156.             0.02038     //  30Y
  157.         };

  158.         return LatentMarketStateBuilder.SmoothOvernightCurve (
  159.             dtSpot,
  160.             strCurrency,
  161.             astrDepositMaturityTenor,
  162.             adblDepositQuote,
  163.             "Rate",
  164.             astrShortEndOISMaturityTenor,
  165.             adblShortEndOISQuote,
  166.             "SwapRate",
  167.             astrOISFuturesEffectiveTenor,
  168.             astrOISFuturesMaturityTenor,
  169.             adblOISFuturesQuote,
  170.             "SwapRate",
  171.             astrLongEndOISMaturityTenor,
  172.             adblLongEndOISQuote,
  173.             "SwapRate"
  174.         );
  175.     }

  176.     private static final DiscountCurve FundingCurve (
  177.         final String strCurrency,
  178.         final JulianDate dtSpot)
  179.         throws Exception
  180.     {
  181.         String[] astrDepositMaturityTenor = new String[] {
  182.             "01D",
  183.             "04D",
  184.             "07D",
  185.             "14D",
  186.             "30D",
  187.             "60D"
  188.         };

  189.         double[] adblDepositQuote = new double[] {
  190.             0.0013,     //  1D
  191.             0.0017,     //  2D
  192.             0.0017,     //  7D
  193.             0.0018,     // 14D
  194.             0.0020,     // 30D
  195.             0.0023      // 60D
  196.         };

  197.         double[] adblFuturesQuote = new double[] {
  198.             0.0027,
  199.             0.0032,
  200.             0.0041,
  201.             0.0054,
  202.             0.0077,
  203.             0.0104,
  204.             0.0134,
  205.             0.0160
  206.         };

  207.         String[] astrFixFloatMaturityTenor = new String[] {
  208.             "04Y",
  209.             "05Y",
  210.             "06Y",
  211.             "07Y",
  212.             "08Y",
  213.             "09Y",
  214.             "10Y",
  215.             "11Y",
  216.             "12Y",
  217.             "15Y",
  218.             "20Y",
  219.             "25Y",
  220.             "30Y",
  221.             "40Y",
  222.             "50Y"
  223.         };

  224.         double[] adblFixFloatQuote = new double[] {
  225.             0.0166,     //   4Y
  226.             0.0206,     //   5Y
  227.             0.0241,     //   6Y
  228.             0.0269,     //   7Y
  229.             0.0292,     //   8Y
  230.             0.0311,     //   9Y
  231.             0.0326,     //  10Y
  232.             0.0340,     //  11Y
  233.             0.0351,     //  12Y
  234.             0.0375,     //  15Y
  235.             0.0393,     //  20Y
  236.             0.0402,     //  25Y
  237.             0.0407,     //  30Y
  238.             0.0409,     //  40Y
  239.             0.0409      //  50Y
  240.         };

  241.         return LatentMarketStateBuilder.SmoothFundingCurve (
  242.             dtSpot,
  243.             strCurrency,
  244.             astrDepositMaturityTenor,
  245.             adblDepositQuote,
  246.             "ForwardRate",
  247.             adblFuturesQuote,
  248.             "ForwardRate",
  249.             astrFixFloatMaturityTenor,
  250.             adblFixFloatQuote,
  251.             "SwapRate"
  252.         );
  253.     }

  254.     public static final void main (
  255.         final String[] astrArgs)
  256.         throws Exception
  257.     {
  258.         EnvManager.InitEnv ("");

  259.         String strCurrency = "USD";

  260.         JulianDate dtSpot = DateUtil.Today().addBusDays (
  261.             0,
  262.             strCurrency
  263.         );

  264.         String[] astrTenor = new String[] {
  265.              "1W",
  266.              "2W",
  267.              "3W",
  268.              "1M",
  269.              "2M",
  270.              "3M",
  271.              "6M",
  272.              "9M",
  273.             "12M",
  274.             "18M",
  275.              "2Y",
  276.              "3Y",
  277.              "4Y",
  278.              "5Y",
  279.              "7Y",
  280.             "10Y",
  281.             "12Y",
  282.             "15Y",
  283.             "20Y",
  284.             "25Y",
  285.             "30Y",
  286.             "40Y",
  287.             "50Y"
  288.         };

  289.         MergedDiscountForwardCurve dcOvernight = (MergedDiscountForwardCurve) OvernightCurve (
  290.             strCurrency,
  291.             dtSpot
  292.         );

  293.         MergedDiscountForwardCurve dcFunding = (MergedDiscountForwardCurve) FundingCurve (
  294.             strCurrency,
  295.             dtSpot
  296.         );

  297.         System.out.println();

  298.         System.out.println ("\t||----------------------------------------------------------||");

  299.         System.out.println ("\t||         PITERBARG (2010) ZERO STRIKE CALL OPTION         ||");

  300.         System.out.println ("\t||----------------------------------------------------------||");

  301.         System.out.println ("\t||    L -> R:                                               ||");

  302.         System.out.println ("\t||            - Date                                        ||");

  303.         System.out.println ("\t||            - Overnight Zero Coupon Bond Price (100 - PAR)||");

  304.         System.out.println ("\t||            - Funding Zero Coupon Bond Price (100 - PAR)  ||");

  305.         System.out.println ("\t||            - Overnight Zero Rate (%)                     ||");

  306.         System.out.println ("\t||            - Funding Zero Rate (%)                       ||");

  307.         System.out.println ("\t||            - Funding - Overnight Basis (bp)              ||");

  308.         System.out.println ("\t||----------------------------------------------------------||");

  309.         for (String strTenor : astrTenor) {
  310.             JulianDate dt = dtSpot.addTenor (strTenor);

  311.             double dblFundingZeroRate = dcFunding.zero (strTenor);

  312.             double dblOvernightZeroRate = dcOvernight.zero (strTenor);

  313.             System.out.println ("\t|| " + dt + " | " +
  314.                 FormatUtil.FormatDouble (dcOvernight.df (dt), 3, 2, 100.) + " | " +
  315.                 FormatUtil.FormatDouble (dcFunding.df (dt), 3, 2, 100.) + " | " +
  316.                 FormatUtil.FormatDouble (dblOvernightZeroRate, 1, 2, 100.) + "% | " +
  317.                 FormatUtil.FormatDouble (dblFundingZeroRate, 1, 2, 100.) + "% ||" +
  318.                 FormatUtil.FormatDouble (dblFundingZeroRate - dblOvernightZeroRate, 3, 0, 10000.) + " ||"
  319.             );
  320.         }

  321.         System.out.println ("\t||----------------------------------------------------------||");

  322.         System.out.println();
  323.     }
  324. }