DomesticCollateralForeignForex.java

  1. package org.drip.sample.piterbarg2012;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.support.CaseInsensitiveTreeMap;
  5. import org.drip.function.r1tor1.*;
  6. import org.drip.param.creator.*;
  7. import org.drip.param.market.CurveSurfaceQuoteContainer;
  8. import org.drip.param.valuation.*;
  9. import org.drip.product.fx.DomesticCollateralizedForeignForward;
  10. import org.drip.product.params.CurrencyPair;
  11. import org.drip.service.env.EnvManager;
  12. import org.drip.state.creator.*;
  13. import org.drip.state.curve.ForeignCollateralizedDiscountCurve;
  14. import org.drip.state.discount.MergedDiscountForwardCurve;
  15. import org.drip.state.fx.FXCurve;
  16. import org.drip.state.identifier.*;
  17. import org.drip.state.nonlinear.*;
  18. import org.drip.state.volatility.VolatilityCurve;

  19. /*
  20.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  21.  */

  22. /*!
  23.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  24.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  25.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  26.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  27.  * Copyright (C) 2014 Lakshmi Krishnamurthy
  28.  *
  29.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  30.  *      libraries targeting analysts and developers
  31.  *      https://lakshmidrip.github.io/DRIP/
  32.  *  
  33.  *  DRIP is composed of four main libraries:
  34.  *  
  35.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  36.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  37.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  38.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  39.  *
  40.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  41.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  42.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  43.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  44.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  45.  *
  46.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  47.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  48.  *
  49.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  50.  *
  51.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  52.  *
  53.  *  Licensed under the Apache License, Version 2.0 (the "License");
  54.  *      you may not use this file except in compliance with the License.
  55.  *  
  56.  *  You may obtain a copy of the License at
  57.  *      http://www.apache.org/licenses/LICENSE-2.0
  58.  *  
  59.  *  Unless required by applicable law or agreed to in writing, software
  60.  *      distributed under the License is distributed on an "AS IS" BASIS,
  61.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  62.  *  
  63.  *  See the License for the specific language governing permissions and
  64.  *      limitations under the License.
  65.  */

  66. /**
  67.  * DomesticCollateralForeignForex demonstrates the construction and the usage of Domestic Currency
  68.  *  Collateralized Foreign Pay-out FX forward product, and the generation of its measures.
  69.  *  
  70.  * @author Lakshmi Krishnamurthy
  71.  */

  72. public class DomesticCollateralForeignForex {
  73.     public static final void main (
  74.         final String[] astrArgs)
  75.         throws Exception
  76.     {
  77.         /*
  78.          * Initialize the Credit Analytics Library
  79.          */

  80.         EnvManager.InitEnv ("");

  81.         JulianDate dtToday = DateUtil.Today();

  82.         String strDomesticCurrency = "USD";
  83.         String strForeignCurrency = "EUR";
  84.         String strMaturity = "1Y";
  85.         double dblFXFwdStrike = 0.984;
  86.         double dblForeignCollateralRate = 0.02;
  87.         double dblCollateralizedFXRate = 1.10;
  88.         double dblForeignRatesVolatility = 0.30;
  89.         double dblFXVolatility = 0.20;
  90.         double dblFXForeignRatesCorrelation = 0.50;

  91.         CurrencyPair cp = CurrencyPair.FromCode (strForeignCurrency + "/" + strDomesticCurrency);

  92.         MergedDiscountForwardCurve dcCcyDomesticCollatDomestic = ScenarioDiscountCurveBuilder.ExponentiallyCompoundedFlatRate (
  93.             dtToday,
  94.             strForeignCurrency,
  95.             dblForeignCollateralRate
  96.         );

  97.         FXCurve fxCurve = new FlatForwardFXCurve (
  98.             dtToday.julian(),
  99.             cp,
  100.             dblCollateralizedFXRate,
  101.             new int[] {dtToday.julian()},
  102.             new double[] {dblCollateralizedFXRate}
  103.         );

  104.         VolatilityCurve vcForeignFunding = new FlatForwardVolatilityCurve (
  105.             dtToday.julian(),
  106.             VolatilityLabel.Standard (CollateralLabel.Standard (strForeignCurrency)),
  107.             strDomesticCurrency,
  108.             new int[] {dtToday.julian()},
  109.             new double[] {dblForeignRatesVolatility}
  110.         );

  111.         VolatilityCurve vcFX = new FlatForwardVolatilityCurve (
  112.             dtToday.julian(),
  113.             VolatilityLabel.Standard (FXLabel.Standard (cp)),
  114.             strDomesticCurrency,
  115.             new int[] {dtToday.julian()},
  116.             new double[] {dblFXVolatility}
  117.         );

  118.         MergedDiscountForwardCurve dcCcyForeignCollatDomestic = new ForeignCollateralizedDiscountCurve (
  119.             strForeignCurrency,
  120.             dcCcyDomesticCollatDomestic,
  121.             fxCurve,
  122.             vcForeignFunding,
  123.             vcFX,
  124.             new FlatUnivariate (dblFXForeignRatesCorrelation)
  125.         );

  126.         CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
  127.             null,
  128.             null,
  129.             null,
  130.             null,
  131.             null,
  132.             null,
  133.             null
  134.         );

  135.         mktParams.setPayCurrencyCollateralCurrencyCurve (
  136.             strForeignCurrency,
  137.             strDomesticCurrency,
  138.             dcCcyForeignCollatDomestic
  139.         );

  140.         mktParams.setPayCurrencyCollateralCurrencyCurve (
  141.             strDomesticCurrency,
  142.             strDomesticCurrency,
  143.             dcCcyDomesticCollatDomestic
  144.         );

  145.         mktParams.setFXState (
  146.             ScenarioFXCurveBuilder.CubicPolynomialCurve (
  147.                 "FX::" + cp.code(),
  148.                 dtToday,
  149.                 cp,
  150.                 new String[] {"10Y"},
  151.                 new double[] {dblCollateralizedFXRate},
  152.                 dblCollateralizedFXRate
  153.             )
  154.         );

  155.         DomesticCollateralizedForeignForward dcff = new DomesticCollateralizedForeignForward (
  156.             cp,
  157.             dblFXFwdStrike,
  158.             dtToday.addTenor (strMaturity)
  159.         );

  160.         CaseInsensitiveTreeMap<Double> mapDCFF = dcff.value (
  161.             new ValuationParams (
  162.                 dtToday,
  163.                 dtToday,
  164.                 strDomesticCurrency
  165.             ),
  166.             null,
  167.             mktParams,
  168.             null
  169.         );

  170.         for (Map.Entry<String, Double> me : mapDCFF.entrySet())
  171.             System.out.println ("\t" + me.getKey() + " => " + me.getValue());
  172.     }
  173. }