java.time.Period.ofMonths()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中java.time.Period.ofMonths()方法的一些代码示例,展示了Period.ofMonths()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Period.ofMonths()方法的具体详情如下:
包路径:java.time.Period
类名称:Period
方法名:ofMonths

Period.ofMonths介绍

[英]Obtains a Period representing a number of months.

The resulting period will have the specified months. The years and days units will be zero.
[中]获取表示月份数的期间。
由此产生的期间将具有指定的月份。年和日单位为零。

代码示例

代码示例来源:origin: OpenGamma/Strata

public void test_of_PeriodPeriodConvention() {
 FraTemplate test = FraTemplate.of(Period.ofMonths(2), Period.ofMonths(4), FRA_GBP_LIBOR_3M);
 assertEquals(test.getPeriodToStart(), Period.ofMonths(2));
 assertEquals(test.getPeriodToEnd(), Period.ofMonths(4));
 assertEquals(test.getConvention(), FRA_GBP_LIBOR_3M);
}

代码示例来源:origin: OpenGamma/Strata

public void test_of_PeriodIndex() {
 FraTemplate test = FraTemplate.of(Period.ofMonths(2), GBP_LIBOR_3M);
 assertEquals(test.getPeriodToStart(), Period.ofMonths(2));
 assertEquals(test.getPeriodToEnd(), Period.ofMonths(5));  // defaulted
 assertEquals(test.getConvention(), FRA_GBP_LIBOR_3M);
}

代码示例来源:origin: OpenGamma/Strata

public void test_of() {
 IborIborSwapTemplate test = IborIborSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 assertEquals(test.getPeriodToStart(), Period.ofMonths(3));
 assertEquals(test.getTenor(), TENOR_10Y);
 assertEquals(test.getConvention(), CONV);
}

代码示例来源:origin: OpenGamma/Strata

public void test_of() {
 ThreeLegBasisSwapTemplate test = ThreeLegBasisSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 assertEquals(test.getPeriodToStart(), Period.ofMonths(3));
 assertEquals(test.getTenor(), TENOR_10Y);
 assertEquals(test.getConvention(), CONV);
}

代码示例来源:origin: OpenGamma/Strata

public void test_of_period() {
 FixedIborSwapTemplate test = FixedIborSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 assertEquals(test.getPeriodToStart(), Period.ofMonths(3));
 assertEquals(test.getTenor(), TENOR_10Y);
 assertEquals(test.getConvention(), CONV);
}

代码示例来源:origin: OpenGamma/Strata

static RawOptionData sut2() {
 List<Period> expiries2 = new ArrayList<>();
 expiries2.add(Period.ofMonths(3));
 expiries2.add(Period.ofYears(1));
 expiries2.add(Period.ofYears(5));
 RawOptionData test2 =
   RawOptionData.of(expiries2, STRIKES, ValueType.STRIKE, DATA_SPARSE, ERROR, ValueType.BLACK_VOLATILITY);
 return test2;
}

代码示例来源:origin: OpenGamma/Strata

public void test_ofLastBusinessDay() {
 PeriodAdjustment test = PeriodAdjustment.ofLastBusinessDay(Period.ofMonths(3), BDA_FOLLOW_SAT_SUN);
 assertEquals(test.getPeriod(), Period.ofMonths(3));
 assertEquals(test.getAdditionConvention(), LAST_BUSINESS_DAY);
 assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN);
 assertEquals(test.toString(), "P3M with LastBusinessDay then apply Following using calendar Sat/Sun");
}

代码示例来源:origin: OpenGamma/Strata

public void test_builder_defaults() {
 FraTemplate test = FraTemplate.builder()
   .periodToStart(Period.ofMonths(2))
   .convention(FRA_GBP_LIBOR_3M)
   .build();
 assertEquals(test.getPeriodToStart(), Period.ofMonths(2));
 assertEquals(test.getPeriodToEnd(), Period.ofMonths(5));  // defaulted
 assertEquals(test.getConvention(), FRA_GBP_LIBOR_3M);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 ThreeLegBasisSwapTemplate test = ThreeLegBasisSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 coverImmutableBean(test);
 ThreeLegBasisSwapTemplate test2 = ThreeLegBasisSwapTemplate.of(Period.ofMonths(2), TENOR_2Y, CONV2);
 coverBeanEquals(test, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void test_beanBuilder() {
 PeriodAdjustment test = PeriodAdjustment.builder()
   .period(Period.ofMonths(3))
   .additionConvention(LAST_DAY)
   .adjustment(BDA_FOLLOW_SAT_SUN)
   .build();
 assertEquals(test.getPeriod(), Period.ofMonths(3));
 assertEquals(test.getAdditionConvention(), LAST_DAY);
 assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 XCcyIborIborSwapTemplate test = XCcyIborIborSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 coverImmutableBean(test);
 DaysAdjustment bda2 = DaysAdjustment.ofBusinessDays(1, EUTA);
 XCcyIborIborSwapConvention conv2 =
   ImmutableXCcyIborIborSwapConvention.of("XXX", USD3M, EUR3M, bda2);
 XCcyIborIborSwapTemplate test2 = XCcyIborIborSwapTemplate.of(Period.ofMonths(2), TENOR_2Y, conv2);
 coverBeanEquals(test, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void test_toTrade_periodTenor() {
 FixedOvernightSwapConvention base = ImmutableFixedOvernightSwapConvention.of(NAME, FIXED, FFUND_LEG, PLUS_TWO_DAYS);
 LocalDate tradeDate = LocalDate.of(2015, 5, 5);
 LocalDate startDate = date(2015, 8, 7);
 LocalDate endDate = date(2025, 8, 7);
 SwapTrade test = base.createTrade(tradeDate, Period.ofMonths(3), TENOR_10Y, BUY, NOTIONAL_2M, 0.25d, REF_DATA);
 Swap expected = Swap.of(
   FIXED.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d),
   FFUND_LEG.toLeg(startDate, endDate, RECEIVE, NOTIONAL_2M));
 assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate));
 assertEquals(test.getProduct(), expected);
}

代码示例来源:origin: OpenGamma/Strata

public void test_createTrade() {
 XCcyIborIborSwapTemplate base = XCcyIborIborSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 LocalDate tradeDate = LocalDate.of(2015, 5, 5);
 LocalDate startDate = date(2015, 8, 7);
 LocalDate endDate = date(2025, 8, 7);
 SwapTrade test = base.createTrade(tradeDate, BUY, NOTIONAL_2M, NOTIONAL_2M * FX_EUR_USD, 0.25d, REF_DATA);
 Swap expected = Swap.of(
   EUR3M.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d),
   USD3M.toLeg(startDate, endDate, RECEIVE, NOTIONAL_2M * FX_EUR_USD));
 assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate));
 assertEquals(test.getProduct(), expected);
}

代码示例来源:origin: OpenGamma/Strata

public void test_createTrade() {
 FixedOvernightSwapTemplate base = FixedOvernightSwapTemplate.of(Period.ofMonths(3), TENOR_10Y, CONV);
 LocalDate tradeDate = LocalDate.of(2015, 5, 5);
 LocalDate startDate = date(2015, 8, 7);
 LocalDate endDate = date(2025, 8, 7);
 SwapTrade test = base.createTrade(tradeDate, BUY, NOTIONAL_2M, 0.25d, REF_DATA);
 Swap expected = Swap.of(
   FIXED.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d),
   FFUND_LEG.toLeg(startDate, endDate, RECEIVE, NOTIONAL_2M));
 assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate));
 assertEquals(test.getProduct(), expected);
}

代码示例来源:origin: OpenGamma/Strata

public void test_toTrade_periodTenor() {
 FixedIborSwapConvention base = ImmutableFixedIborSwapConvention.of(NAME, FIXED, IBOR);
 LocalDate tradeDate = LocalDate.of(2015, 5, 5);
 LocalDate startDate = date(2015, 8, 7);
 LocalDate endDate = date(2025, 8, 7);
 SwapTrade test = base.createTrade(tradeDate, Period.ofMonths(3), TENOR_10Y, BUY, NOTIONAL_2M, 0.25d, REF_DATA);
 Swap expected = Swap.of(
   FIXED.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d),
   IBOR.toLeg(startDate, endDate, RECEIVE, NOTIONAL_2M));
 assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate));
 assertEquals(test.getProduct(), expected);
}

代码示例来源:origin: OpenGamma/Strata

@Test(dataProvider = "types")
public void test_null(PeriodAdditionConvention type) {
 assertThrowsIllegalArg(() -> type.adjust(null, Period.ofMonths(3), HolidayCalendars.NO_HOLIDAYS));
 assertThrowsIllegalArg(() -> type.adjust(date(2014, 7, 11), null, HolidayCalendars.NO_HOLIDAYS));
 assertThrowsIllegalArg(() -> type.adjust(date(2014, 7, 11), Period.ofMonths(3), null));
 assertThrowsIllegalArg(() -> type.adjust(null, null, null));
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 TermDepositTemplate test1 = TermDepositTemplate.of(DEPOSIT_PERIOD, CONVENTION);
 coverImmutableBean(test1);
 TermDepositTemplate test2 = TermDepositTemplate.of(Period.ofMonths(6),
   ImmutableTermDepositConvention.of(
     "GBP-Dep", GBP, BDA_MOD_FOLLOW, ACT_365F, DaysAdjustment.ofBusinessDays(2, GBLO)));
 coverBeanEquals(test1, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 FraCurveNode test = FraCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD);
 coverImmutableBean(test);
 FraCurveNode test2 = FraCurveNode.of(
   FraTemplate.of(Period.ofMonths(1), GBP_LIBOR_6M), QuoteId.of(StandardId.of("OG-Ticker", "Deposit2")));
 coverBeanEquals(test, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void test_createRateComputation_noFirstIndexValue() {
 InflationRateCalculation test = InflationRateCalculation.builder()
   .index(CH_CPI)
   .lag(Period.ofMonths(3))
   .indexCalculationMethod(INTERPOLATED)
   .build();
 assertThrows(() -> test.createRateComputation(DATE_2015_04_05), IllegalStateException.class);
}

代码示例来源:origin: OpenGamma/Strata

public void test_of_tooBig() {
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofMonths(12001)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofMonths(Integer.MAX_VALUE)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofYears(1001)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofYears(Integer.MAX_VALUE)));
 assertThrowsIllegalArg(() -> Frequency.ofMonths(12001), "Months must not exceed 12,000");
 assertThrowsIllegalArg(() -> Frequency.ofMonths(Integer.MAX_VALUE));
 assertThrowsIllegalArg(() -> Frequency.ofYears(1001), "Years must not exceed 1,000");
 assertThrowsIllegalArg(() -> Frequency.ofYears(Integer.MAX_VALUE));
 assertThrowsIllegalArg(() -> Frequency.of(Period.of(10000, 0, 1)));
}

相关文章