ForwardContract.java
- package org.drip.sample.piterbarg2010;
- import org.drip.analytics.date.*;
- import org.drip.analytics.support.Helper;
- import org.drip.numerical.common.FormatUtil;
- import org.drip.service.env.EnvManager;
- import org.drip.service.template.LatentMarketStateBuilder;
- import org.drip.state.discount.*;
- /*
- * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- */
- /*!
- * Copyright (C) 2018 Lakshmi Krishnamurthy
- * Copyright (C) 2017 Lakshmi Krishnamurthy
- *
- * This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
- * libraries targeting analysts and developers
- * https://lakshmidrip.github.io/DRIP/
- *
- * DRIP is composed of four main libraries:
- *
- * - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
- * - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
- * - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
- * - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
- *
- * - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
- * Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
- * Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
- * Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
- * Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
- *
- * - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
- * Incorporator, Holdings Constraint, and Transaction Costs.
- *
- * - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
- *
- * - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- *
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * ForwardContract examines the Valuation of Forward Contract under CSA and non-CSA Settle Agreements. CSA is
- * proxied using the OIS Curve, and non-CSA using the Issuer Hedge Funding Curve. The corresponding
- * Convexity Adjustments using Spread/CSA Covariance are also calculated. The References are:
- *
- * - Barden, P. (2009): Equity Forward Prices in the Presence of Funding Spreads, ICBI Conference, Rome.
- *
- * - Burgard, C., and M. Kjaer (2009): Modeling and successful Management of Credit Counter-party Risk of
- * Derivative Portfolios, ICBI Conference, Rome.
- *
- * - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90.
- *
- * - Johannes, M., and S. Sundaresan (2007): Pricing Collateralized Swaps, Journal of Finance 62 383-410.
- *
- * - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
- * 21 (2) 97-102.
- *
- * @author Lakshmi Krishnamurthy
- */
- public class ForwardContract {
- private static final DiscountCurve CSACurve (
- final String strCurrency,
- final JulianDate dtSpot)
- throws Exception
- {
- String[] astrDepositMaturityTenor = new String[] {
- "1D",
- // "2D",
- // "3D"
- };
- double[] adblDepositQuote = new double[] {
- 0.0004, // 1D
- // 0.0004, // 2D
- // 0.0004 // 3D
- };
- String[] astrShortEndOISMaturityTenor = new String[] {
- "1W",
- "2W",
- "3W",
- "1M"
- };
- double[] adblShortEndOISQuote = new double[] {
- 0.00070, // 1W
- 0.00069, // 2W
- 0.00078, // 3W
- 0.00074 // 1M
- };
- String[] astrOISFuturesEffectiveTenor = new String[] {
- "1M",
- "2M",
- "3M",
- "4M",
- "5M"
- };
- String[] astrOISFuturesMaturityTenor = new String[] {
- "1M",
- "1M",
- "1M",
- "1M",
- "1M"
- };
- double[] adblOISFuturesQuote = new double[] {
- 0.00046, // 1M x 1M
- 0.00016, // 2M x 1M
- -0.00007, // 3M x 1M
- -0.00013, // 4M x 1M
- -0.00014 // 5M x 1M
- };
- String[] astrLongEndOISMaturityTenor = new String[] {
- "15M",
- "18M",
- "21M",
- "02Y",
- "03Y",
- "04Y",
- "05Y",
- "06Y",
- "07Y",
- "08Y",
- "09Y",
- "10Y",
- "11Y",
- "12Y",
- "15Y",
- "20Y",
- "25Y",
- "30Y"
- };
- double[] adblLongEndOISQuote = new double[] {
- 0.00002, // 15M
- 0.00008, // 18M
- 0.00021, // 21M
- 0.00036, // 2Y
- 0.00127, // 3Y
- 0.00274, // 4Y
- 0.00456, // 5Y
- 0.00647, // 6Y
- 0.00827, // 7Y
- 0.00996, // 8Y
- 0.01147, // 9Y
- 0.01280, // 10Y
- 0.01404, // 11Y
- 0.01516, // 12Y
- 0.01764, // 15Y
- 0.01939, // 20Y
- 0.02003, // 25Y
- 0.02038 // 30Y
- };
- return LatentMarketStateBuilder.SmoothOvernightCurve (
- dtSpot,
- strCurrency,
- astrDepositMaturityTenor,
- adblDepositQuote,
- "Rate",
- astrShortEndOISMaturityTenor,
- adblShortEndOISQuote,
- "SwapRate",
- astrOISFuturesEffectiveTenor,
- astrOISFuturesMaturityTenor,
- adblOISFuturesQuote,
- "SwapRate",
- astrLongEndOISMaturityTenor,
- adblLongEndOISQuote,
- "SwapRate"
- );
- }
- private static final DiscountCurve NonCSACurve (
- final String strCurrency,
- final JulianDate dtSpot)
- throws Exception
- {
- String[] astrDepositMaturityTenor = new String[] {
- "01D",
- "04D",
- "07D",
- "14D",
- "30D",
- "60D"
- };
- double[] adblDepositQuote = new double[] {
- 0.0013, // 1D
- 0.0017, // 2D
- 0.0017, // 7D
- 0.0018, // 14D
- 0.0020, // 30D
- 0.0023 // 60D
- };
- double[] adblFuturesQuote = new double[] {
- 0.0027,
- 0.0032,
- 0.0041,
- 0.0054,
- 0.0077,
- 0.0104,
- 0.0134,
- 0.0160
- };
- String[] astrFixFloatMaturityTenor = new String[] {
- "04Y",
- "05Y",
- "06Y",
- "07Y",
- "08Y",
- "09Y",
- "10Y",
- "11Y",
- "12Y",
- "15Y",
- "20Y",
- "25Y",
- "30Y",
- "40Y",
- "50Y"
- };
- double[] adblFixFloatQuote = new double[] {
- 0.0166, // 4Y
- 0.0206, // 5Y
- 0.0241, // 6Y
- 0.0269, // 7Y
- 0.0292, // 8Y
- 0.0311, // 9Y
- 0.0326, // 10Y
- 0.0340, // 11Y
- 0.0351, // 12Y
- 0.0375, // 15Y
- 0.0393, // 20Y
- 0.0402, // 25Y
- 0.0407, // 30Y
- 0.0409, // 40Y
- 0.0409 // 50Y
- };
- return LatentMarketStateBuilder.SmoothFundingCurve (
- dtSpot,
- strCurrency,
- astrDepositMaturityTenor,
- adblDepositQuote,
- "ForwardRate",
- adblFuturesQuote,
- "ForwardRate",
- astrFixFloatMaturityTenor,
- adblFixFloatQuote,
- "SwapRate"
- );
- }
- public static final void main (
- final String[] astrArgs)
- throws Exception
- {
- EnvManager.InitEnv ("");
- String strCurrency = "USD";
- double dblATMForward = 50.;
- double dblCSAVolatility = 0.1;
- double dblCSANonCSASpreadVolatility = 0.2;
- double dblCSANonCSASpreadCorrelation = 0.2;
- JulianDate dtSpot = DateUtil.Today().addBusDays (
- 0,
- strCurrency
- );
- String[] astrTenor = new String[] {
- "1W",
- "2W",
- "3W",
- "1M",
- "2M",
- "3M",
- "6M",
- "9M",
- "12M",
- "18M",
- "2Y",
- "3Y",
- "4Y",
- "5Y",
- "7Y",
- "10Y",
- "12Y",
- "15Y",
- "20Y",
- "25Y",
- "30Y",
- "40Y",
- "50Y"
- };
- DiscountCurve dcOvernight = CSACurve (
- strCurrency,
- dtSpot
- );
- DiscountCurve dcFunding = NonCSACurve (
- strCurrency,
- dtSpot
- );
- System.out.println();
- System.out.println ("\t||-----------------------------------------------||");
- System.out.println ("\t|| FORWARD CONTRACT CONVEXITY ADJUSTMENT ||");
- System.out.println ("\t||-----------------------------------------------||");
- System.out.println ("\t|| L -> R: ||");
- System.out.println ("\t|| - Date ||");
- System.out.println ("\t|| - Spread Numeraire ||");
- System.out.println ("\t|| - Convexity Adjustment ||");
- System.out.println ("\t|| - CSA-Funding Convexity Adjustment ||");
- System.out.println ("\t||-----------------------------------------------||");
- for (String strTenor : astrTenor) {
- JulianDate dt = dtSpot.addTenor (strTenor);
- double dblTenorToYF = Helper.TenorToYearFraction (strTenor);
- double dblSpreadNumeraire = dcFunding.df (dt) / dcOvernight.df (dt);
- double dblConvexityAdjustment = dblCSANonCSASpreadCorrelation * dblCSANonCSASpreadVolatility * dblCSAVolatility;
- System.out.println ("\t|| " + dt + " | " +
- FormatUtil.FormatDouble (dblSpreadNumeraire, 1, 4, 1.) + " | " +
- FormatUtil.FormatDouble (dblConvexityAdjustment * dblTenorToYF, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblConvexityAdjustment * dblATMForward * dblSpreadNumeraire * dblTenorToYF, 1, 6, 1.) + " ||"
- );
- }
- System.out.println ("\t||-----------------------------------------------||");
- System.out.println();
- }
- }