@DataProvider(name = "based") public static Object[][] data_based() { return new Object[][] { {Tenor.ofDays(1), false, false}, {Tenor.ofDays(2), false, false}, {Tenor.ofDays(6), false, false}, {Tenor.ofDays(7), true, false}, {Tenor.ofWeeks(1), true, false}, {Tenor.ofWeeks(3), true, false}, {Tenor.ofMonths(1), false, true}, {Tenor.ofMonths(3), false, true}, {Tenor.ofYears(1), false, true}, {Tenor.ofYears(3), false, true}, {Tenor.of(Period.of(1, 2, 3)), false, false}, }; }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.label == null && builder.template != null) { builder.label = Tenor.of(builder.template.getPeriodToEnd()).toString(); } }
public void test_of_notZero() { assertThrowsIllegalArg(() -> Tenor.of(Period.ofDays(0))); assertThrowsIllegalArg(() -> Tenor.ofDays(0)); assertThrowsIllegalArg(() -> Tenor.ofWeeks(0)); assertThrowsIllegalArg(() -> Tenor.ofMonths(0)); assertThrowsIllegalArg(() -> Tenor.ofYears(0)); }
@DataProvider(name = "stubOn") public static Object[][] data_stub_on() { return new Object[][] { {OvernightIborSwapConventions.USD_FED_FUND_AA_LIBOR_3M, Tenor.TENOR_4M}, {OvernightIborSwapConventions.GBP_SONIA_OIS_1Y_LIBOR_3M, Tenor.of(Period.ofMonths(13))}, }; }
public void test_of_notNegative() { assertThrowsIllegalArg(() -> Tenor.of(Period.ofDays(-1))); assertThrowsIllegalArg(() -> Tenor.ofDays(-1)); assertThrowsIllegalArg(() -> Tenor.ofWeeks(-1)); assertThrowsIllegalArg(() -> Tenor.ofMonths(-1)); assertThrowsIllegalArg(() -> Tenor.ofYears(-1)); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.label == null && builder.template != null) { builder.label = Tenor.of(builder.template.getDepositPeriod()).toString(); } }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.label == null && builder.template != null) { builder.label = Tenor.of(builder.template.getDepositPeriod()).toString(); } }
/** * Normalizes the months and years of this tenor. * <p> * This method returns a normalized tenor of an equivalent length. * If the period is exactly 1 year then the result will be expressed as 12 months. * Otherwise, the result will be expressed using {@link Period#normalized()}. * * @return the normalized tenor */ public Tenor normalized() { if (period.getDays() == 0 && period.toTotalMonths() == 12) { return TENOR_12M; } Period norm = period.normalized(); return (norm != period ? Tenor.of(norm) : this); }
/** * Converts a date range to a period string. * * @param start the start date * @param end the end date * @return the string form */ public static String datePeriod(LocalDate start, LocalDate end) { int months = Math.toIntExact(MONTHS.between(start, end.plusDays(3))); if (months > 0) { return Tenor.of(Period.ofMonths((int) months)).normalized().toString(); } else { return Tenor.of(Period.ofDays((int) start.until(end, ChronoUnit.DAYS))).toString(); } }
@Test(dataProvider = "normalized") public void test_normalized(Period period, Period normalized) { assertEquals(Tenor.of(period).normalized().getPeriod(), normalized); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); if (date.isFixed()) { return LabelDateParameterMetadata.of(nodeDate, label); } Tenor tenor = Tenor.of(template.getDepositPeriod()); return TenorDateParameterMetadata.of(nodeDate, tenor, label); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); if (date.isFixed()) { return LabelDateParameterMetadata.of(nodeDate, label); } Tenor tenor = Tenor.of(template.getPeriodToFar()); return TenorDateParameterMetadata.of(nodeDate, tenor, label); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); if (date.isFixed()) { return LabelDateParameterMetadata.of(nodeDate, label); } Tenor tenor = Tenor.of(template.getPeriodToEnd()); return TenorDateParameterMetadata.of(nodeDate, tenor, label); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); if (date.isFixed()) { return LabelDateParameterMetadata.of(nodeDate, label); } Tenor tenor = Tenor.of(template.getDepositPeriod()); return TenorDateParameterMetadata.of(nodeDate, tenor, label); }
public void test_of_additionConventionNone() { TenorAdjustment test = TenorAdjustment.of(Tenor.of(Period.of(1, 2, 3)), PAC_NONE, BDA_NONE); assertEquals(test.getTenor(), Tenor.of(Period.of(1, 2, 3))); assertEquals(test.getAdditionConvention(), PAC_NONE); assertEquals(test.getAdjustment(), BDA_NONE); assertEquals(test.toString(), "1Y2M3D"); }
public void documentTenor() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.convertIndexTenor("1", "M"), Tenor.TENOR_1M); assertEquals(test.convertIndexTenor("12", "M"), Tenor.TENOR_12M); assertEquals(test.convertIndexTenor("1", "Y"), Tenor.TENOR_12M); assertEquals(test.convertIndexTenor("13", "Y"), Tenor.of(Period.ofYears(13))); }
public void test_metadata_end() { FxSwapCurveNode node = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); LocalDate valuationDate = LocalDate.of(2015, 1, 22); LocalDate endDate = CONVENTION.getBusinessDayAdjustment() .adjust(CONVENTION.getSpotDateOffset().adjust(valuationDate, REF_DATA).plus(FAR_PERIOD), REF_DATA); ParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); assertEquals(((TenorDateParameterMetadata) metadata).getDate(), endDate); assertEquals(((TenorDateParameterMetadata) metadata).getTenor(), Tenor.of(FAR_PERIOD)); }
public void hard_coded_value_one_curve_all_dates_tenor() { final LocalDate sensitivityDate = LocalDate.of(2015, 8, 18); Function<LocalDate, ParameterMetadata> parameterMetadataFunction = (d) -> TenorParameterMetadata.of(Tenor .of(Period.ofDays((int) (d.toEpochDay() - sensitivityDate.toEpochDay())))); Function<CurrencyParameterSensitivities, CurrencyParameterSensitivities> rebucketFunction = (s) -> CurveSensitivityUtils.linearRebucketing(s, TARGET_DATES, sensitivityDate); test_from_functions_one_curve_all_dates(parameterMetadataFunction, rebucketFunction); }
public void hard_coded_value_one_curve_one_date_tenor() { final LocalDate sensitivityDate = LocalDate.of(2015, 8, 18); Function<LocalDate, ParameterMetadata> parameterMetadataFunction = (d) -> TenorParameterMetadata.of(Tenor .of(Period.ofDays((int) (d.toEpochDay() - sensitivityDate.toEpochDay())))); Function<CurrencyParameterSensitivities, CurrencyParameterSensitivities> rebucketFunction = (s) -> CurveSensitivityUtils.linearRebucketing(s, TARGET_DATES, sensitivityDate); test_from_functions_one_curve_one_date(parameterMetadataFunction, rebucketFunction); }