@Override public DiscountFactors toDiscountFactors() { return DiscountFactors.of(currency, valuationDate, curve); }
@Override public DiscountFactors discountFactors(Currency currency) { Curve curve = discountCurves.get(currency); if (curve == null) { throw new IllegalArgumentException("Unable to find discount curve: " + currency); } return DiscountFactors.of(currency, valuationDate, curve); }
/** * Obtains an instance from a curve and time-series of fixings. * <p> * The curve is specified by an instance of {@link Curve}, such as {@link InterpolatedNodalCurve}. * The curve must have x-values of {@linkplain ValueType#YEAR_FRACTION year fractions} with * the day count specified. The y-values must be {@linkplain ValueType#ZERO_RATE zero rates} * or {@linkplain ValueType#DISCOUNT_FACTOR discount factors}. * * @param index the index * @param valuationDate the valuation date for which the curve is valid * @param forwardCurve the forward curve * @param fixings the time-series of fixings * @return the rates view */ public static OvernightIndexRates of( OvernightIndex index, LocalDate valuationDate, Curve forwardCurve, LocalDateDoubleTimeSeries fixings) { DiscountFactors discountFactors = DiscountFactors.of(index.getCurrency(), valuationDate, forwardCurve); return DiscountOvernightIndexRates.of(index, discountFactors, fixings); }
public void test_of_prices() { assertThrowsIllegalArg(() -> DiscountFactors.of(GBP, DATE_VAL, CURVE_PRICES)); }
public void test_of_zeroRatePeriodic() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_ZERO_PERIODIC); assertEquals(test instanceof ZeroRatePeriodicDiscountFactors, true); assertEquals(test.getCurrency(), GBP); assertEquals(test.getValuationDate(), DATE_VAL); }
public void test_of_discountFactors() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_DF); assertEquals(test instanceof SimpleDiscountFactors, true); assertEquals(test.getCurrency(), GBP); assertEquals(test.getValuationDate(), DATE_VAL); }
public void test_of_zeroRate() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE_ZERO); assertEquals(test instanceof ZeroRateDiscountFactors, true); assertEquals(test.getCurrency(), GBP); assertEquals(test.getValuationDate(), DATE_VAL); }
public 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), TOLERANCE_DELTA_FD); }
public 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 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 static final ImmutableLegalEntityDiscountingProvider multiBond(LocalDate valDate) { ImmutableMap<Pair<RepoGroup, Currency>, DiscountFactors> repoCurves = ImmutableMap.of( Pair.of(US_REPO_GROUP, USD), DiscountFactors.of(USD, valDate, US_REPO_CURVE)); ImmutableMap<Pair<LegalEntityGroup, Currency>, DiscountFactors> issuerCurves = ImmutableMap.of( Pair.of(US_ISSUER_1_GROUP, USD), DiscountFactors.of(USD, valDate, US_ISSUER_CURVE_1), Pair.of(US_ISSUER_2_GROUP, USD), DiscountFactors.of(USD, valDate, 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(); }
curve, currency, c -> replaceIssuerCurve(immProv, legCcy, DiscountFactors.of(currency, valuationDate, c)), sensitivitiesFn); result = result.combinedWith(gammaSingle); currency, c -> replaceIssuerCurve( immProv, legCcy, DiscountFactors.of(currency, valuationDate, curve.withUnderlyingCurve(currentIndex, c))), sensitivitiesFn); result = result.combinedWith(gammaSingle); curve, currency, c -> replaceRepoCurve(immProv, rgCcy, DiscountFactors.of(currency, valuationDate, c)), sensitivitiesFn); result = result.combinedWith(gammaSingle); currency, c -> replaceRepoCurve( immProv, rgCcy, DiscountFactors.of(currency, valuationDate, curve.withUnderlyingCurve(currentIndex, c))), sensitivitiesFn); result = result.combinedWith(gammaSingle);
/** * Obtains an instance from a curve and time-series of fixings. * <p> * The curve is specified by an instance of {@link Curve}, such as {@link InterpolatedNodalCurve}. * The curve must have x-values of {@linkplain ValueType#YEAR_FRACTION year fractions} with * the day count specified. The y-values must be {@linkplain ValueType#ZERO_RATE zero rates} * or {@linkplain ValueType#DISCOUNT_FACTOR discount factors}. * * @param index the index * @param valuationDate the valuation date for which the curve is valid * @param forwardCurve the forward curve * @param fixings the time-series of fixings * @return the rates view */ public static IborIndexRates of( IborIndex index, LocalDate valuationDate, Curve forwardCurve, LocalDateDoubleTimeSeries fixings) { if (forwardCurve.getMetadata().getYValueType().equals(ValueType.FORWARD_RATE)) { return SimpleIborIndexRates.of(index, valuationDate, forwardCurve, fixings); } DiscountFactors discountFactors = DiscountFactors.of(index.getCurrency(), valuationDate, forwardCurve); return DiscountIborIndexRates.of(index, discountFactors, fixings); }
public static final 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 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.getValuationDate(), 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.getFxRateProvider(), FX_MATRIX); }
public void merge_content_3() { ImmutableRatesProvider test1 = ImmutableRatesProvider.builder(VAL_DATE) .discountCurve(GBP, DISCOUNT_CURVE_GBP) .timeSeries(GBP_USD_WM, TS) .build(); ImmutableRatesProvider test2 = ImmutableRatesProvider.builder(VAL_DATE) .iborIndexCurve(USD_LIBOR_3M, USD_LIBOR_CURVE) .overnightIndexCurve(USD_FED_FUND, FED_FUND_CURVE) .build(); ImmutableRatesProvider test3 = ImmutableRatesProvider.builder(VAL_DATE) .discountCurve(USD, DISCOUNT_CURVE_USD) .priceIndexCurve(GB_RPI, GBPRI_CURVE) .timeSeries(GB_RPI, TS) .build(); ImmutableRatesProvider merged = ImmutableRatesProvider.combined(FX_MATRIX, test1, test2, test3); assertEquals(merged.getValuationDate(), 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.getFxRateProvider(), FX_MATRIX); }