EOSMetricsReplicator.java

  1. package org.drip.service.scenario;

  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>EOSMetricsReplicator</i> generates the EOS Metrics for Bonds with Embedded Option Schedules.
  78.  *
  79.  * <br><br>
  80.  *  <ul>
  81.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  82.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationSupportLibrary.md">Computation Support</a></li>
  83.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/service/README.md">Environment, Product/Definition Containers, and Scenario/State Manipulation APIs</a></li>
  84.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/service/scenario/README.md">Custom Scenario Service Metric Generator</a></li>
  85.  *  </ul>
  86.  * <br><br>
  87.  *
  88.  * @author Lakshmi Krishnamurthy
  89.  */

  90. public class EOSMetricsReplicator
  91. {
  92.     private int _iNumPath = -1;
  93.     private double _dblPrice = java.lang.Double.NaN;
  94.     private org.drip.product.credit.BondComponent _bond = null;
  95.     private org.drip.measure.process.DiffusionEvolver _de = null;
  96.     private org.drip.state.sequence.GovvieBuilderSettings _gbs = null;
  97.     private org.drip.param.valuation.ValuationParams _valParams = null;
  98.     private org.drip.param.market.CurveSurfaceQuoteContainer _csqc = null;

  99.     /**
  100.      * Standard Static EOSMetricsReplicator Creator
  101.      *
  102.      * @param bond Bond Instance
  103.      * @param valParams Valuation Parameters
  104.      * @param csqc Market Parameters
  105.      * @param gbs Govvie Builder Settings
  106.      * @param dblLogNormalVolatility Long Normal Treasury Forward Volatility
  107.      * @param dblPrice Market Price
  108.      *
  109.      * @return EOSMetricsReplicator Instance
  110.      */

  111.     public static final EOSMetricsReplicator Standard (
  112.         final org.drip.product.credit.BondComponent bond,
  113.         final org.drip.param.valuation.ValuationParams valParams,
  114.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  115.         final org.drip.state.sequence.GovvieBuilderSettings gbs,
  116.         final double dblLogNormalVolatility,
  117.         final double dblPrice)
  118.     {
  119.         try {
  120.             return new EOSMetricsReplicator (
  121.                 bond,
  122.                 valParams,
  123.                 csqc,
  124.                 gbs,
  125.                 new org.drip.measure.process.DiffusionEvolver (
  126.                     org.drip.measure.dynamics.DiffusionEvaluatorLogarithmic.Standard (
  127.                         0.,
  128.                         dblLogNormalVolatility
  129.                     )
  130.                 ),
  131.                 50,
  132.                 dblPrice
  133.             );
  134.         } catch (java.lang.Exception e) {
  135.             e.printStackTrace();
  136.         }

  137.         return null;
  138.     }

  139.     /**
  140.      * EOSMetricsReplicator Constructor
  141.      *
  142.      * @param bond Bond Instance
  143.      * @param valParams Valuation Parameters
  144.      * @param csqc Market Parameters
  145.      * @param gbs Govvie Builder Settings
  146.      * @param de Diffusion Evolver
  147.      * @param iNumPath Number of Simulation Paths
  148.      * @param dblPrice Market Price
  149.      *
  150.      * @throws java.lang.Exception Thrown if the Inputs are Invalid/Inconsistent
  151.      */

  152.     public EOSMetricsReplicator (
  153.         final org.drip.product.credit.BondComponent bond,
  154.         final org.drip.param.valuation.ValuationParams valParams,
  155.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  156.         final org.drip.state.sequence.GovvieBuilderSettings gbs,
  157.         final org.drip.measure.process.DiffusionEvolver de,
  158.         final int iNumPath,
  159.         final double dblPrice)
  160.         throws java.lang.Exception
  161.     {
  162.         if (null == (_bond = bond) || (!_bond.callable() && _bond.putable()) ||
  163.             null == (_valParams = valParams) ||
  164.             null == (_csqc = csqc) ||
  165.             null == (_gbs = gbs) ||
  166.             null == (_de = de) ||
  167.             0 >= (_iNumPath = iNumPath) ||
  168.             !org.drip.numerical.common.NumberUtil.IsValid (_dblPrice = dblPrice))
  169.             throw new java.lang.Exception ("EOSMetricsReplicator Constructor => Invalid Inputs");
  170.     }

  171.     /**
  172.      * Retrieve the Underlying Bond
  173.      *
  174.      * @return The Underlying Bond
  175.      */

  176.     public org.drip.product.credit.BondComponent bond()
  177.     {
  178.         return _bond;
  179.     }

  180.     /**
  181.      * Retrieve the Valuation Parameters
  182.      *
  183.      * @return The Valuation Parameters
  184.      */

  185.     public org.drip.param.valuation.ValuationParams valuationParameters()
  186.     {
  187.         return _valParams;
  188.     }

  189.     /**
  190.      * Retrieve the Market Parameters
  191.      *
  192.      * @return The Market Parameters
  193.      */

  194.     public org.drip.param.market.CurveSurfaceQuoteContainer marketParameters()
  195.     {
  196.         return _csqc;
  197.     }

  198.     /**
  199.      * Retrieve the Price
  200.      *
  201.      * @return The Price
  202.      */

  203.     public double price()
  204.     {
  205.         return _dblPrice;
  206.     }

  207.     /**
  208.      * Retrieve the Diffusion Evolver
  209.      *
  210.      * @return The Diffusion Evolver
  211.      */

  212.     public org.drip.measure.process.DiffusionEvolver diffusionEvolver()
  213.     {
  214.         return _de;
  215.     }

  216.     /**
  217.      * Retrieve the Govvie Builder Settings
  218.      *
  219.      * @return The Govvie Builder Settings
  220.      */

  221.     public org.drip.state.sequence.GovvieBuilderSettings govvieBuilderSetting()
  222.     {
  223.         return _gbs;
  224.     }

  225.     /**
  226.      * Retrieve the Number of Simulation Paths
  227.      *
  228.      * @return The Number of Simulation Paths
  229.      */

  230.     public int numPath()
  231.     {
  232.         return _iNumPath;
  233.     }

  234.     /**
  235.      * Generate an Instance of a Replication Run
  236.      *
  237.      * @return Instance of a Replication Run
  238.      */

  239.     public org.drip.analytics.output.BondEOSMetrics generateRun()
  240.     {
  241.         return _bond.callable() ? _bond.callMetrics (
  242.             _valParams,
  243.             _csqc,
  244.             null,
  245.             _dblPrice,
  246.             _gbs,
  247.             _de,
  248.             _iNumPath
  249.         ) :  _bond.putMetrics (
  250.             _valParams,
  251.             _csqc,
  252.             null,
  253.             _dblPrice,
  254.             _gbs,
  255.             _de,
  256.             _iNumPath
  257.         );
  258.     }
  259. }