Java Code Examples for java.time.YearMonth#isBefore()

The following examples show how to use java.time.YearMonth#isBefore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoricPriceIndexValues.java    From Strata with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 2
Source File: HistoricPriceIndexValues.java    From Strata with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: SimplePriceIndexValues.java    From Strata with Apache License 2.0 5 votes vote down vote up
@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();
    }
  }
  // otherwise, return the estimate from the curve.
  double nbMonth = numberOfMonths(fixingMonth);
  return curve.yValue(nbMonth);
}
 
Example 4
Source File: SimplePriceIndexValues.java    From Strata with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: SimplePriceIndexValues.java    From Strata with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 6
Source File: SimplePriceIndexValuesTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_value_futfixing() {
  for (int i = 0; i < TEST_MONTHS.length; i++) {
    double valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]);
    YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
    double valueExpected;
    if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
      valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
    } else {
      double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
      valueExpected = CURVE_INFL2.yValue(x);
    }
    assertThat(valueComputed).as("test " + i).isCloseTo(valueExpected, offset(TOLERANCE_VALUE));
  }
}
 
Example 7
Source File: SimplePriceIndexValuesTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
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);
    }
    assertThat(ptsComputed.build().equalWithTolerance(ptsExpected.build(), TOLERANCE_VALUE)).as("test " + i).isTrue();
  }
}
 
Example 8
Source File: SimplePriceIndexValuesTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_value_parameter_sensitivity_futfixing() {
  for (int i = 0; i < TEST_MONTHS.length; i++) {
    YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
    if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
      InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d);
      CurrencyParameterSensitivities psComputed = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected);
      double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
      UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x));
      CurrencyParameterSensitivities psExpected =
          sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity());
      assertThat(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA)).as("test " + i).isTrue();
    }
  }
}