AlbrecherMayerSchoutensTistaert.java

  1. package org.drip.sample.stochasticvolatility;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.numerical.fourier.PhaseAdjuster;
  4. import org.drip.param.pricer.HestonOptionPricerParams;
  5. import org.drip.pricer.option.*;

  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.  * AlbrecherMayerSchoutensTistaert displays the Heston (1993) Price/Vol Surface across the Range of Strikes
  55.  *  and Maturities, demonstrating the smiles and the skews. It also runs a Robustness Comparison Run using
  56.  *  the Methodology of Albrecher, Mayer, Schoutens, and Tistaert (2007).
  57.  *
  58.  * @author Lakshmi Krishnamurthy
  59.  */

  60. public class AlbrecherMayerSchoutensTistaert {
  61.     private static final double CallPrice (
  62.         final double dblATMFactor,
  63.         final double dblTimeToExpiry,
  64.         final int iPayoffTransformScheme)
  65.         throws Exception
  66.     {
  67.         double dblRho = 0.3;
  68.         double dblKappa = 1.;
  69.         double dblSigma = 0.5;
  70.         double dblTheta = 0.2;
  71.         double dblLambda = 0.;

  72.         HestonOptionPricerParams fphp = new HestonOptionPricerParams (
  73.             iPayoffTransformScheme,
  74.             dblRho,
  75.             dblKappa,
  76.             dblSigma,
  77.             dblTheta,
  78.             dblLambda,
  79.             PhaseAdjuster.MULTI_VALUE_BRANCH_POWER_PHASE_TRACKER_KAHL_JACKEL
  80.         );

  81.         HestonStochasticVolatilityAlgorithm hsva = new HestonStochasticVolatilityAlgorithm (fphp);

  82.         double dblStrike = dblATMFactor;
  83.         double dblRiskFreeRate = 0.0;
  84.         double dblSpot = 1.;
  85.         double dblInitialVolatility = 0.1;

  86.         Greeks greeks = hsva.greeks (
  87.             dblStrike,
  88.             dblTimeToExpiry,
  89.             dblRiskFreeRate,
  90.             dblSpot,
  91.             false,
  92.             false,
  93.             dblInitialVolatility
  94.         );

  95.         return greeks.price();
  96.     }

  97.     public static final void main (
  98.         final String[] astrArgs)
  99.         throws Exception
  100.     {
  101.         double[] adblATMFactor = new double[] {
  102.             0.8, 0.9, 1.0, 1.1, 1.2
  103.         };
  104.         double[] adblTTE = new double[] {
  105.             0.5, 1., 2., 3., 4., 5., 7., 10., 12., 15., 20., 25., 30.
  106.         };

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

  108.         System.out.println ("\t\t\t----    HESTON 1993 TRANSFORM    ----");

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

  110.         for (double dblTTE : adblTTE)
  111.             System.out.print ("  " + FormatUtil.FormatDouble (dblTTE, 2, 2, 1.) + " ");

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

  113.         for (double dblATMFactor : adblATMFactor) {
  114.             System.out.print ("\t|  " + FormatUtil.FormatDouble (dblATMFactor, 2, 2, 1.) + "   =>");

  115.             for (double dblTTE : adblTTE)
  116.                 System.out.print ("  " + FormatUtil.FormatDouble (CallPrice (dblATMFactor, dblTTE,
  117.                     HestonStochasticVolatilityAlgorithm.PAYOFF_TRANSFORM_SCHEME_HESTON_1993), 1, 4, 1.));

  118.             System.out.print ("  |\n");
  119.         }

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

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

  122.         System.out.println ("\t\t\t----    ALBRECHER, MAYER, SCHOUTENS, TISTAERT 2007 TRANSFORM    ----");

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

  124.         for (double dblTTE : adblTTE)
  125.             System.out.print ("  " + FormatUtil.FormatDouble (dblTTE, 2, 2, 1.) + " ");

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

  127.         for (double dblATMFactor : adblATMFactor) {
  128.             System.out.print ("\t|  " + FormatUtil.FormatDouble (dblATMFactor, 2, 2, 1.) + "   =>");

  129.             for (double dblTTE : adblTTE)
  130.                 System.out.print ("  " + FormatUtil.FormatDouble (CallPrice (dblATMFactor, dblTTE,
  131.                     HestonStochasticVolatilityAlgorithm.PAYOFF_TRANSFORM_SCHEME_AMST_2007), 1, 4, 1.));

  132.             System.out.print ("  |\n");
  133.         }

  134.         System.out.println ("  \t|------------------------------------------------------------------------------------------------------------------------------------|");
  135.     }
  136. }