BrokenDateVolSurface.java

  1. package org.drip.sample.option;

  2. import org.drip.analytics.date.*;
  3. import org.drip.analytics.definition.MarketSurface;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.state.creator.ScenarioMarketSurfaceBuilder;

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

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

  53. /**
  54.  * BrokenDateVolSurface contains an illustration of the Construction and Usage of the Option Volatility
  55.  *  Surface, and the Evaluation at the supplied Broken Dates.
  56.  *
  57.  * @author Lakshmi Krishnamurthy
  58.  */

  59. public class BrokenDateVolSurface {
  60.     public static final void main (
  61.         final String[] asrtArgs)
  62.         throws Exception
  63.     {
  64.         JulianDate dtStart = DateUtil.Today();

  65.         double[] adblStrikeATMFactor = new double[] {
  66.             0.8, 0.9, 1.0, 1.1, 1.2
  67.         };
  68.         String[] astrMaturityTenor = new String[] {
  69.             "1Y", "2Y", "3Y", "4Y", "5Y"
  70.         };

  71.         double[][] aadblImpliedVolatility = new double[][] {
  72.             {0.44, 0.38, 0.33, 0.27, 0.25},
  73.             {0.41, 0.34, 0.30, 0.22, 0.27},
  74.             {0.36, 0.31, 0.28, 0.30, 0.37},
  75.             {0.38, 0.31, 0.34, 0.40, 0.47},
  76.             {0.43, 0.46, 0.48, 0.52, 0.57}
  77.         };

  78.         MarketSurface volSurface = ScenarioMarketSurfaceBuilder.CubicPolynomialWireSurface (
  79.             "SAMPLE_VOL_SURFACE",
  80.             dtStart,
  81.             "USD",
  82.             adblStrikeATMFactor,
  83.             astrMaturityTenor,
  84.             aadblImpliedVolatility
  85.         );

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

  87.         System.out.println ("\t|----------------- INPUT  SURFACE  RECOVERY -----------------|");

  88.         System.out.print ("\t|------------------------------------------------------------|\n\t|  ATM/TTE  =>");

  89.         for (String strMaturity : astrMaturityTenor)
  90.             System.out.print ("     " + strMaturity + "  ");

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

  92.         for (double dblStrike : adblStrikeATMFactor) {
  93.             System.out.print ("\t|  " + FormatUtil.FormatDouble (dblStrike, 1, 2, 1.) + "    =>");

  94.             for (String strMaturity : astrMaturityTenor)
  95.                 System.out.print ("  " + FormatUtil.FormatDouble (volSurface.node (dblStrike, strMaturity), 2, 2, 100.) + "%");

  96.             System.out.print ("  |\n");
  97.         }

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

  99.         adblStrikeATMFactor = new double[] {
  100.             0.850, 0.925, 1.000, 1.075, 1.15
  101.         };
  102.         astrMaturityTenor = new String[] {
  103.             "18M", "27M", "36M", "45M", "54M"
  104.         };

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

  106.         System.out.println ("\t|------------- INTERIM  SURFACE  RECALCULATION --------------|");

  107.         System.out.print ("\t|------------------------------------------------------------|\n\t|  ATM/TTE  =>");

  108.         for (String strMaturity : astrMaturityTenor)
  109.             System.out.print ("    " + strMaturity + "  ");

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

  111.         for (double dblStrike : adblStrikeATMFactor) {
  112.             System.out.print ("\t|  " + FormatUtil.FormatDouble (dblStrike, 1, 2, 1.) + "    =>");

  113.             for (String strMaturity : astrMaturityTenor)
  114.                 System.out.print ("  " + FormatUtil.FormatDouble (volSurface.node (dblStrike, strMaturity), 2, 2, 100.) + "%");

  115.             System.out.print ("  |\n");
  116.         }

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

  118.         adblStrikeATMFactor = new double[] {
  119.             0.700, 0.850, 1.000, 1.150, 1.300
  120.         };
  121.         astrMaturityTenor = new String[] {
  122.             "06M", "21M", "36M", "51M", "66M"
  123.         };

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

  125.         System.out.println ("\t|------------- INTERIM  SURFACE  RECALCULATION --------------|");

  126.         System.out.print ("\t|------------------------------------------------------------|\n\t|  ATM/TTE  =>");

  127.         for (String strMaturity : astrMaturityTenor)
  128.             System.out.print ("    " + strMaturity + "  ");

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

  130.         for (double dblStrike : adblStrikeATMFactor) {
  131.             System.out.print ("\t|  " + FormatUtil.FormatDouble (dblStrike, 1, 2, 1.) + "    =>");

  132.             for (String strMaturity : astrMaturityTenor)
  133.                 System.out.print ("  " + FormatUtil.FormatDouble (volSurface.node (dblStrike, strMaturity), 2, 2, 100.) + "%");

  134.             System.out.print ("  |\n");
  135.         }

  136.         System.out.println ("\t|------------------------------------------------------------|");
  137.     }
  138. }