public ImmutableLegalEntityDiscountingProvider toImmutableLegalEntityDiscountingProvider() { // repo curves IDictionary <Pair <RepoGroup, Currency>, DiscountFactors> repoCurves = new Dictionary <Pair <RepoGroup, Currency>, DiscountFactors>(); foreach (Pair <RepoGroup, Currency> pair in lookup.RepoCurves.Keys) { CurveId curveId = lookup.RepoCurves.get(pair); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); repoCurves[pair] = DiscountFactors.of(pair.Second, ValuationDate, curve); } } // issuer curves IDictionary <Pair <LegalEntityGroup, Currency>, DiscountFactors> issuerCurves = new Dictionary <Pair <LegalEntityGroup, Currency>, DiscountFactors>(); foreach (Pair <LegalEntityGroup, Currency> pair in lookup.IssuerCurves.Keys) { CurveId curveId = lookup.IssuerCurves.get(pair); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); issuerCurves[pair] = DiscountFactors.of(pair.Second, ValuationDate, curve); } } // build result return(ImmutableLegalEntityDiscountingProvider.builder().valuationDate(ValuationDate).repoCurveSecurityGroups(lookup.RepoCurveSecurityGroups).repoCurveGroups(lookup.RepoCurveGroups).repoCurves(repoCurves).issuerCurveGroups(lookup.IssuerCurveGroups).issuerCurves(issuerCurves).build()); }
public virtual void test_of_zeroRatePeriodic() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_ZERO_PERIODIC); assertEquals(test is ZeroRatePeriodicDiscountFactors, true); assertEquals(test.Currency, GBP); assertEquals(test.ValuationDate, DATE_VAL); }
//------------------------------------------------------------------------- public virtual void test_of_discountFactors() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_DF); assertEquals(test is SimpleDiscountFactors, true); assertEquals(test.Currency, GBP); assertEquals(test.ValuationDate, DATE_VAL); }
public virtual void test_discountFactorTimeDerivative() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expectedP = test.discountFactor(relativeYearFraction + EPS); double expectedM = test.discountFactor(relativeYearFraction - EPS); assertEquals(test.discountFactorTimeDerivative(relativeYearFraction), (expectedP - expectedM) / (2 * EPS), TOL_FD); }
//------------------------------------------------------------------------- public DiscountFactors discountFactors(Currency currency) { Curve curve = discountCurves.get(currency); if (curve == null) { throw new System.ArgumentException("Unable to find discount curve: " + currency); } return(DiscountFactors.of(currency, valuationDate, curve)); }
//------------------------------------------------------------------------- public DiscountFactors discountFactors(Currency currency) { CurveId curveId = lookup.DiscountCurves.get(currency); if (curveId == null) { throw new MarketDataNotFoundException(lookup.msgCurrencyNotFound(currency)); } Curve curve = marketData.getValue(curveId); return(DiscountFactors.of(currency, ValuationDate, curve)); }
// lookup the discount factors for the legal entity group private IssuerCurveDiscountFactors issuerCurveDiscountFactors(LegalEntityGroup legalEntityGroup, Currency currency) { CurveId curveId = lookup.IssuerCurves.get(Pair.of(legalEntityGroup, currency)); if (curveId == null) { throw new MarketDataNotFoundException("Unable to find issuer curve: " + legalEntityGroup + ", " + currency); } Curve curve = marketData.getValue(curveId); DiscountFactors df = DiscountFactors.of(currency, ValuationDate, curve); return(IssuerCurveDiscountFactors.of(df, legalEntityGroup)); }
// lookup the discount factors for the repo group private RepoCurveDiscountFactors repoCurveDiscountFactors(RepoGroup repoGroup, Currency currency) { CurveId curveId = lookup.RepoCurves.get(Pair.of(repoGroup, currency)); if (curveId == null) { throw new MarketDataNotFoundException("Unable to find repo curve: " + repoGroup + ", " + currency); } Curve curve = marketData.getValue(curveId); DiscountFactors df = DiscountFactors.of(currency, ValuationDate, curve); return(RepoCurveDiscountFactors.of(df, repoGroup)); }
public virtual void merge_content_2() { ImmutableRatesProvider test1 = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).timeSeries(GBP_USD_WM, TS).build(); ImmutableRatesProvider test2 = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(USD, DISCOUNT_CURVE_USD).iborIndexCurve(USD_LIBOR_3M, USD_LIBOR_CURVE).overnightIndexCurve(USD_FED_FUND, FED_FUND_CURVE).priceIndexCurve(GB_RPI, GBPRI_CURVE).timeSeries(GB_RPI, TS).build(); ImmutableRatesProvider merged = ImmutableRatesProvider.combined(FX_MATRIX, test1, test2); assertEquals(merged.ValuationDate, VAL_DATE); assertEquals(merged.discountFactors(USD), DiscountFactors.of(USD, VAL_DATE, DISCOUNT_CURVE_USD)); assertEquals(merged.discountFactors(GBP), DiscountFactors.of(GBP, VAL_DATE, DISCOUNT_CURVE_GBP)); assertEquals(merged.iborIndexRates(USD_LIBOR_3M), IborIndexRates.of(USD_LIBOR_3M, VAL_DATE, USD_LIBOR_CURVE)); assertEquals(merged.overnightIndexRates(USD_FED_FUND), OvernightIndexRates.of(USD_FED_FUND, VAL_DATE, FED_FUND_CURVE)); assertEquals(merged.priceIndexValues(GB_RPI), PriceIndexValues.of(GB_RPI, VAL_DATE, GBPRI_CURVE, TS)); assertEquals(merged.timeSeries(GBP_USD_WM), TS); assertEquals(merged.FxRateProvider, FX_MATRIX); }
//------------------------------------------------------------------------- /// <summary> /// Computes intra-curve cross gamma for bond curves by applying finite difference method to curve delta. /// <para> /// This computes the intra-curve cross gamma, i.e., the second order sensitivities to individual curves. /// Thus the sensitivity of a curve delta to another curve is not produced. /// </para> /// <para> /// The underlying instruments must be single-currency, i.e., the curve currency must be the same as the sensitivity currency. /// /// </para> /// </summary> /// <param name="ratesProvider"> the rates provider </param> /// <param name="sensitivitiesFn"> the sensitivity function </param> /// <returns> the cross gamma </returns> public CrossGammaParameterSensitivities calculateCrossGammaIntraCurve(LegalEntityDiscountingProvider ratesProvider, System.Func <ImmutableLegalEntityDiscountingProvider, CurrencyParameterSensitivities> sensitivitiesFn) { LocalDate valuationDate = ratesProvider.ValuationDate; ImmutableLegalEntityDiscountingProvider immProv = ratesProvider.toImmutableLegalEntityDiscountingProvider(); CurrencyParameterSensitivities baseDelta = sensitivitiesFn(immProv); // used to check target sensitivity exits CrossGammaParameterSensitivities result = CrossGammaParameterSensitivities.empty(); // issuer curve foreach (KeyValuePair <Pair <LegalEntityGroup, Currency>, DiscountFactors> entry in immProv.IssuerCurves.entrySet()) { Pair <LegalEntityGroup, Currency> legCcy = entry.Key; Currency currency = legCcy.Second; Curve curve = getCurve(entry.Value); CurveName curveName = curve.Name; if (baseDelta.findSensitivity(curveName, currency).Present) { CrossGammaParameterSensitivity gammaSingle = computeGammaForCurve(curveName, curve, currency, c => replaceIssuerCurve(immProv, legCcy, DiscountFactors.of(currency, valuationDate, c)), sensitivitiesFn); result = result.combinedWith(gammaSingle); } else { ImmutableList <Curve> curves = curve.split(); int nCurves = curves.size(); if (nCurves > 1) { for (int i = 0; i < nCurves; ++i) { int currentIndex = i; Curve underlyingCurve = curves.get(currentIndex); CurveName underlyingCurveName = underlyingCurve.Name; if (baseDelta.findSensitivity(underlyingCurveName, currency).Present) { CrossGammaParameterSensitivity gammaSingle = computeGammaForCurve(underlyingCurveName, underlyingCurve, currency, c => replaceIssuerCurve(immProv, legCcy, DiscountFactors.of(currency, valuationDate, curve.withUnderlyingCurve(currentIndex, c))), sensitivitiesFn); result = result.combinedWith(gammaSingle); } } } } } // repo curve foreach (KeyValuePair <Pair <RepoGroup, Currency>, DiscountFactors> entry in immProv.RepoCurves.entrySet()) { Pair <RepoGroup, Currency> rgCcy = entry.Key; Currency currency = rgCcy.Second; Curve curve = getCurve(entry.Value); CurveName curveName = curve.Name; if (baseDelta.findSensitivity(curveName, currency).Present) { CrossGammaParameterSensitivity gammaSingle = computeGammaForCurve(curveName, curve, currency, c => replaceRepoCurve(immProv, rgCcy, DiscountFactors.of(currency, valuationDate, c)), sensitivitiesFn); result = result.combinedWith(gammaSingle); } else { ImmutableList <Curve> curves = curve.split(); int nCurves = curves.size(); if (nCurves > 1) { for (int i = 0; i < nCurves; ++i) { int currentIndex = i; Curve underlyingCurve = curves.get(currentIndex); CurveName underlyingCurveName = underlyingCurve.Name; if (baseDelta.findSensitivity(underlyingCurveName, rgCcy.Second).Present) { CrossGammaParameterSensitivity gammaSingle = computeGammaForCurve(underlyingCurveName, underlyingCurve, currency, c => replaceRepoCurve(immProv, rgCcy, DiscountFactors.of(currency, valuationDate, curve.withUnderlyingCurve(currentIndex, c))), sensitivitiesFn); result = result.combinedWith(gammaSingle); } } } } } return(result); }
public static ImmutableLegalEntityDiscountingProvider multiBondCombined(LocalDate valDate) { ImmutableMap <Pair <RepoGroup, Currency>, DiscountFactors> repoCurves = ImmutableMap.of(Pair.of(US_REPO_GROUP, USD), DiscountFactors.of(USD, valDate, CombinedCurve.of(USD_L3_BASE, US_REPO_CURVE))); ImmutableMap <Pair <LegalEntityGroup, Currency>, DiscountFactors> issuerCurves = ImmutableMap.of(Pair.of(US_ISSUER_1_GROUP, USD), DiscountFactors.of(USD, valDate, CombinedCurve.of(USD_L3_BASE, US_ISSUER_CURVE_1)), Pair.of(US_ISSUER_2_GROUP, USD), DiscountFactors.of(USD, valDate, CombinedCurve.of(USD_L3_BASE, US_ISSUER_CURVE_2))); ImmutableMap <LegalEntityId, RepoGroup> repoGroups = ImmutableMap.of(US_ISSUER_1_ID, US_REPO_GROUP, US_ISSUER_2_ID, US_REPO_GROUP, US_ISSUER_3_ID, US_REPO_GROUP); ImmutableMap <LegalEntityId, LegalEntityGroup> legalEntityGroups = ImmutableMap.of(US_ISSUER_1_ID, US_ISSUER_1_GROUP, US_ISSUER_2_ID, US_ISSUER_2_GROUP, US_ISSUER_3_ID, US_ISSUER_2_GROUP); return(ImmutableLegalEntityDiscountingProvider.builder().valuationDate(valDate).repoCurves(repoCurves).repoCurveGroups(repoGroups).issuerCurves(issuerCurves).issuerCurveGroups(legalEntityGroups).build()); }
public virtual void test_of_prices() { assertThrowsIllegalArg(() => DiscountFactors.of(GBP, DATE_VAL, CURVE_PRICES)); }