R1Jump.java

  1. package org.drip.sample.numeraire;

  2. import org.drip.measure.discrete.SequenceGenerator;
  3. import org.drip.measure.dynamics.*;
  4. import org.drip.measure.process.JumpDiffusionEvolver;
  5. import org.drip.measure.realization.*;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.service.env.EnvManager;

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

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

  52. /**
  53.  * R1Jump demonstrates the Jump Evolution of a Default-able Asset. The References are:
  54.  *  
  55.  *  - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk
  56.  *      and Funding Costs, Journal of Credit Risk, 7 (3) 1-19.
  57.  *  
  58.  *  - Cesari, G., J. Aquilina, N. Charpillon, X. Filipovic, G. Lee, and L. Manda (2009): Modeling, Pricing,
  59.  *      and Hedging Counter-party Credit Exposure - A Technical Guide, Springer Finance, New York.
  60.  *  
  61.  *  - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90.
  62.  *  
  63.  *  - Li, B., and Y. Tang (2007): Quantitative Analysis, Derivatives Modeling, and Trading Strategies in the
  64.  *      Presence of Counter-party Credit Risk for the Fixed Income Market, World Scientific Publishing,
  65.  *      Singapore.
  66.  *
  67.  *  - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
  68.  *      21 (2) 97-102.
  69.  *
  70.  * @author Lakshmi Krishnamurthy
  71.  */

  72. public class R1Jump {

  73.     public static final void main (
  74.         final String[] astrArgs)
  75.         throws Exception
  76.     {
  77.         EnvManager.InitEnv ("");

  78.         double dblTimeWidth = 1. / 24.;
  79.         double dblTime = 0.;
  80.         double dblAssetDrift = 0.06;
  81.         double dblAssetVolatility = 0.15;
  82.         double dblAssetHazard = 0.05;
  83.         double dblAssetDefaultMagnitude = 0.6;
  84.         double dblTerminalAssetNumeraire = 1.;

  85.         int iNumTimeStep = (int) (1. / dblTimeWidth);
  86.         double[] adblTimeWidth = new double[iNumTimeStep];

  87.         for (int i = 0; i < iNumTimeStep; ++i)
  88.             adblTimeWidth[i] = dblTimeWidth;

  89.         JumpDiffusionEvolver meAsset = new JumpDiffusionEvolver (
  90.             DiffusionEvaluatorLogarithmic.Standard (
  91.                 dblAssetDrift,
  92.                 dblAssetVolatility
  93.             ),
  94.             HazardJumpEvaluator.Standard (
  95.                 dblAssetHazard,
  96.                 dblAssetDefaultMagnitude
  97.             )
  98.         );

  99.         double[] adblAssetNumeraireTimeSeries = SequenceGenerator.Gaussian (iNumTimeStep);

  100.         double[] adblDefaultIndicatorTimeSeries = SequenceGenerator.Uniform (iNumTimeStep);

  101.         JumpDiffusionEdge[] aR1AssetLR = meAsset.incrementSequence (
  102.             new JumpDiffusionVertex (
  103.                 0.,
  104.                 dblTerminalAssetNumeraire,
  105.                 0.,
  106.                 false
  107.             ),
  108.             JumpDiffusionEdgeUnit.JumpDiffusion (
  109.                 adblTimeWidth,
  110.                 adblAssetNumeraireTimeSeries,
  111.                 adblDefaultIndicatorTimeSeries
  112.             ),
  113.             dblTimeWidth
  114.         );

  115.         System.out.println();

  116.         for (int i = 0; i < iNumTimeStep; ++i) {
  117.             dblTime = dblTime + dblTimeWidth;

  118.             System.out.println (
  119.                 "\t|| " +
  120.                 FormatUtil.FormatDouble (dblTime, 1, 6, 1.) + " => " +
  121.                 FormatUtil.FormatDouble (aR1AssetLR[i].start(), 1, 4, 1.) + " | " +
  122.                 FormatUtil.FormatDouble (aR1AssetLR[i].finish(), 1, 4, 1.) + " | " +
  123.                 FormatUtil.FormatDouble (aR1AssetLR[i].diffusionWander(), 1, 4, 1.) + " | " +
  124.                 aR1AssetLR[i].stochasticJumpEdge().jumpOccurred() + " ||"
  125.             );
  126.         }

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