EuroDollar.java

  1. package org.drip.template.forwardratefutures;

  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.definition.Component;
  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>EuroDollar</i> contains a Templated Pricing of the EuroDollar (i.e, LIBOR 3M USD Futures) 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/forwardratefutures/README.md">Forward Rate Futures Construction Template</a></li>
  96.  *  </ul>
  97.  * <br><br>
  98.  *
  99.  * @author Lakshmi Krishnamurthy
  100.  */

  101. public class EuroDollar {

  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 = "USD";

  109.         Component futures = ExchangeInstrumentBuilder.ForwardRateFutures (
  110.             dtSpot,
  111.             strCurrency
  112.         );

  113.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  114.         csqc.setFundingState (
  115.             LatentMarketStateBuilder.SmoothFundingCurve (
  116.                 dtSpot,
  117.                 strCurrency,
  118.                 new String[] {
  119.                     "02D", "07D", "14D", "30D", "60D"
  120.                 },
  121.                 new double[] {
  122.                     0.0017, 0.0017, 0.0018, 0.0020, 0.0023
  123.                 },
  124.                 "ForwardRate",
  125.                 new double[] {
  126.                     0.0027, 0.0032, 0.0041, 0.0054, 0.0077, 0.0104, 0.0134, 0.0160
  127.                 },
  128.                 "ForwardRate",
  129.                 new String[] {
  130.                     "04Y", "05Y", "06Y", "07Y", "08Y", "09Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "40Y", "50Y"
  131.                 },
  132.                 new double[] {
  133.                     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
  134.                 },
  135.                 "SwapRate"
  136.             )
  137.         );

  138.         Map<String, Double> mapOutput = futures.value (
  139.             ValuationParams.Spot (dtSpot.julian()),
  140.             null,
  141.             csqc,
  142.             null
  143.         );

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

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

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

  148.         System.out.println ("\t\t|    Cash Flow Details                                                                                                  ||");

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

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

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

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

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

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

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

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

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

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

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

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

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

  162.         for (CompositePeriod cp : futures.couponPeriods())
  163.             System.out.println ("\t\t| [" +
  164.                 new JulianDate (cp.startDate()) + " - " +
  165.                 new JulianDate (cp.endDate()) + "] => " +
  166.                 new JulianDate (cp.payDate()) + " | " +
  167.                 new JulianDate (cp.fxFixingDate()) + " | " +
  168.                 FormatUtil.FormatDouble (cp.baseNotional(), 1, 4, 1.) + " | " +
  169.                 FormatUtil.FormatDouble (cp.couponDCF(), 1, 4, 1.) + " | " +
  170.                 cp.tenor() + " | " +
  171.                 cp.fundingLabel().fullyQualifiedName() + " | " +
  172.                 cp.floaterLabel().fullyQualifiedName() + " | " +
  173.                 FormatUtil.FormatDouble (cp.df (csqc), 1, 4, 1.) + " | " +
  174.                 FormatUtil.FormatDouble (cp.couponMetrics (dtSpot.julian(), csqc).rate(), 1, 2, 100.) + "% ||"
  175.             );

  176.         System.out.println ("\t\t|-----------------------------------------------------------------------------------------------------------------------||");
  177.     }
  178. }