FXStateShifted.java

  1. package org.drip.template.statebump;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.param.market.CurveSurfaceQuoteContainer;
  6. import org.drip.param.valuation.ValuationParams;
  7. import org.drip.product.definition.Component;
  8. import org.drip.product.fx.FXForwardComponent;
  9. import org.drip.product.params.CurrencyPair;
  10. import org.drip.service.env.EnvManager;
  11. import org.drip.service.template.*;
  12. import org.drip.state.fx.FXCurve;

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

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

  89. /**
  90.  * <i>FXStateShifted</i> demonstrates the Generation and the Usage of Tenor Bumped FX Curves.
  91.  *
  92.  *  <br><br>
  93.  *  <ul>
  94.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  95.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  96.  *      <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>
  97.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/statebump/README.md">Shifted Latent State Construction Template</a></li>
  98.  *  </ul>
  99.  * <br><br>
  100.  *
  101.  * @author Lakshmi Krishnamurthy
  102.  */

  103. public class FXStateShifted {

  104.     public static final void main (
  105.         final String[] astrArgs)
  106.         throws Exception
  107.     {
  108.         EnvManager.InitEnv ("");

  109.         CurrencyPair cp = new CurrencyPair (
  110.             "EUR",
  111.             "USD",
  112.             "USD",
  113.             10000.
  114.         );

  115.         JulianDate dtSpot = DateUtil.Today().addBusDays (
  116.             0,
  117.             cp.denomCcy()
  118.         );

  119.         double dblFXSpot = 1.1013;
  120.         double dblBump = 0.0001;
  121.         boolean bIsBumpProportional = false;

  122.         String[] astrMaturityTenor = new String[] {
  123.             "1D",
  124.             "2D",
  125.             "3D",
  126.             "1W",
  127.             "2W",
  128.             "3W",
  129.             "1M",
  130.             "2M",
  131.             "3M",
  132.             "6M",
  133.             "9M"
  134.         };

  135.         double[] adblFXForward = new double[] {
  136.             1.1011,     // "1D"
  137.             1.1007,     // "2D"
  138.             1.0999,     // "3D"
  139.             1.0976,     // "1W"
  140.             1.0942,     // "2W"
  141.             1.0904,     // "3W"
  142.             1.0913,     // "1M"
  143.             1.0980,     // "2M"
  144.             1.1088,     // "3M"
  145.             1.1115,     // "6M"
  146.             1.1011      // "9M"
  147.         };

  148.         Map<String, FXCurve> mapBumpedFXCurve = LatentMarketStateBuilder.BumpedFXCurve (
  149.             dtSpot,
  150.             cp,
  151.             astrMaturityTenor,
  152.             adblFXForward,
  153.             "Outright",
  154.             dblFXSpot,
  155.             LatentMarketStateBuilder.SMOOTH,
  156.             dblBump,
  157.             bIsBumpProportional
  158.         );

  159.         FXForwardComponent[] aFXFC = OTCInstrumentBuilder.FXForward (
  160.             dtSpot,
  161.             cp,
  162.             astrMaturityTenor
  163.         );

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

  165.         ValuationParams valParams = ValuationParams.Spot (dtSpot.julian());

  166.         for (Map.Entry<String, FXCurve> meFX : mapBumpedFXCurve.entrySet()) {
  167.             String strKey = meFX.getKey();

  168.             if (!strKey.startsWith ("fxfwd")) continue;

  169.             CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  170.             csqc.setFXState (meFX.getValue());

  171.             System.out.print ("\t|  [" + meFX.getKey() + "] => ");

  172.             for (Component comp : aFXFC)
  173.                 System.out.print (FormatUtil.FormatDouble (
  174.                     comp.measureValue (
  175.                         valParams,
  176.                         null,
  177.                         csqc,
  178.                         null,
  179.                         "Outright"
  180.                     ), 1, 4, 1.) + " |");

  181.             System.out.print ("|\n");
  182.         }

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

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

  185.         CurveSurfaceQuoteContainer csqcBase = new CurveSurfaceQuoteContainer();

  186.         csqcBase.setFXState (mapBumpedFXCurve.get ("Base"));

  187.         CurveSurfaceQuoteContainer csqcBump = new CurveSurfaceQuoteContainer();

  188.         csqcBump.setFXState (mapBumpedFXCurve.get ("Bump"));

  189.         for (Component comp : aFXFC)
  190.             System.out.println (
  191.                 "\t| OUTRIGHT  => " +
  192.                 comp.maturityDate() + " | " +
  193.                 FormatUtil.FormatDouble (comp.measureValue (
  194.                     valParams,
  195.                     null,
  196.                     csqcBase,
  197.                     null,
  198.                     "Outright"
  199.                 ), 1, 4, 1.) + " | " +
  200.                 FormatUtil.FormatDouble (comp.measureValue (
  201.                     valParams,
  202.                     null,
  203.                     csqcBump,
  204.                     null,
  205.                     "Outright"
  206.                 ), 1, 4, 1.) + " ||"
  207.             );

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