BrownianBridgeLinear.java

  1. package org.drip.sample.measure;

  2. import org.drip.analytics.date.*;
  3. import org.drip.measure.bridge.BrokenDateInterpolatorBrownian3P;
  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) 2019 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  15.  *      calculations, valuation adjustment, and portfolio construction within and across fixed income,
  16.  *      credit, commodity, equity, FX, and structured products.
  17.  *  
  18.  *      https://lakshmidrip.github.io/DROP/
  19.  *  
  20.  *  DROP is composed of three modules:
  21.  *  
  22.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  23.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  24.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  25.  *
  26.  *  DROP Analytics Core implements libraries for the following:
  27.  *  - Fixed Income Analytics
  28.  *  - Asset Backed Analytics
  29.  *  - XVA Analytics
  30.  *  - Exposure and Margin Analytics
  31.  *
  32.  *  DROP Portfolio Core implements libraries for the following:
  33.  *  - Asset Allocation Analytics
  34.  *  - Transaction Cost Analytics
  35.  *
  36.  *  DROP Numerical Core implements libraries for the following:
  37.  *  - Statistical Learning
  38.  *  - Numerical Optimizer
  39.  *  - Spline Builder
  40.  *  - Algorithm Support
  41.  *
  42.  *  Documentation for DROP is Spread Over:
  43.  *
  44.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  45.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  46.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  47.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  48.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  49.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  50.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  51.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  52.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  53.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  54.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  55.  *
  56.  *  Licensed under the Apache License, Version 2.0 (the "License");
  57.  *      you may not use this file except in compliance with the License.
  58.  *  
  59.  *  You may obtain a copy of the License at
  60.  *      http://www.apache.org/licenses/LICENSE-2.0
  61.  *  
  62.  *  Unless required by applicable law or agreed to in writing, software
  63.  *      distributed under the License is distributed on an "AS IS" BASIS,
  64.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  65.  *  
  66.  *  See the License for the specific language governing permissions and
  67.  *      limitations under the License.
  68.  */

  69. /**
  70.  * <i>BrownianBridgeLinear</i> demonstrates using the Brownian Bridge Scheme to Interpolate Three Linear
  71.  * Value Points.
  72.  *  
  73.  * <br><br>
  74.  *  <ul>
  75.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  76.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalSupportLibrary.md">Numerical Support Library</a></li>
  77.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  78.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/measure/README.md">Probability Measure Generators</a></li>
  79.  *  </ul>
  80.  * <br><br>
  81.  *
  82.  * @author Lakshmi Krishnamurthy
  83.  */

  84. public class BrownianBridgeLinear {

  85.     public static final void main (
  86.         final String[] astrArgs)
  87.         throws Exception
  88.     {
  89.         EnvManager.InitEnv ("");

  90.         JulianDate dt1 = DateUtil.CreateFromYMD (
  91.             2015,
  92.             DateUtil.JULY,
  93.             1
  94.         );

  95.         JulianDate dt2 = DateUtil.CreateFromYMD (
  96.             2015,
  97.             DateUtil.AUGUST,
  98.             1
  99.         );

  100.         JulianDate dt3 = DateUtil.CreateFromYMD (
  101.             2015,
  102.             DateUtil.SEPTEMBER,
  103.             1
  104.         );

  105.         double dblV1 = 10.;
  106.         double dblV2 = 15.;
  107.         double dblV3 = 20.;

  108.         int iDaysStep = 2;

  109.         BrokenDateInterpolatorBrownian3P tpbb = new BrokenDateInterpolatorBrownian3P (
  110.             dt1.julian(),
  111.             dt2.julian(),
  112.             dt3.julian(),
  113.             dblV1,
  114.             dblV2,
  115.             dblV3
  116.         );

  117.         System.out.println();

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

  119.         System.out.println ("\t||  BROWNIAN BRIDGE LINEAR  ||");

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

  121.         System.out.println (
  122.             "\t|| [" + dt1 + "] => " +
  123.             FormatUtil.FormatDouble (tpbb.interpolate (dt1.julian()), 2, 3, 1.) + " ||"
  124.         );

  125.         JulianDate dt = dt1.addDays (iDaysStep);

  126.         while (dt.julian() < dt3.julian()) {
  127.             System.out.println (
  128.                 "\t|| [" + dt + "] => " +
  129.                 FormatUtil.FormatDouble (tpbb.interpolate (dt.julian()), 2, 3, 1.) + " ||"
  130.             );

  131.             dt = dt.addDays (iDaysStep);
  132.         }

  133.         System.out.println (
  134.             "\t|| [" + dt3 + "] => " +
  135.             FormatUtil.FormatDouble (tpbb.interpolate (dt3.julian()), 2, 3, 1.) + " ||"
  136.         );

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

  138.         System.out.println();

  139.         EnvManager.TerminateEnv();
  140.     }
  141. }