UnivariateSequence.java

  1. package org.drip.sample.statistics;

  2. import org.drip.feed.loader.*;
  3. import org.drip.measure.statistics.UnivariateMoments;
  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.  * Copyright (C) 2016 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.  * UnivariateSequence demonstrates the Generation of the Statistical Measures for the Input Series of
  53.  *  Univariate Sequences.
  54.  *
  55.  * @author Lakshmi Krishnamurthy
  56.  */

  57. public class UnivariateSequence {

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

  63.         String strSeriesLocation = "C:\\DRIP\\CreditAnalytics\\Daemons\\Feeds\\MeanVarianceOptimizer\\FormattedSeries1.csv";

  64.         CSVGrid csvGrid = CSVParser.NamedStringGrid (strSeriesLocation);

  65.         UnivariateMoments mvTOK = UnivariateMoments.Standard (
  66.             csvGrid.header (1),
  67.             csvGrid.doubleArrayAtColumn (1)
  68.         );

  69.         UnivariateMoments mvEWJ = UnivariateMoments.Standard (
  70.             csvGrid.header (2),
  71.             csvGrid.doubleArrayAtColumn (2)
  72.         );

  73.         UnivariateMoments mvHYG = UnivariateMoments.Standard (
  74.             csvGrid.header (3),
  75.             csvGrid.doubleArrayAtColumn (3)
  76.         );

  77.         UnivariateMoments mvLQD = UnivariateMoments.Standard (
  78.             csvGrid.header (4),
  79.             csvGrid.doubleArrayAtColumn (4)
  80.         );

  81.         UnivariateMoments mvEMD = UnivariateMoments.Standard (
  82.             csvGrid.header (5),
  83.             csvGrid.doubleArrayAtColumn (5)
  84.         );

  85.         UnivariateMoments mvGSG = UnivariateMoments.Standard (
  86.             csvGrid.header (6),
  87.             csvGrid.doubleArrayAtColumn (6)
  88.         );

  89.         UnivariateMoments mvBWX = UnivariateMoments.Standard (
  90.             csvGrid.header (7),
  91.             csvGrid.doubleArrayAtColumn (7)
  92.         );

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

  94.         System.out.println (
  95.             "\t| " + mvTOK.name() + " | " +
  96.             FormatUtil.FormatDouble (mvTOK.mean(), 1, 2, 1200) + "% | " +
  97.             FormatUtil.FormatDouble (mvTOK.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  98.             mvTOK.numSample() + " ||"
  99.         );

  100.         System.out.println (
  101.             "\t| " + mvEWJ.name() + " | " +
  102.             FormatUtil.FormatDouble (mvEWJ.mean(), 1, 2, 1200) + "% | " +
  103.             FormatUtil.FormatDouble (mvEWJ.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  104.             mvEWJ.numSample() + " ||"
  105.         );

  106.         System.out.println (
  107.             "\t| " + mvHYG.name() + " | " +
  108.             FormatUtil.FormatDouble (mvHYG.mean(), 1, 2, 1200) + "% | " +
  109.             FormatUtil.FormatDouble (mvHYG.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  110.             mvHYG.numSample() + " ||"
  111.         );

  112.         System.out.println (
  113.             "\t| " + mvLQD.name() + " | " +
  114.             FormatUtil.FormatDouble (mvLQD.mean(), 1, 2, 1200) + "% | " +
  115.             FormatUtil.FormatDouble (mvLQD.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  116.             mvLQD.numSample() + " ||"
  117.         );

  118.         System.out.println (
  119.             "\t| " + mvEMD.name() + " | " +
  120.             FormatUtil.FormatDouble (mvEMD.mean(), 1, 2, 1200) + "% | " +
  121.             FormatUtil.FormatDouble (mvEMD.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  122.             mvEMD.numSample() + " ||"
  123.         );

  124.         System.out.println (
  125.             "\t| " + mvGSG.name() + " | " +
  126.             FormatUtil.FormatDouble (mvGSG.mean(), 1, 2, 1200) + "% | " +
  127.             FormatUtil.FormatDouble (mvGSG.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  128.             mvGSG.numSample() + " ||"
  129.         );

  130.         System.out.println (
  131.             "\t| " + mvBWX.name() + " | " +
  132.             FormatUtil.FormatDouble (mvBWX.mean(), 1, 2, 1200) + "% | " +
  133.             FormatUtil.FormatDouble (mvBWX.stdDev(), 2, 1, 100 * Math.sqrt (12)) + "% | " +
  134.             mvBWX.numSample() + " ||"
  135.         );

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