CSAFundingAbsoluteForward.java

  1. package org.drip.sample.piterbarg2010;

  2. import org.drip.exposure.csadynamics.FundingBasisEvolver;
  3. import org.drip.measure.dynamics.*;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;

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

  50. /**
  51.  * CSAFundingAbsoluteForward compares the Absolute Differences between the CSA and the non-CSA Forward LIBOR
  52.  *  under a Stochastic Funding Model. The References are:
  53.  *  
  54.  *  - Barden, P. (2009): Equity Forward Prices in the Presence of Funding Spreads, ICBI Conference, Rome.
  55.  *  
  56.  *  - Burgard, C., and M. Kjaer (2009): Modeling and successful Management of Credit Counter-party Risk of
  57.  *      Derivative Portfolios, ICBI Conference, Rome.
  58.  *  
  59.  *  - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90.
  60.  *  
  61.  *  - Johannes, M., and S. Sundaresan (2007): Pricing Collateralized Swaps, Journal of Finance 62 383-410.
  62.  *
  63.  *  - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
  64.  *      21 (2) 97-102.
  65.  *
  66.  * @author Lakshmi Krishnamurthy
  67.  */

  68. public class CSAFundingAbsoluteForward {

  69.     public static final void main (
  70.         final String[] astrArgs)
  71.         throws Exception
  72.     {
  73.         EnvManager.InitEnv ("");

  74.         double dblUnderlyingVolatility = 0.3;
  75.         double dblFundingSpreadVolatility = 0.015;
  76.         double dblFundingSpreadMeanReversionRate = 0.05;
  77.         double dblCSALIBOR = 0.018;

  78.         double[] adblCorrelation = new double[] {
  79.             -0.20,
  80.              0.00,
  81.              0.20,
  82.              0.40
  83.         };

  84.         int[] aiTenor = new int[] {
  85.              1,
  86.              2,
  87.              3,
  88.              4,
  89.              5,
  90.              7,
  91.             10,
  92.             15,
  93.             20,
  94.             25,
  95.             30
  96.         };

  97.         DiffusionEvaluatorLogarithmic delUnderlying = DiffusionEvaluatorLogarithmic.Standard (
  98.             0.,
  99.             dblUnderlyingVolatility
  100.         );

  101.         DiffusionEvaluatorMeanReversion demrFundingSpread = DiffusionEvaluatorMeanReversion.Standard (
  102.             dblFundingSpreadMeanReversionRate,
  103.             0.,
  104.             dblFundingSpreadVolatility
  105.         );

  106.         System.out.println();

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

  108.         System.out.println ("\t||     DRIP CSA vs Non CSA Forward Rates      ||");

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

  110.         String strHeader = "\t|| CORR => ";

  111.         for (double dblCorrelation : adblCorrelation)
  112.             strHeader = strHeader + "  " + FormatUtil.FormatDouble (dblCorrelation, 2, 0, 100.) + "%  |";

  113.         System.out.println (strHeader + "|");

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

  115.         for (int iTenor : aiTenor) {
  116.             String strDump = "\t|| " + FormatUtil.FormatDouble (iTenor, 2, 0, 1.) + "Y => ";

  117.             for (double dblCorrelation : adblCorrelation) {
  118.                 FundingBasisEvolver sftf = new FundingBasisEvolver (
  119.                     delUnderlying,
  120.                     demrFundingSpread,
  121.                     dblCorrelation
  122.                 );

  123.                 strDump = strDump + " " + FormatUtil.FormatDouble (dblCSALIBOR * (sftf.CSANoCSARatio (iTenor + "Y") - 1.), 1, 2, 100.) + "% |";
  124.             }

  125.             System.out.println (strDump + "|");
  126.         }

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

  128.         System.out.println();
  129.     }
  130. }