RdMultiPathQR.java

  1. package org.drip.sample.rng;

  2. import java.util.List;

  3. import org.drip.measure.crng.RandomNumberGenerator;
  4. import org.drip.measure.discrete.*;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.service.env.EnvManager;

  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.  * RdMultiPathQR illustrates the Generation of the Multi-Path Correlated Random Variables using Quadratic
  53.  *  Re-sampling but without Antithetic Variables.
  54.  *
  55.  * @author Lakshmi Krishnamurthy
  56.  */

  57. public class RdMultiPathQR {

  58.     public static final void main (
  59.         final String[] astrArgs)
  60.         throws Exception
  61.     {
  62.         EnvManager.InitEnv ("");

  63.         int iNumPath = 1;
  64.         int iNumVertex = 50;
  65.         boolean bDebias = false;
  66.         boolean bMeanCenter = false;
  67.         boolean bApplyAntithetic = false;

  68.         double[][] aadblCorrelation = new double[][] {
  69.             {1.000, 0.161, 0.245, 0.352, 0.259, 0.166, 0.003, 0.038, 0.114},    // USD_LIBOR_3M
  70.             {0.161, 1.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000},    // EUR_LIBOR_3M
  71.             {0.245, 0.000, 1.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000},    // JPY_LIBOR_3M
  72.             {0.352, 0.000, 0.000, 1.000, 0.000, 0.000, 0.000, 0.000, 0.000},    // CHF_LIBOR_3M
  73.             {0.259, 0.000, 0.000, 0.000, 1.000, 0.000, 0.000, 0.000, 0.000},    // GBP_LIBOR_3M
  74.             {0.166, 0.000, 0.000, 0.000, 0.000, 1.000, 0.000, 0.000, 0.000},    // EURUSD
  75.             {0.003, 0.000, 0.000, 0.000, 0.000, 0.000, 1.000, 0.000, 0.000},    // JPYUSD
  76.             {0.038, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 1.000, 0.000},    // CHFUSD
  77.             {0.114, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 1.000},    // GBPUSD
  78.         };

  79.         CorrelatedPathVertexDimension cpvd = new CorrelatedPathVertexDimension (
  80.             new RandomNumberGenerator(),
  81.             aadblCorrelation,
  82.             iNumVertex,
  83.             iNumPath,
  84.             bApplyAntithetic,
  85.             new QuadraticResampler (
  86.                 bMeanCenter,
  87.                 bDebias
  88.             )
  89.         );

  90.         VertexRd vertexRd = cpvd.multiPathVertexRd()[0];

  91.         List<double[]> lsVertexRd = vertexRd.vertexList();

  92.         System.out.println();

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

  94.         for (int i = 0; i < lsVertexRd.size(); ++i) {
  95.             double[] adblRd = lsVertexRd.get (i);

  96.             String strDump = "\t||" + FormatUtil.FormatDouble (i, 2, 0, 1.) + " => ";

  97.             for (int j = 0; j < adblRd.length; ++j)
  98.                 strDump = strDump + FormatUtil.FormatDouble (adblRd[j], 1, 5, 1.) + " |";

  99.             System.out.println (strDump + "|");
  100.         }

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

  102.         System.out.println();
  103.     }
  104. }