void clearFocus() { LocalDate focusDate = datePicker.getValue(); if (focusDate == null) { focusDate = LocalDate.now(); } if (YearMonth.from(focusDate).equals(selectedYearMonth.get())) { goToDate(focusDate, true); } }
private void goToDate(LocalDate date, boolean focusDayCell) { if (isValidDate(datePicker.getChronology(), date)) { selectedYearMonth.set(YearMonth.from(date)); if (focusDayCell) { findDayCellOfDate(date).requestFocus(); } } }
selectedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now()); selectedYearMonth.addListener((observable, oldValue, newValue) -> updateValues());
@Override public YearMonth queryFrom(TemporalAccessor temporal) { return YearMonth.from(temporal); } };
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); LocalDate referenceDate = template.calculateReferenceDateFromTradeDate(valuationDate, refData); if (label.isEmpty()) { return YearMonthDateParameterMetadata.of(nodeDate, YearMonth.from(referenceDate)); } return YearMonthDateParameterMetadata.of(nodeDate, YearMonth.from(referenceDate), label); }
@Override public YearMonth convertToEntityAttribute(java.sql.Date dbData) { return YearMonth.from(Instant.ofEpochMilli(dbData.getTime()) .atZone(ZoneId.systemDefault()) .toLocalDate()); } }
void clearFocus() { LocalDate focusDate = datePicker.getValue(); if (focusDate == null) { focusDate = LocalDate.now(); } if (YearMonth.from(focusDate).equals(selectedYearMonth.get())) { goToDate(focusDate, true); } }
@Override public double value(PriceIndexObservation observation) { YearMonth fixingMonth = observation.getFixingMonth(); // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { OptionalDouble fixing = fixings.get(fixingMonth.atEndOfMonth()); if (fixing.isPresent()) { return fixing.getAsDouble(); } } throw new MarketDataNotFoundException("Unable to query forward value for historic index " + index); }
private void goToDate(LocalDate date, boolean focusDayCell) { if (isValidDate(datePicker.getChronology(), date)) { selectedYearMonth.set(YearMonth.from(date)); if (focusDayCell) { findDayCellOfDate(date).requestFocus(); } } }
@Test(dataProvider = "quarterly10th") public void test_nextOrSameQuarterly10th(LocalDate base, LocalDate expect1, LocalDate expect2, LocalDate expect3) { LocalDate date = base.plusDays(1); while (!date.isAfter(expect1)) { assertEquals(DateSequences.QUARTERLY_10TH.nextOrSame(date), expect1); assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 1), expect1); assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 2), expect2); assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 3), expect3); date = date.plusDays(1); } assertEquals(DateSequences.QUARTERLY_10TH.dateMatching(YearMonth.from(date)), expect1); }
@Test(dataProvider = "monthlyImm") public void test_nextOrSameMonthlyImm(LocalDate base, LocalDate immDate1, LocalDate immDate2, LocalDate immDate3) { LocalDate date = base.plusDays(1); while (!date.isAfter(immDate1)) { assertEquals(DateSequences.MONTHLY_IMM.nextOrSame(date), immDate1); assertEquals(DateSequences.MONTHLY_IMM.nthOrSame(date, 1), immDate1); assertEquals(DateSequences.MONTHLY_IMM.nthOrSame(date, 2), immDate2); assertEquals(DateSequences.MONTHLY_IMM.nthOrSame(date, 3), immDate3); date = date.plusDays(1); } assertEquals(DateSequences.MONTHLY_IMM.dateMatching(YearMonth.from(date)), immDate1); }
@Test(dataProvider = "quarterlyImm") public void test_nextOrSameQuarterlyImm(LocalDate base, LocalDate immDate1, LocalDate immDate2, LocalDate immDate3) { LocalDate date = base.plusDays(1); while (!date.isAfter(immDate1)) { assertEquals(DateSequences.QUARTERLY_IMM.nextOrSame(date), immDate1); assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 1), immDate1); assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 2), immDate2); assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 3), immDate3); date = date.plusDays(1); } assertEquals(DateSequences.QUARTERLY_IMM.dateMatching(YearMonth.from(date)), immDate1); }
@Override public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) { YearMonth fixingMonth = observation.getFixingMonth(); // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { if (fixings.get(fixingMonth.atEndOfMonth()).isPresent()) { return PointSensitivityBuilder.none(); } } throw new MarketDataNotFoundException("Unable to query forward value sensitivity for historic index " + index); }
@Override public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) { YearMonth fixingMonth = observation.getFixingMonth(); // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { if (fixings.get(fixingMonth.atEndOfMonth()).isPresent()) { return PointSensitivityBuilder.none(); } } return InflationRateSensitivity.of(observation, 1d); }
public void test_metadata_end() { IborFutureCurveNode node = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL); LocalDate date = LocalDate.of(2015, 10, 20); LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(date, REF_DATA); LocalDate maturityDate = TEMPLATE.getIndex().calculateMaturityFromEffective(referenceDate, REF_DATA); ParameterMetadata metadata = node.metadata(date, REF_DATA); assertEquals(metadata.getLabel(), LABEL); assertTrue(metadata instanceof YearMonthDateParameterMetadata); assertEquals(((YearMonthDateParameterMetadata) metadata).getDate(), maturityDate); assertEquals(((YearMonthDateParameterMetadata) metadata).getYearMonth(), YearMonth.from(referenceDate)); }
private UnitParameterSensitivities unitParameterSensitivity(YearMonth month) { // If fixing in the past, check time series and returns the historic month price index if present if (month.isBefore(YearMonth.from(valuationDate))) { if (fixings.get(month.atEndOfMonth()).isPresent()) { return UnitParameterSensitivities.empty(); } } double nbMonth = numberOfMonths(month); return UnitParameterSensitivities.of(curve.yValueParameterSensitivity(nbMonth)); }
public void value_multiplicative() { InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF); for (int i = 1; i < TEST_MONTHS.length; i++) { double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS); double valueComputed = curveComputed.yValue(nbMonths); int x = (int) ((nbMonths + 12) % 12); double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths); double adj = SEASONALITY_MULTIPLICATIVE_COMP_2.get(x); double valueExpected = valueNoAdj * adj; assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE); } }
public void test_metadata_last_fixing() { IborFutureCurveNode node = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).withDate(CurveNodeDate.LAST_FIXING); ImmutableMarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, 0.0d).build(); IborFutureTrade trade = node.trade(1d, marketData, REF_DATA); LocalDate fixingDate = trade.getProduct().getFixingDate(); DatedParameterMetadata metadata = node.metadata(VAL_DATE, REF_DATA); assertEquals(metadata.getDate(), fixingDate); LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(VAL_DATE, REF_DATA); assertEquals(((YearMonthDateParameterMetadata) metadata).getYearMonth(), YearMonth.from(referenceDate)); }
public void test_value_pts_sensitivity_futfixing() { for (int i = 0; i < TEST_MONTHS.length; i++) { PointSensitivityBuilder ptsComputed = INSTANCE_WITH_FUTFIXING.valuePointSensitivity(TEST_OBS[i]); YearMonth fixingMonth = TEST_OBS[i].getFixingMonth(); PointSensitivityBuilder ptsExpected; if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { ptsExpected = PointSensitivityBuilder.none(); } else { ptsExpected = InflationRateSensitivity.of(TEST_OBS[i], 1d); } assertTrue(ptsComputed.build().equalWithTolerance(ptsExpected.build(), TOLERANCE_VALUE), "test " + i); } }