//------------------------------------------------------------------------- public virtual void test_rate() { ImmutableRatesProvider prov = createProvider(RATE_START, RATE_END); InflationMonthlyRateComputation ro = InflationMonthlyRateComputation.of(GB_RPIX, REFERENCE_START_MONTH, REFERENCE_END_MONTH); ForwardInflationMonthlyRateComputationFn obsFn = ForwardInflationMonthlyRateComputationFn.DEFAULT; double rateExpected = RATE_END / RATE_START - 1.0; assertEquals(obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov), rateExpected, EPS); // explain ExplainMapBuilder builder = ExplainMap.builder(); assertEquals(obsFn.explainRate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov, builder), rateExpected, EPS); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true); assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 2); ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0); assertEquals(explain0.get(ExplainKey.FIXING_DATE), REFERENCE_START_MONTH.atEndOfMonth()); assertEquals(explain0.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain0.get(ExplainKey.INDEX_VALUE), RATE_START); ExplainMap explain1 = built.get(ExplainKey.OBSERVATIONS).get().get(1); assertEquals(explain1.get(ExplainKey.FIXING_DATE), REFERENCE_END_MONTH.atEndOfMonth()); assertEquals(explain1.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain1.get(ExplainKey.INDEX_VALUE), RATE_END); assertEquals(built.get(ExplainKey.COMBINED_RATE).Value.doubleValue(), rateExpected, EPS); }
//------------------------------------------------------------------------- public virtual void test_rate() { ImmutableRatesProvider prov = createProvider(RATE_END, RATE_END_INTERP); InflationEndInterpolatedRateComputation ro = InflationEndInterpolatedRateComputation.of(GB_RPIX, START_INDEX_VALUE, REF_END_MONTH, WEIGHT); ForwardInflationEndInterpolatedRateComputationFn obsFn = ForwardInflationEndInterpolatedRateComputationFn.DEFAULT; // rate double rateExpected = (WEIGHT * RATE_END + (1.0 - WEIGHT) * RATE_END_INTERP) / START_INDEX_VALUE - 1; assertEquals(obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov), rateExpected, EPS); // explain ExplainMapBuilder builder = ExplainMap.builder(); assertEquals(obsFn.explainRate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov, builder), rateExpected, EPS); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).Present, true); assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 2); ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0); assertEquals(explain0.get(ExplainKey.FIXING_DATE), REF_END_MONTH.atEndOfMonth()); assertEquals(explain0.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain0.get(ExplainKey.INDEX_VALUE), RATE_END); assertEquals(explain0.get(ExplainKey.WEIGHT), WEIGHT); ExplainMap explain1 = built.get(ExplainKey.OBSERVATIONS).get().get(1); assertEquals(explain1.get(ExplainKey.FIXING_DATE), REF_END_MONTH_INTERP.atEndOfMonth()); assertEquals(explain1.get(ExplainKey.INDEX), GB_RPIX); assertEquals(explain1.get(ExplainKey.INDEX_VALUE), RATE_END_INTERP); assertEquals(explain1.get(ExplainKey.WEIGHT), (1d - WEIGHT)); assertEquals(built.get(ExplainKey.COMBINED_RATE).Value.doubleValue(), rateExpected, EPS); }
//------------------------------------------------------------------------- public virtual void test_value() { for (int i = 0; i < TEST_MONTHS.Length; i++) { double valueComputed = INSTANCE.value(TEST_OBS[i]); YearMonth fixingMonth = TEST_OBS[i].FixingMonth; double valueExpected; if (USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).Value; } else { double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS); valueExpected = CURVE_INFL.yValue(x); } assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i); } }
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()).HasValue) { return(UnitParameterSensitivities.empty()); } } double nbMonth = numberOfMonths(month); return(UnitParameterSensitivities.of(curve.yValueParameterSensitivity(nbMonth))); }
//------------------------------------------------------------------------- public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) { YearMonth fixingMonth = observation.FixingMonth; // 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()).HasValue) { return(PointSensitivityBuilder.none()); } } return(InflationRateSensitivity.of(observation, 1d)); }
//------------------------------------------------------------------------- // loads a single fixing series CSV file private static ImmutableMap <ObservableId, LocalDateDoubleTimeSeries> parseSingle(CharSource resource) { IDictionary <ObservableId, LocalDateDoubleTimeSeriesBuilder> builders = new Dictionary <ObservableId, LocalDateDoubleTimeSeriesBuilder>(); try { CsvFile csv = CsvFile.of(resource, true); foreach (CsvRow row in csv.rows()) { string referenceStr = row.getField(REFERENCE_FIELD); string dateStr = row.getField(DATE_FIELD); string valueStr = row.getField(VALUE_FIELD); Index index = LoaderUtils.findIndex(referenceStr); ObservableId id = IndexQuoteId.of(index); double value = double.Parse(valueStr); LocalDate date; if (index is PriceIndex) { try { YearMonth ym = LoaderUtils.parseYearMonth(dateStr); date = ym.atEndOfMonth(); } catch (Exception) { date = LoaderUtils.parseDate(dateStr); if (date.DayOfMonth != date.lengthOfMonth()) { throw new System.ArgumentException(Messages.format("Fixing Series CSV loader for price index must have date at end of month: {}", resource)); } } } else { date = LoaderUtils.parseDate(dateStr); } LocalDateDoubleTimeSeriesBuilder builder = builders.computeIfAbsent(id, k => LocalDateDoubleTimeSeries.builder()); builder.put(date, value); } } catch (Exception ex) { throw new System.ArgumentException(Messages.format("Error processing resource as CSV file: {}", resource), ex); } return(MapStream.of(builders).mapValues(builder => builder.build()).toMap()); }
public virtual void test_value_parameter_sensitivity() { for (int i = 0; i < TEST_MONTHS.Length; i++) { YearMonth fixingMonth = TEST_OBS[i].FixingMonth; if (!USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) { InflationRateSensitivity ptsExpected = (InflationRateSensitivity)InflationRateSensitivity.of(TEST_OBS[i], 1d); CurrencyParameterSensitivities psComputed = INSTANCE.parameterSensitivity(ptsExpected); double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS); UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL.yValueParameterSensitivity(x)); CurrencyParameterSensitivities psExpected = sens1.multipliedBy(ptsExpected.Currency, ptsExpected.Sensitivity); assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i); } } }
public virtual void test_value_pts_sensitivity() { for (int i = 0; i < TEST_MONTHS.Length; i++) { PointSensitivityBuilder ptsComputed = INSTANCE.valuePointSensitivity(TEST_OBS[i]); YearMonth fixingMonth = TEST_OBS[i].FixingMonth; PointSensitivityBuilder ptsExpected; if (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); } }
//------------------------------------------------------------------------- public double value(PriceIndexObservation observation) { YearMonth fixingMonth = observation.FixingMonth; // If fixing in the past, check time series and returns the historic month price index if present if (fixingMonth.isBefore(YearMonth.from(valuationDate))) { double?fixing = fixings.get(fixingMonth.atEndOfMonth()); if (fixing.HasValue) { return(fixing.Value); } } // otherwise, return the estimate from the curve. double nbMonth = numberOfMonths(fixingMonth); return(curve.yValue(nbMonth)); }