ConvexityAdjustment.java

  1. package org.drip.analytics.output;

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

  79. /**
  80.  * <i>ConvexityAdjustment</i> holds the dynamical convexity Adjustments between the Latent States.
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  86.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/README.md">Date, Cash Flow, and Cash Flow Period Measure Generation Utilities</a></li>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/output/README.md">Period Product Targeted Valuation Measures</a></li>
  88.  *  </ul>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class ConvexityAdjustment {
  93.     private double _dblCollateralCredit = 1.;
  94.     private double _dblCollateralForward = 1.;
  95.     private double _dblCollateralFunding = 1.;
  96.     private double _dblCollateralFX = 1.;
  97.     private double _dblCreditForward = 1.;
  98.     private double _dblCreditFunding = 1.;
  99.     private double _dblCreditFX = 1.;
  100.     private double _dblForwardFunding = 1.;
  101.     private double _dblForwardFX = 1.;
  102.     private double _dblFundingFX = 1.;

  103.     /**
  104.      * Empty ConvexityAdjustment Constructor
  105.      */

  106.     public ConvexityAdjustment()
  107.     {
  108.     }

  109.     /**
  110.      * Set the Collateral/Credit Convexity Adjustment
  111.      *
  112.      * @param dblCollateralCredit The Collateral/Credit Convexity Adjustment
  113.      *
  114.      * @return TRUE - The Collateral/Credit Convexity Adjustment successfully set
  115.      */

  116.     public boolean setCollateralCredit (
  117.         final double dblCollateralCredit)
  118.     {
  119.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCollateralCredit)) return false;

  120.         _dblCollateralCredit = dblCollateralCredit;
  121.         return true;
  122.     }

  123.     /**
  124.      * Retrieve the Collateral/Credit Convexity Adjustment
  125.      *
  126.      * @return The Collateral/Credit Convexity Adjustment
  127.      */

  128.     public double collateralCredit()
  129.     {
  130.         return _dblCollateralCredit;
  131.     }

  132.     /**
  133.      * Set the Collateral/Forward Convexity Adjustment
  134.      *
  135.      * @param dblCollateralForward The Collateral/Forward Convexity Adjustment
  136.      *
  137.      * @return TRUE - The Collateral/Forward Convexity Adjustment successfully set
  138.      */

  139.     public boolean setCollateralForward (
  140.         final double dblCollateralForward)
  141.     {
  142.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCollateralForward)) return false;

  143.         _dblCollateralForward = dblCollateralForward;
  144.         return true;
  145.     }

  146.     /**
  147.      * Retrieve the Collateral/Forward Convexity Adjustment
  148.      *
  149.      * @return The Collateral/Forward Convexity Adjustment
  150.      */

  151.     public double collateralForward()
  152.     {
  153.         return _dblCollateralForward;
  154.     }

  155.     /**
  156.      * Set the Collateral/Funding Convexity Adjustment
  157.      *
  158.      * @param dblCollateralFunding The Collateral/Funding Convexity Adjustment
  159.      *
  160.      * @return TRUE - The Collateral/Funding Convexity Adjustment successfully set
  161.      */

  162.     public boolean setCollateralFunding (
  163.         final double dblCollateralFunding)
  164.     {
  165.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCollateralFunding)) return false;

  166.         _dblCollateralFunding = dblCollateralFunding;
  167.         return true;
  168.     }

  169.     /**
  170.      * Retrieve the Collateral/Funding Convexity Adjustment
  171.      *
  172.      * @return The Collateral/Funding Convexity Adjustment
  173.      */

  174.     public double collateralFunding()
  175.     {
  176.         return _dblCollateralFunding;
  177.     }

  178.     /**
  179.      * Set the Collateral/FX Convexity Adjustment
  180.      *
  181.      * @param dblCollateralFX The Collateral/FX Convexity Adjustment
  182.      *
  183.      * @return TRUE - The Collateral/FX Convexity Adjustment successfully set
  184.      */

  185.     public boolean setCollateralFX (
  186.         final double dblCollateralFX)
  187.     {
  188.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCollateralFX)) return false;

  189.         _dblCollateralFX = dblCollateralFX;
  190.         return true;
  191.     }

  192.     /**
  193.      * Retrieve the Collateral/FX Convexity Adjustment
  194.      *
  195.      * @return The Collateral/FX Convexity Adjustment
  196.      */

  197.     public double collateralFX()
  198.     {
  199.         return _dblCollateralFX;
  200.     }

  201.     /**
  202.      * Set the Credit/Forward Convexity Adjustment
  203.      *
  204.      * @param dblCreditForward The Credit/Forward Convexity Adjustment
  205.      *
  206.      * @return TRUE - The Credit/Forward Convexity Adjustment successfully set
  207.      */

  208.     public boolean setCreditForward (
  209.         final double dblCreditForward)
  210.     {
  211.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCreditForward)) return false;

  212.         _dblCreditForward = dblCreditForward;
  213.         return true;
  214.     }

  215.     /**
  216.      * Retrieve the Credit/Forward Convexity Adjustment
  217.      *
  218.      * @return The Credit/Forward Convexity Adjustment
  219.      */

  220.     public double creditForward()
  221.     {
  222.         return _dblCreditForward;
  223.     }

  224.     /**
  225.      * Set the Credit/Funding Convexity Adjustment
  226.      *
  227.      * @param dblCreditFunding The Credit/Funding Convexity Adjustment
  228.      *
  229.      * @return TRUE - The Credit/Funding Convexity Adjustment successfully set
  230.      */

  231.     public boolean setCreditFunding (
  232.         final double dblCreditFunding)
  233.     {
  234.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCreditFunding)) return false;

  235.         _dblCreditFunding = dblCreditFunding;
  236.         return true;
  237.     }

  238.     /**
  239.      * Retrieve the Credit/Funding Convexity Adjustment
  240.      *
  241.      * @return The Credit/Funding Convexity Adjustment
  242.      */

  243.     public double creditFunding()
  244.     {
  245.         return _dblCreditFunding;
  246.     }

  247.     /**
  248.      * Set the Credit/FX Convexity Adjustment
  249.      *
  250.      * @param dblCreditFX The Credit/FX Convexity Adjustment
  251.      *
  252.      * @return TRUE - The Credit/FX Convexity Adjustment successfully set
  253.      */

  254.     public boolean setCreditFX (
  255.         final double dblCreditFX)
  256.     {
  257.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCreditFX)) return false;

  258.         _dblCreditFX = dblCreditFX;
  259.         return true;
  260.     }

  261.     /**
  262.      * Retrieve the Credit/FX Convexity Adjustment
  263.      *
  264.      * @return The Credit/FX Convexity Adjustment
  265.      */

  266.     public double creditFX()
  267.     {
  268.         return _dblCreditFX;
  269.     }

  270.     /**
  271.      * Set the Forward/Funding Convexity Adjustment
  272.      *
  273.      * @param dblForwardFunding The Forward/Funding Convexity Adjustment
  274.      *
  275.      * @return TRUE - The Forward/Funding Convexity Adjustment successfully set
  276.      */

  277.     public boolean setForwardFunding (
  278.         final double dblForwardFunding)
  279.     {
  280.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblForwardFunding)) return false;

  281.         _dblForwardFunding = dblForwardFunding;
  282.         return true;
  283.     }

  284.     /**
  285.      * Retrieve the Forward/Funding Convexity Adjustment
  286.      *
  287.      * @return The Forward/Funding Convexity Adjustment
  288.      */

  289.     public double forwardFunding()
  290.     {
  291.         return _dblForwardFunding;
  292.     }

  293.     /**
  294.      * Set the Forward/FX Convexity Adjustment
  295.      *
  296.      * @param dblForwardFX The Forward/FX Convexity Adjustment
  297.      *
  298.      * @return TRUE - The Forward/FX Convexity Adjustment successfully set
  299.      */

  300.     public boolean setForwardFX (
  301.         final double dblForwardFX)
  302.     {
  303.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblForwardFX)) return false;

  304.         _dblForwardFX = dblForwardFX;
  305.         return true;
  306.     }

  307.     /**
  308.      * Retrieve the Forward/FX Convexity Adjustment
  309.      *
  310.      * @return The Forward/FX Convexity Adjustment
  311.      */

  312.     public double forwardFX()
  313.     {
  314.         return _dblForwardFX;
  315.     }

  316.     /**
  317.      * Set the Funding/FX Convexity Adjustment
  318.      *
  319.      * @param dblFundingFX The Funding/FX Convexity Adjustment
  320.      *
  321.      * @return TRUE - The Funding/FX Convexity Adjustment successfully set
  322.      */

  323.     public boolean setFundingFX (
  324.         final double dblFundingFX)
  325.     {
  326.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblFundingFX)) return false;

  327.         _dblFundingFX = dblFundingFX;
  328.         return true;
  329.     }

  330.     /**
  331.      * Retrieve the Funding/FX Convexity Adjustment
  332.      *
  333.      * @return The Funding/FX Convexity Adjustment
  334.      */

  335.     public double fundingFX()
  336.     {
  337.         return _dblFundingFX;
  338.     }

  339.     /**
  340.      * Retrieve the Cumulative Convexity Correction
  341.      *
  342.      * @return The Cumulative Convexity Correction
  343.      */

  344.     public double cumulative()
  345.     {
  346.         return _dblCollateralCredit * _dblCollateralForward * _dblCollateralFunding * _dblCollateralFX *
  347.             _dblCreditForward * _dblCreditFunding * _dblCreditFX * _dblForwardFunding * _dblForwardFX *
  348.                 _dblFundingFX;
  349.     }
  350. }