GovvieBuilderSettings.java

  1. package org.drip.state.sequence;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  10.  *
  11.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  12.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  13.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  14.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  15.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  16.  *      and computational support.
  17.  *  
  18.  *      https://lakshmidrip.github.io/DROP/
  19.  *  
  20.  *  DROP is composed of three modules:
  21.  *  
  22.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  23.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  24.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  25.  *
  26.  *  DROP Product Core implements libraries for the following:
  27.  *  - Fixed Income Analytics
  28.  *  - Loan Analytics
  29.  *  - Transaction Cost Analytics
  30.  *
  31.  *  DROP Portfolio Core implements libraries for the following:
  32.  *  - Asset Allocation Analytics
  33.  *  - Asset Liability Management Analytics
  34.  *  - Capital Estimation Analytics
  35.  *  - Exposure Analytics
  36.  *  - Margin Analytics
  37.  *  - XVA Analytics
  38.  *
  39.  *  DROP Computational Core implements libraries for the following:
  40.  *  - Algorithm Support
  41.  *  - Computation Support
  42.  *  - Function Analysis
  43.  *  - Model Validation
  44.  *  - Numerical Analysis
  45.  *  - Numerical Optimizer
  46.  *  - Spline Builder
  47.  *  - Statistical Learning
  48.  *
  49.  *  Documentation for DROP is Spread Over:
  50.  *
  51.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  52.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  53.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  54.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  55.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  56.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  57.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  58.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  59.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  60.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  61.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  62.  *
  63.  *  Licensed under the Apache License, Version 2.0 (the "License");
  64.  *      you may not use this file except in compliance with the License.
  65.  *  
  66.  *  You may obtain a copy of the License at
  67.  *      http://www.apache.org/licenses/LICENSE-2.0
  68.  *  
  69.  *  Unless required by applicable law or agreed to in writing, software
  70.  *      distributed under the License is distributed on an "AS IS" BASIS,
  71.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  72.  *  
  73.  *  See the License for the specific language governing permissions and
  74.  *      limitations under the License.
  75.  */

  76. /**
  77.  * <i>GovvieBuilderSettings</i> exposes the Functionality to generate a Sequence of Govvie Curve Realizations
  78.  * across Multiple Paths.
  79.  *
  80.  *  <br><br>
  81.  *  <ul>
  82.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  83.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  84.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/README.md">Latent State Inference and Creation Utilities</a></li>
  85.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/sequence/README.md">Monte Carlo Path State Realizations</a></li>
  86.  *  </ul>
  87.  * <br><br>
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class GovvieBuilderSettings {
  92.     private double[] _adblTreasuryYield = null;
  93.     private double[] _adblTreasuryCoupon = null;
  94.     private java.lang.String[] _astrTenor = null;
  95.     private java.lang.String _strTreasuryCode = "";
  96.     private double[] _adblForwardYieldGround = null;
  97.     private org.drip.analytics.date.JulianDate _dtSpot = null;
  98.     private org.drip.state.curve.BasisSplineGovvieYield _bsgyGround = null;

  99.     protected static final org.drip.state.curve.BasisSplineGovvieYield GovvieCurve (
  100.         final org.drip.analytics.date.JulianDate dtSpot,
  101.         final java.lang.String strCode,
  102.         final java.lang.String[] astrTenor,
  103.         final double[] adblCoupon,
  104.         final double[] adblYield)
  105.         throws Exception
  106.     {
  107.         int iNumInstrument = astrTenor.length;
  108.         org.drip.analytics.date.JulianDate[] adtMaturity = new
  109.             org.drip.analytics.date.JulianDate[iNumInstrument];
  110.         org.drip.analytics.date.JulianDate[] adtEffective = new
  111.             org.drip.analytics.date.JulianDate[iNumInstrument];

  112.         for (int i = 0; i < iNumInstrument; ++i)
  113.             adtMaturity[i] = (adtEffective[i] = dtSpot).addTenor (astrTenor[i]);

  114.         return (org.drip.state.curve.BasisSplineGovvieYield)
  115.             org.drip.service.template.LatentMarketStateBuilder.GovvieCurve (strCode, dtSpot, adtEffective,
  116.                 adtMaturity, adblCoupon, adblYield, "Yield",
  117.                     org.drip.service.template.LatentMarketStateBuilder.SHAPE_PRESERVING);
  118.     }

  119.     /**
  120.      * GovvieBuilderSettings Constructor
  121.      *
  122.      * @param dtSpot The Spot Date
  123.      * @param strTreasuryCode The Treasury Code
  124.      * @param astrTenor Array of Maturity Tenors
  125.      * @param adblTreasuryCoupon Array of Treasury Coupon
  126.      * @param adblTreasuryYield Array of Treasury Yield
  127.      *
  128.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  129.      */

  130.     public GovvieBuilderSettings (
  131.         final org.drip.analytics.date.JulianDate dtSpot,
  132.         final java.lang.String strTreasuryCode,
  133.         final java.lang.String[] astrTenor,
  134.         final double[] adblTreasuryCoupon,
  135.         final double[] adblTreasuryYield)
  136.         throws java.lang.Exception
  137.     {
  138.         if (null == (_bsgyGround = GovvieCurve (_dtSpot = dtSpot, _strTreasuryCode = strTreasuryCode,
  139.             _astrTenor = astrTenor, _adblTreasuryCoupon = adblTreasuryCoupon, _adblTreasuryYield =
  140.                 adblTreasuryYield)))
  141.             throw new java.lang.Exception ("GovvieBuilderSettings Constructor => Invalid Inputs");

  142.         org.drip.state.nonlinear.FlatForwardDiscountCurve ffdcGround = _bsgyGround.flatForward (_astrTenor);

  143.         if (null == ffdcGround || null == (_adblForwardYieldGround = ffdcGround.nodeValues()))
  144.             throw new java.lang.Exception ("GovvieBuilderSettings Constructor => Invalid Inputs");
  145.     }

  146.     /**
  147.      * Retrieve the Spot Date
  148.      *
  149.      * @return The Spot Date
  150.      */

  151.     public org.drip.analytics.date.JulianDate spot()
  152.     {
  153.         return _dtSpot;
  154.     }

  155.     /**
  156.      * Retrieve the Treasury Code
  157.      *
  158.      * @return The Treasury Code
  159.      */

  160.     public java.lang.String code()
  161.     {
  162.         return _strTreasuryCode;
  163.     }

  164.     /**
  165.      * Retrieve the Treasury Maturity Tenor Array
  166.      *
  167.      * @return The Treasury Maturity Tenor Array
  168.      */

  169.     public java.lang.String[] tenors()
  170.     {
  171.         return _astrTenor;
  172.     }

  173.     /**
  174.      * Retrieve the Calibration Treasury Coupon Array
  175.      *
  176.      * @return The Calibration Treasury Coupon Array
  177.      */

  178.     public double[] coupon()
  179.     {
  180.         return _adblTreasuryCoupon;
  181.     }

  182.     /**
  183.      * Retrieve the Calibration Treasury Yield Array
  184.      *
  185.      * @return The Calibration Treasury Yield Array
  186.      */

  187.     public double[] yield()
  188.     {
  189.         return _adblTreasuryYield;
  190.     }

  191.     /**
  192.      * Retrieve the Ground State Govvie Curve
  193.      *
  194.      * @return The Ground State Govvie Curve
  195.      */

  196.     public org.drip.state.curve.BasisSplineGovvieYield groundState()
  197.     {
  198.         return _bsgyGround;
  199.     }

  200.     /**
  201.      * Retrieve the Ground Forward Yield Array
  202.      *
  203.      * @return The Ground Forward Yield Array
  204.      */

  205.     public double[] groundForwardYield()
  206.     {
  207.         return _adblForwardYieldGround;
  208.     }

  209.     /**
  210.      * Retrieve the Calibration Instrument Dimension
  211.      *
  212.      * @return The Calibration Instrument Dimension
  213.      */

  214.     public int dimension()
  215.     {
  216.         return _astrTenor.length;
  217.     }
  218. }