CompositeFedFundLIBORSwap.java
- package org.drip.sample.fedfund;
- import java.util.*;
- import org.drip.analytics.date.*;
- import org.drip.analytics.support.*;
- import org.drip.function.r1tor1.QuadraticRationalShapeControl;
- import org.drip.market.otc.*;
- import org.drip.numerical.common.FormatUtil;
- import org.drip.param.creator.*;
- import org.drip.param.market.CurveSurfaceQuoteContainer;
- import org.drip.param.period.*;
- import org.drip.param.valuation.*;
- import org.drip.product.creator.SingleStreamComponentBuilder;
- import org.drip.product.definition.CalibratableComponent;
- import org.drip.product.rates.*;
- import org.drip.service.env.EnvManager;
- import org.drip.spline.basis.PolynomialFunctionSetParams;
- import org.drip.spline.params.*;
- import org.drip.spline.stretch.*;
- import org.drip.state.creator.*;
- import org.drip.state.discount.*;
- import org.drip.state.estimator.LatentStateStretchBuilder;
- import org.drip.state.forward.ForwardCurve;
- import org.drip.state.identifier.*;
- import org.drip.state.inference.*;
- /*
- * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- */
- /*!
- * Copyright (C) 2019 Lakshmi Krishnamurthy
- * Copyright (C) 2018 Lakshmi Krishnamurthy
- * Copyright (C) 2017 Lakshmi Krishnamurthy
- * Copyright (C) 2016 Lakshmi Krishnamurthy
- * Copyright (C) 2015 Lakshmi Krishnamurthy
- * Copyright (C) 2014 Lakshmi Krishnamurthy
- *
- * This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
- * calculations, valuation adjustment, and portfolio construction within and across fixed income,
- * credit, commodity, equity, FX, and structured products.
- *
- * https://lakshmidrip.github.io/DROP/
- *
- * DROP is composed of three modules:
- *
- * - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
- * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
- * - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
- *
- * DROP Analytics Core implements libraries for the following:
- * - Fixed Income Analytics
- * - Asset Backed Analytics
- * - XVA Analytics
- * - Exposure and Margin Analytics
- *
- * DROP Portfolio Core implements libraries for the following:
- * - Asset Allocation Analytics
- * - Transaction Cost Analytics
- *
- * DROP Numerical Core implements libraries for the following:
- * - Statistical Learning
- * - Numerical Optimizer
- * - Spline Builder
- * - Algorithm Support
- *
- * Documentation for DROP is Spread Over:
- *
- * - Main => https://lakshmidrip.github.io/DROP/
- * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki
- * - GitHub => https://github.com/lakshmiDRIP/DROP
- * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
- * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html
- * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
- * - Release Versions => https://lakshmidrip.github.io/DROP/version.html
- * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html
- * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues
- * - JUnit => https://lakshmidrip.github.io/DROP/junit/index.html
- * - Jacoco => https://lakshmidrip.github.io/DROP/jacoco/index.html
- *
- * 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.
- */
- /**
- * <i>CompositeFedFundLIBORSwap</i> demonstrates the Construction, the Valuation, and Bloomberg Metrics
- * Analysis for the Composite Fed Fund vs. LIBOR Basis Swaps.
- *
- * <br><br>
- * <ul>
- * <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
- * <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
- * <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
- * <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/fedfund/README.md">Fed Fund Analytics</a></li>
- * </ul>
- * <br><br>
- *
- * @author Lakshmi Krishnamurthy
- */
- public class CompositeFedFundLIBORSwap {
- private static final FloatFloatComponent OTCFloatFloat (
- final JulianDate dtSpot,
- final String strCurrency,
- final String strDerivedTenor,
- final String strMaturityTenor,
- final double dblBasis)
- {
- FloatFloatSwapConvention ffConv = IBORFloatFloatContainer.ConventionFromJurisdiction (strCurrency);
- return ffConv.createFloatFloatComponent (
- dtSpot,
- strDerivedTenor,
- strMaturityTenor,
- dblBasis,
- 1.
- );
- }
- private static final FixFloatComponent OTCOISFixFloat (
- final JulianDate dtSpot,
- final String strCurrency,
- final String strMaturityTenor,
- final double dblCoupon)
- {
- FixedFloatSwapConvention ffConv = OvernightFixedFloatContainer.FundConventionFromJurisdiction (
- strCurrency
- );
- return ffConv.createFixFloatComponent (
- dtSpot,
- strMaturityTenor,
- dblCoupon,
- 0.,
- 1.
- );
- }
- /*
- * Construct the Array of Deposit Instruments from the given set of parameters
- *
- * USE WITH CARE: This sample ignores errors and does not handle exceptions.
- */
- private static final SingleStreamComponent[] DepositInstrumentsFromMaturityDays (
- final JulianDate dtEffective,
- final String strCurrency,
- final int[] aiDay)
- throws Exception
- {
- SingleStreamComponent[] aDeposit = new SingleStreamComponent[aiDay.length];
- for (int i = 0; i < aiDay.length; ++i)
- aDeposit[i] = SingleStreamComponentBuilder.Deposit (
- dtEffective,
- dtEffective.addBusDays (
- aiDay[i],
- strCurrency
- ),
- OvernightLabel.Create (
- strCurrency
- )
- );
- return aDeposit;
- }
- /*
- * Construct the Array of Overnight Index Instruments from the given set of parameters
- *
- * USE WITH CARE: This sample ignores errors and does not handle exceptions.
- */
- private static final FixFloatComponent[] OISFromMaturityTenor (
- final JulianDate dtSpot,
- final String strCurrency,
- final String[] astrMaturityTenor,
- final double[] adblCoupon)
- throws Exception
- {
- FixFloatComponent[] aOIS = new FixFloatComponent[astrMaturityTenor.length];
- for (int i = 0; i < astrMaturityTenor.length; ++i)
- aOIS[i] = OTCOISFixFloat (
- dtSpot,
- strCurrency,
- astrMaturityTenor[i],
- adblCoupon[i]
- );
- return aOIS;
- }
- /*
- * Construct the Array of Overnight Index Future Instruments from the given set of parameters
- *
- * USE WITH CARE: This sample ignores errors and does not handle exceptions.
- */
- private static final FixFloatComponent[] OISFuturesFromMaturityTenor (
- final JulianDate dtSpot,
- final String strCurrency,
- final String[] astrStartTenor,
- final String[] astrMaturityTenor,
- final double[] adblCoupon)
- throws Exception
- {
- FixFloatComponent[] aOISFutures = new FixFloatComponent[astrMaturityTenor.length];
- for (int i = 0; i < astrMaturityTenor.length; ++i)
- aOISFutures[i] = OTCOISFixFloat (
- dtSpot.addTenor (astrStartTenor[i]),
- strCurrency,
- astrMaturityTenor[i],
- adblCoupon[i]
- );
- return aOISFutures;
- }
- private static final MergedDiscountForwardCurve OISDiscountCurve (
- final JulianDate dtSpot,
- final String strCurrency,
- final String strHeaderComment)
- throws Exception
- {
- System.out.println ("\n\t----------------------------------------------------------------");
- System.out.println ("\t " + strHeaderComment);
- System.out.println ("\t----------------------------------------------------------------");
- /*
- * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters
- */
- SingleStreamComponent[] aDepositComp = DepositInstrumentsFromMaturityDays (
- dtSpot,
- strCurrency,
- new int[] {
- 1, 2, 3
- }
- );
- double[] adblDepositQuote = new double[] {
- 0.0004, 0.0004, 0.0004 // Deposit
- };
- /*
- * Construct the Deposit Instrument Set Stretch Builder
- */
- LatentStateStretchSpec depositStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
- " DEPOSIT ",
- aDepositComp,
- "ForwardRate",
- adblDepositQuote
- );
- /*
- * Construct the Array of Short End OIS Instruments and their Quotes from the given set of parameters
- */
- double[] adblShortEndOISQuote = new double[] {
- 0.00070, // 1W
- 0.00069, // 2W
- 0.00078, // 3W
- 0.00074 // 1M
- };
- CalibratableComponent[] aShortEndOISComp = OISFromMaturityTenor (
- dtSpot,
- strCurrency,
- new java.lang.String[] {
- "1W", "2W", "3W", "1M"
- },
- adblShortEndOISQuote
- );
- /*
- * Construct the Short End OIS Instrument Set Stretch Builder
- */
- LatentStateStretchSpec oisShortEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
- "SHORT END OIS",
- aShortEndOISComp,
- "SwapRate",
- adblShortEndOISQuote
- );
- /*
- * Construct the Array of OIS Futures Instruments and their Quotes from the given set of parameters
- */
- double[] adblOISFutureQuote = 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
- };
- CalibratableComponent[] aOISFutureComp = OISFuturesFromMaturityTenor (
- dtSpot,
- strCurrency,
- new java.lang.String[] {
- "1M", "2M", "3M", "4M", "5M"
- },
- new java.lang.String[] {
- "1M", "1M", "1M", "1M", "1M"
- },
- adblOISFutureQuote
- );
- /*
- * Construct the OIS Future Instrument Set Stretch Builder
- */
- LatentStateStretchSpec oisFutureStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
- " OIS FUTURE ",
- aOISFutureComp,
- "SwapRate",
- adblOISFutureQuote
- );
- /*
- * Construct the Array of Long End OIS Instruments and their Quotes from the given set of parameters
- */
- 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
- };
- CalibratableComponent[] aLongEndOISComp = OISFromMaturityTenor (
- dtSpot,
- strCurrency,
- new java.lang.String[] {
- "15M", "18M", "21M", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
- },
- adblLongEndOISQuote
- );
- /*
- * Construct the Long End OIS Instrument Set Stretch Builder
- */
- LatentStateStretchSpec oisLongEndStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec (
- "LONG END OIS ",
- aLongEndOISComp,
- "SwapRate",
- adblLongEndOISQuote
- );
- LatentStateStretchSpec[] aStretchSpec = new LatentStateStretchSpec[] {
- depositStretch,
- oisShortEndStretch,
- oisFutureStretch,
- oisLongEndStretch
- };
- /*
- * Set up the Linear Curve Calibrator using the following parameters:
- * - Cubic Exponential Mixture Basis Spline Set
- * - Ck = 2, Segment Curvature Penalty = 2
- * - Quadratic Rational Shape Controller
- * - Natural Boundary Setting
- */
- LinearLatentStateCalibrator lcc = new LinearLatentStateCalibrator (
- new SegmentCustomBuilderControl (
- MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
- new PolynomialFunctionSetParams (4),
- SegmentInelasticDesignControl.Create (
- 2,
- 2
- ),
- new ResponseScalingShapeControl (
- true,
- new QuadraticRationalShapeControl (0.)
- ),
- null
- ),
- BoundarySettings.NaturalStandard(),
- MultiSegmentSequence.CALIBRATE,
- null,
- null
- );
- /*
- * Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array
- * of Deposit and Swap Stretches.
- */
- ValuationParams valParams = new ValuationParams (
- dtSpot,
- dtSpot,
- strCurrency
- );
- MergedDiscountForwardCurve dc = ScenarioDiscountCurveBuilder.ShapePreservingDFBuild (
- strCurrency,
- lcc,
- aStretchSpec,
- valParams,
- null,
- null,
- null,
- 1.
- );
- CurveSurfaceQuoteContainer csqs = MarketParamsBuilder.Create (
- dc,
- null,
- null,
- null,
- null,
- null,
- null
- );
- /*
- * Cross-Comparison of the Deposit Calibration Instrument "Rate" metric across the different curve
- * construction methodologies.
- */
- System.out.println ("\t----------------------------------------------------------------");
- System.out.println ("\t DEPOSIT INSTRUMENTS CALIBRATION RECOVERY");
- System.out.println ("\t----------------------------------------------------------------");
- for (int i = 0; i < aDepositComp.length; ++i)
- System.out.println ("\t[" + aDepositComp[i].effectiveDate() + " => " + aDepositComp[i].maturityDate() + "] = " +
- FormatUtil.FormatDouble (aDepositComp[i].measureValue (valParams, null, csqs, null, "Rate"), 1, 6, 1.) +
- " | " + FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.));
- /*
- * Cross-Comparison of the Short End OIS Calibration Instrument "Rate" metric across the different curve
- * construction methodologies.
- */
- System.out.println ("\n\t----------------------------------------------------------------");
- System.out.println ("\t OIS SHORT END INSTRUMENTS CALIBRATION RECOVERY");
- System.out.println ("\t----------------------------------------------------------------");
- for (int i = 0; i < aShortEndOISComp.length; ++i) {
- Map<String, Double> mapCalc = aShortEndOISComp[i].value (
- valParams,
- null,
- csqs,
- null
- );
- double dblCalibSwapRate = mapCalc.get ("CalibSwapRate");
- double dblFairPremium = mapCalc.get ("FairPremium");
- System.out.println ("\t[" + aShortEndOISComp[i].effectiveDate() + " => " + aShortEndOISComp[i].maturityDate() + "] = " +
- FormatUtil.FormatDouble (dblCalibSwapRate, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (adblShortEndOISQuote[i], 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblFairPremium, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblFairPremium - dblCalibSwapRate, 1, 2, 10000.)
- );
- }
- /*
- * Cross-Comparison of the OIS Future Calibration Instrument "Rate" metric across the different curve
- * construction methodologies.
- */
- System.out.println ("\n\t----------------------------------------------------------------");
- System.out.println ("\t OIS FUTURE INSTRUMENTS CALIBRATION RECOVERY");
- System.out.println ("\t----------------------------------------------------------------");
- for (int i = 0; i < aOISFutureComp.length; ++i) {
- Map<String, Double> mapCalc = aOISFutureComp[i].value (
- valParams,
- null,
- csqs,
- null
- );
- double dblSwapRate = mapCalc.get ("SwapRate");
- double dblFairPremium = mapCalc.get ("FairPremium");
- System.out.println ("\t[" + aOISFutureComp[i].effectiveDate() + " => " + aOISFutureComp[i].maturityDate() + "] = " +
- FormatUtil.FormatDouble (dblSwapRate, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (adblOISFutureQuote[i], 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblFairPremium, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblFairPremium - dblSwapRate, 1, 2, 10000.)
- );
- }
- /*
- * Cross-Comparison of the Long End OIS Calibration Instrument "Rate" metric across the different curve
- * construction methodologies.
- */
- System.out.println ("\n\t----------------------------------------------------------------");
- System.out.println ("\t OIS LONG END INSTRUMENTS CALIBRATION RECOVERY");
- System.out.println ("\t----------------------------------------------------------------");
- for (int i = 0; i < aLongEndOISComp.length; ++i) {
- Map<String, Double> mapCalc = aLongEndOISComp[i].value (
- valParams,
- null,
- csqs,
- null
- );
- double dblCalibSwapRate = mapCalc.get ("CalibSwapRate");
- double dblFairPremium = mapCalc.get ("FairPremium");
- System.out.println ("\t[" + aLongEndOISComp[i].effectiveDate() + " => " + aLongEndOISComp[i].maturityDate() + "] = " +
- FormatUtil.FormatDouble (dblCalibSwapRate, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (adblLongEndOISQuote[i], 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblFairPremium, 1, 6, 1.) + " | " +
- FormatUtil.FormatDouble (dblFairPremium - dblCalibSwapRate, 1, 2, 10000.)
- );
- }
- return dc;
- }
- /*
- * Construct an array of float-float swaps from the corresponding reference (6M) and the derived legs.
- *
- * USE WITH CARE: This sample ignores errors and does not handle exceptions.
- */
- private static final FloatFloatComponent[] MakexM6MBasisSwap (
- final JulianDate dtSpot,
- final String strCurrency,
- final String[] astrMaturityTenor,
- final int iTenorInMonths)
- throws Exception
- {
- FloatFloatComponent[] aFFC = new FloatFloatComponent[astrMaturityTenor.length];
- for (int i = 0; i < astrMaturityTenor.length; ++i)
- aFFC[i] = OTCFloatFloat (
- dtSpot,
- strCurrency,
- iTenorInMonths + "M",
- astrMaturityTenor[i],
- 0.
- );
- return aFFC;
- }
- private static final ForwardCurve MakexMForwardCurve (
- final JulianDate dtSpot,
- final String strCurrency,
- final MergedDiscountForwardCurve dc,
- final int iTenorInMonths,
- final String[] astrxM6MFwdTenor,
- final String strManifestMeasure,
- final double[] adblxM6MBasisSwapQuote)
- throws Exception
- {
- /*
- * Construct the 6M-xM float-float basis swap.
- */
- FloatFloatComponent[] aFFC = MakexM6MBasisSwap (
- dtSpot,
- strCurrency,
- astrxM6MFwdTenor,
- iTenorInMonths
- );
- String strBasisTenor = iTenorInMonths + "M";
- ValuationParams valParams = new ValuationParams (
- dtSpot,
- dtSpot,
- strCurrency
- );
- /*
- * Calculate the starting forward rate off of the discount curve.
- */
- double dblStartingFwd = dc.forward (
- dtSpot.julian(),
- dtSpot.addTenor (strBasisTenor).julian()
- );
- /*
- * Set the discount curve based component market parameters.
- */
- CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
- dc,
- null,
- null,
- null,
- null,
- null,
- null
- );
- /*
- * Construct the shape preserving forward curve off of Cubic Polynomial Basis Spline.
- */
- return ScenarioForwardCurveBuilder.ShapePreservingForwardCurve (
- "CUBIC_FWD" + strBasisTenor,
- ForwardLabel.Create (
- strCurrency,
- strBasisTenor
- ),
- valParams,
- null,
- mktParams,
- null,
- MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
- new PolynomialFunctionSetParams (4),
- aFFC,
- strManifestMeasure,
- adblxM6MBasisSwapQuote,
- dblStartingFwd
- );
- }
- private static final FloatFloatComponent[] FedFundLIBORBasisSwap (
- final JulianDate dtEffective,
- final String strCurrency,
- final String[] astrMaturityTenor)
- throws Exception
- {
- FloatFloatComponent[] aFFC = new FloatFloatComponent[astrMaturityTenor.length];
- ComposableFloatingUnitSetting cfusLIBOR = new ComposableFloatingUnitSetting (
- "3M",
- CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
- null,
- ForwardLabel.Standard (strCurrency + "-3M"),
- CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
- 0.
- );
- ComposableFloatingUnitSetting cfusFedFund = new ComposableFloatingUnitSetting (
- "ON",
- CompositePeriodBuilder.EDGE_DATE_SEQUENCE_OVERNIGHT,
- null,
- OvernightLabel.Create (
- strCurrency
- ),
- CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
- 0.
- );
- CompositePeriodSetting cpsLIBOR = new CompositePeriodSetting (
- 4,
- "3M",
- strCurrency,
- null,
- -1.,
- null,
- null,
- null,
- null
- );
- CompositePeriodSetting cpsFedFund = new CompositePeriodSetting (
- 4,
- "3M",
- strCurrency,
- null,
- 1.,
- null,
- null,
- null,
- null
- );
- CashSettleParams csp = new CashSettleParams (
- 0,
- strCurrency,
- 0
- );
- for (int i = 0; i < astrMaturityTenor.length; ++i) {
- List<Integer> lsReferenceStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
- dtEffective,
- "3M",
- astrMaturityTenor[i],
- null
- );
- List<Integer> lsDerivedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
- dtEffective,
- "3M",
- astrMaturityTenor[i],
- null
- );
- Stream streamLIBOR = new Stream (
- CompositePeriodBuilder.FloatingCompositeUnit (
- lsReferenceStreamEdgeDate,
- cpsLIBOR,
- cfusLIBOR
- )
- );
- Stream streamFedFund = new Stream (
- CompositePeriodBuilder.FloatingCompositeUnit (
- lsDerivedStreamEdgeDate,
- cpsFedFund,
- cfusFedFund
- )
- );
- aFFC[i] = new FloatFloatComponent (
- streamLIBOR,
- streamFedFund,
- csp
- );
- }
- return aFFC;
- }
- /*
- * Construct the Array of Overnight Index Instruments from the given set of parameters
- *
- * USE WITH CARE: This sample ignores errors and does not handle exceptions.
- */
- private static final FixFloatComponent[] SwapInstrumentsFromMaturityTenor (
- final JulianDate dtEffective,
- final String[] astrMaturityTenor,
- final double[] adblCoupon,
- final String strCurrency)
- throws Exception
- {
- FixFloatComponent[] aOIS = new FixFloatComponent[astrMaturityTenor.length];
- UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
- 2,
- "Act/360",
- false,
- "Act/360",
- false,
- strCurrency,
- false,
- CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
- );
- CashSettleParams csp = new CashSettleParams (
- 0,
- strCurrency,
- 0
- );
- for (int i = 0; i < astrMaturityTenor.length; ++i) {
- java.lang.String strFixedTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
- astrMaturityTenor[i],
- "6M"
- ) ? astrMaturityTenor[i] : "6M";
- java.lang.String strFloatingTenor = Helper.LEFT_TENOR_LESSER == Helper.TenorCompare (
- astrMaturityTenor[i],
- "3M"
- ) ? astrMaturityTenor[i] : "3M";
- ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
- "3M",
- CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
- null,
- ForwardLabel.Create (
- strCurrency,
- "3M"
- ),
- CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
- 0.
- );
- ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
- strFixedTenor,
- CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
- null,
- adblCoupon[i],
- 0.,
- strCurrency
- );
- CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
- 4,
- strFloatingTenor,
- strCurrency,
- null,
- -1.,
- null,
- null,
- null,
- null
- );
- CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
- 2,
- strFixedTenor,
- strCurrency,
- null,
- 1.,
- null,
- null,
- null,
- null
- );
- List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
- dtEffective,
- strFixedTenor,
- astrMaturityTenor[i],
- null
- );
- List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
- dtEffective,
- strFloatingTenor,
- astrMaturityTenor[i],
- null
- );
- Stream floatingStream = new Stream (
- CompositePeriodBuilder.FloatingCompositeUnit (
- lsFloatingStreamEdgeDate,
- cpsFloating,
- cfusFloating
- )
- );
- Stream fixedStream = new Stream (
- CompositePeriodBuilder.FixedCompositeUnit (
- lsFixedStreamEdgeDate,
- cpsFixed,
- ucasFixed,
- cfusFixed
- )
- );
- FixFloatComponent ois = new FixFloatComponent (
- fixedStream,
- floatingStream,
- csp
- );
- ois.setPrimaryCode ("OIS." + astrMaturityTenor[i] + "." + strCurrency);
- aOIS[i] = ois;
- }
- return aOIS;
- }
- public static final void main (
- final String[] astrArgs)
- throws Exception
- {
- /*
- * Initialize the Credit Analytics Library
- */
- EnvManager.InitEnv ("");
- String strCurrency = "USD";
- JulianDate dtToday = DateUtil.CreateFromYMD (
- 2012,
- DateUtil.DECEMBER,
- 11
- );
- MergedDiscountForwardCurve dcOIS = OISDiscountCurve (
- dtToday,
- strCurrency,
- "OVERNIGHT INDEX RUN RECONCILIATION"
- );
- ForwardCurve fc = MakexMForwardCurve (
- dtToday,
- strCurrency,
- dcOIS,
- 3,
- new String[] {
- "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
- },
- "ReferenceParBasisSpread",
- new double[] {
- 0.00186, // 1Y
- 0.00127, // 2Y
- 0.00097, // 3Y
- 0.00080, // 4Y
- 0.00067, // 5Y
- 0.00058, // 6Y
- 0.00051, // 7Y
- 0.00046, // 8Y
- 0.00042, // 9Y
- 0.00038, // 10Y
- 0.00035, // 11Y
- 0.00033, // 12Y
- 0.00028, // 15Y
- 0.00022, // 20Y
- 0.00020, // 25Y
- 0.00018 // 30Y
- }
- );
- CurveSurfaceQuoteContainer mktParams = MarketParamsBuilder.Create (
- dcOIS,
- null,
- null,
- null,
- null,
- null,
- null
- );
- mktParams.setForwardState (fc);
- String[] astrMaturityTenor = new String[] {
- "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y"
- };
- FloatFloatComponent[] aFedFundLIBORSwap = FedFundLIBORBasisSwap (
- dtToday,
- strCurrency,
- astrMaturityTenor
- );
- FixFloatComponent[] aOIS = OISFromMaturityTenor (
- dtToday,
- strCurrency,
- astrMaturityTenor,
- new double[] {
- 0.00002,
- 0.00036,
- 0.00127,
- 0.00274,
- 0.00456,
- 0.00647,
- 0.00827,
- 0.00996,
- 0.01147,
- 0.01280,
- 0.01404,
- 0.01516,
- 0.01764,
- 0.01939,
- 0.02003,
- 0.02038
- }
- );
- FixFloatComponent[] aIRS = SwapInstrumentsFromMaturityTenor (
- dtToday,
- astrMaturityTenor,
- new double[] {
- 0.00002,
- 0.00036,
- 0.00127,
- 0.00274,
- 0.00456,
- 0.00647,
- 0.00827,
- 0.00996,
- 0.01147,
- 0.01280,
- 0.01404,
- 0.01516,
- 0.01764,
- 0.01939,
- 0.02003,
- 0.02038
- },
- strCurrency
- );
- ValuationParams valParams = new ValuationParams (
- dtToday,
- dtToday,
- strCurrency
- );
- System.out.println ("\n\t--------------------------------------------------------------------------");
- System.out.println ("\t FED FUND OIS BASIS COMPARISON");
- System.out.println ("\t--------------------------------------------------------------------------");
- System.out.println ("\t\tOutput Order[Effective Date - Maturity Date]");
- System.out.println ("\t\t\t IRS Rate (%)");
- System.out.println ("\t\t\t Fed Fund LIBOR Basis (bp)");
- System.out.println ("\t\t\t OIS Rate Uncompounded (%) (Bloomberg 2010 Methodology)");
- System.out.println ("\t\t\t OIS Rate Daily Compounded (%) (Bloomberg 2010 Methodology)");
- System.out.println ("\t\t\t OIS Rate (%) From Full Calibration\n");
- System.out.println ("\t--------------------------------------------------------------------------");
- for (int i = 0; i < aFedFundLIBORSwap.length; ++i) {
- Map<String, Double> mapOIS = aOIS[i].value (
- valParams,
- null,
- mktParams,
- null
- );
- Map<String, Double> mapIRS = aIRS[i].value (
- valParams,
- null,
- mktParams,
- null
- );
- double dblOISRate = mapOIS.get ("SwapRate");
- double dblIRSRate = mapIRS.get ("SwapRate");
- double dblLIBORFedFundBasis = dblIRSRate - dblOISRate;
- System.out.println ("\t[" +
- aFedFundLIBORSwap[i].effectiveDate() + " - " +
- aFedFundLIBORSwap[i].maturityDate() + "] => " +
- FormatUtil.FormatDouble (dblIRSRate, 1, 4, 100.) + "% | " +
- FormatUtil.FormatDouble (dblLIBORFedFundBasis, 1, 1, 10000.) + " | " +
- FormatUtil.FormatDouble (Helper.OISFromLIBORSwapFedFundBasis (dblIRSRate, -dblLIBORFedFundBasis), 1, 4, 100.) + "% | " +
- FormatUtil.FormatDouble (Helper.OISFromLIBORSwapFedFundBasis2 (dblIRSRate, -dblLIBORFedFundBasis), 1, 4, 100.) + "% | " +
- FormatUtil.FormatDouble (dblOISRate, 1, 4, 100.) + "%"
- );
- }
- System.out.println ("\t--------------------------------------------------------------------------");
- EnvManager.TerminateEnv();
- }
- }