INR.java

  1. package org.drip.template.irs;

  2. import java.util.Map;

  3. import org.drip.analytics.cashflow.CompositePeriod;
  4. import org.drip.analytics.date.*;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.param.market.CurveSurfaceQuoteContainer;
  7. import org.drip.param.valuation.ValuationParams;
  8. import org.drip.product.rates.FixFloatComponent;
  9. import org.drip.service.env.EnvManager;
  10. import org.drip.service.template.*;

  11. /*
  12.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  13.  */

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

  87. /**
  88.  * <i>INR</i> contains a Templated Pricing of the OTC Fix-Float INR IRS Instrument.
  89.  *
  90.  *  <br><br>
  91.  *  <ul>
  92.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  93.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  94.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/README.md">Pricing/Risk Templates for Fixed Income Component Products</a></li>
  95.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/irs/README.md">Standard IRS Fix-Float Template</a></li>
  96.  *  </ul>
  97.  * <br><br>
  98.  *
  99.  * @author Lakshmi Krishnamurthy
  100.  */

  101. public class INR {

  102.     public static final void main (
  103.         final String[] args)
  104.         throws Exception
  105.     {
  106.         EnvManager.InitEnv ("");

  107.         JulianDate dtSpot = DateUtil.Today();

  108.         String strCurrency = "INR";
  109.         String strMaturityTenor = "5Y";

  110.         FixFloatComponent irs = OTCInstrumentBuilder.FixFloatStandard (
  111.             dtSpot,
  112.             strCurrency,
  113.             "ALL",
  114.             strMaturityTenor,
  115.             "MAIN",
  116.             0.0206
  117.         );

  118.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  119.         csqc.setFundingState (
  120.             LatentMarketStateBuilder.SmoothFundingCurve (
  121.                 dtSpot,
  122.                 strCurrency,
  123.                 new String[] {
  124.                     "04D", "07D", "14D", "30D", "60D"
  125.                 },
  126.                 new double[] {
  127.                     0.0017, 0.0017, 0.0018, 0.0020, 0.0023
  128.                 },
  129.                 "ForwardRate",
  130.                 new double[] {
  131.                     0.0027, 0.0032, 0.0041, 0.0054, 0.0077, 0.0104, 0.0134, 0.0160
  132.                 },
  133.                 "ForwardRate",
  134.                 new String[] {
  135.                     "04Y", "05Y", "06Y", "07Y", "08Y", "09Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "40Y", "50Y"
  136.                 },
  137.                 new double[] {
  138.                     0.0166, 0.0206, 0.0241, 0.0269, 0.0292, 0.0311, 0.0326, 0.0340, 0.0351, 0.0375, 0.0393, 0.0402, 0.0407, 0.0409, 0.0409
  139.                 },
  140.                 "SwapRate"
  141.             )
  142.         );

  143.         Map<String, Double> mapOutput = irs.value (
  144.             ValuationParams.Spot (dtSpot.julian()),
  145.             null,
  146.             csqc,
  147.             null
  148.         );

  149.         for (Map.Entry<String, Double> me : mapOutput.entrySet())
  150.             System.out.println ("\t | " + me.getKey() + " => " + me.getValue() + " ||");

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

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

  153.         System.out.println ("\t\t|    Floating Stream Cash Flow Details                                                                                  ||");

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

  155.         System.out.println ("\t\t|               Start Date                                                                                              ||");

  156.         System.out.println ("\t\t|               End Date                                                                                                ||");

  157.         System.out.println ("\t\t|               Pay Date                                                                                                ||");

  158.         System.out.println ("\t\t|               FX Fixing Date                                                                                          ||");

  159.         System.out.println ("\t\t|               Base Notional                                                                                           ||");

  160.         System.out.println ("\t\t|               Period DCF                                                                                              ||");

  161.         System.out.println ("\t\t|               Tenor                                                                                                   ||");

  162.         System.out.println ("\t\t|               Funding Label                                                                                           ||");

  163.         System.out.println ("\t\t|               Forward Label                                                                                           ||");

  164.         System.out.println ("\t\t|               Pay Discount Factor                                                                                     ||");

  165.         System.out.println ("\t\t|               Coupon Rate                                                                                             ||");

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

  167.         for (CompositePeriod cp : irs.derivedStream().cashFlowPeriod())
  168.             System.out.println ("\t\t| [" +
  169.                 new JulianDate (cp.startDate()) + " - " +
  170.                 new JulianDate (cp.endDate()) + "] => " +
  171.                 new JulianDate (cp.payDate()) + " | " +
  172.                 new JulianDate (cp.fxFixingDate()) + " | " +
  173.                 FormatUtil.FormatDouble (cp.baseNotional(), 1, 4, 1.) + " | " +
  174.                 FormatUtil.FormatDouble (cp.couponDCF(), 1, 4, 1.) + " | " +
  175.                 cp.tenor() + " | " +
  176.                 cp.fundingLabel().fullyQualifiedName() + " | " +
  177.                 cp.floaterLabel().fullyQualifiedName() + " | " +
  178.                 FormatUtil.FormatDouble (cp.df (csqc), 1, 4, 1.) + " | " +
  179.                 FormatUtil.FormatDouble (cp.couponMetrics (dtSpot.julian(), csqc).rate(), 1, 2, 100.) + "% ||"
  180.             );

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

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

  183.         System.out.println ("\t\t|    Fixed Stream Cash Flow Details                                                                      ||");

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

  185.         System.out.println ("\t\t|               Start Date                                                                               ||");

  186.         System.out.println ("\t\t|               End Date                                                                                 ||");

  187.         System.out.println ("\t\t|               Pay Date                                                                                 ||");

  188.         System.out.println ("\t\t|               FX Fixing Date                                                                           ||");

  189.         System.out.println ("\t\t|               Base Notional                                                                            ||");

  190.         System.out.println ("\t\t|               Period DCF                                                                               ||");

  191.         System.out.println ("\t\t|               Tenor                                                                                    ||");

  192.         System.out.println ("\t\t|               Funding Label                                                                            ||");

  193.         System.out.println ("\t\t|               Pay Discount Factor                                                                      ||");

  194.         System.out.println ("\t\t|               Coupon Rate                                                                              ||");

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

  196.         for (CompositePeriod cp : irs.referenceStream().cashFlowPeriod())
  197.             System.out.println ("\t\t| [" +
  198.                 new JulianDate (cp.startDate()) + " - " +
  199.                 new JulianDate (cp.endDate()) + "] => " +
  200.                 new JulianDate (cp.payDate()) + " | " +
  201.                 new JulianDate (cp.fxFixingDate()) + " | " +
  202.                 FormatUtil.FormatDouble (cp.baseNotional(), 1, 4, 1.) + " | " +
  203.                 FormatUtil.FormatDouble (cp.couponDCF(), 1, 4, 1.) + " | " +
  204.                 cp.tenor() + " | " +
  205.                 cp.fundingLabel().fullyQualifiedName() + " | " +
  206.                 FormatUtil.FormatDouble (cp.df (csqc), 1, 4, 1.) + " | " +
  207.                 FormatUtil.FormatDouble (cp.couponMetrics (dtSpot.julian(), csqc).rate(), 1, 2, 100.) + "% ||"
  208.             );

  209.         System.out.println ("\t\t|--------------------------------------------------------------------------------------------------------||");
  210.     }
  211. }