public void adjust_notNegative() { assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(1d), 1d, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(0d), 0d, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(-0d), 0d, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(-1d), 0d, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(Double.MAX_VALUE), Double.MAX_VALUE, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(Double.MIN_VALUE), Double.MIN_VALUE, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(Double.NEGATIVE_INFINITY), 0d, 0d); assertEquals(NegativeRateMethod.NOT_NEGATIVE.adjust(Double.NaN), Double.NaN); // force to Double for comparison }
@Test(dataProvider = "name") public void test_of_lookup(NegativeRateMethod convention, String name) { assertEquals(NegativeRateMethod.of(name), convention); }
@Test(dataProvider = "name") public void test_toString(NegativeRateMethod convention, String name) { assertEquals(convention.toString(), name); }
public void test_of_lookup_notFound() { assertThrows(() -> NegativeRateMethod.of("Rubbish"), IllegalArgumentException.class); }
public void adjust_allowNegative() { assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(1d), 1d, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(0d), 0d, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(-0d), -0d, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(-1d), -1d, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(Double.MAX_VALUE), Double.MAX_VALUE, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(Double.MIN_VALUE), Double.MIN_VALUE, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0d); assertEquals(NegativeRateMethod.ALLOW_NEGATIVE.adjust(Double.NaN), Double.NaN); // force to Double for comparison }
public void test_of_lookup_null() { assertThrows(() -> NegativeRateMethod.of(null), IllegalArgumentException.class); }
private double unitNotionalAccrualRaw(RateAccrualPeriod accrualPeriod, double rawRate, double spread) { double treatedRate = rawRate * accrualPeriod.getGearing() + spread; return accrualPeriod.getNegativeRateMethod().adjust(treatedRate * accrualPeriod.getYearFraction()); }
private static RateCalculation parseOvernightRateCalculation( CsvRow row, String leg, OvernightIndex overnightIndex, OvernightAccrualMethod accrualMethod) { OvernightRateCalculation.Builder builder = OvernightRateCalculation.builder(); // basics builder.index(overnightIndex); builder.accrualMethod(findValue(row, leg, ACCRUAL_METHOD_FIELD) .map(s -> OvernightAccrualMethod.of(s)) .orElse(accrualMethod)); // optionals findValue(row, leg, DAY_COUNT_FIELD) .map(s -> LoaderUtils.parseDayCount(s)) .ifPresent(v -> builder.dayCount(v)); findValue(row, leg, RATE_CUT_OFF_DAYS_FIELD) .map(s -> Integer.valueOf(s)) .ifPresent(v -> builder.rateCutOffDays(v)); findValue(row, leg, NEGATIVE_RATE_METHOD_FIELD).map(s -> NegativeRateMethod.of(s)) .ifPresent(v -> builder.negativeRateMethod(v)); findValue(row, leg, GEARING_FIELD) .map(s -> LoaderUtils.parseDouble(s)) .ifPresent(v -> builder.gearing(ValueSchedule.of(v))); findValue(row, leg, SPREAD_FIELD) .map(s -> LoaderUtils.parseDoublePercent(s)) .ifPresent(v -> builder.spread(ValueSchedule.of(v))); return builder.build(); }
private void explainPresentValue( RateAccrualPeriod accrualPeriod, DayCount dayCount, Currency currency, double notional, RatesProvider provider, ExplainMapBuilder builder) { double rawRate = rateComputationFn.explainRate( accrualPeriod.getRateComputation(), accrualPeriod.getStartDate(), accrualPeriod.getEndDate(), provider, builder); double payOffRate = rawRate * accrualPeriod.getGearing() + accrualPeriod.getSpread(); double ua = unitNotionalAccrual(accrualPeriod, accrualPeriod.getSpread(), provider); // Note that the forecast value is not published since this is potentially misleading when // compounding is being applied, and when it isn't then it's the same as the forecast // value of the payment period. builder.put(ExplainKey.ENTRY_TYPE, "AccrualPeriod"); builder.put(ExplainKey.START_DATE, accrualPeriod.getStartDate()); builder.put(ExplainKey.UNADJUSTED_START_DATE, accrualPeriod.getUnadjustedStartDate()); builder.put(ExplainKey.END_DATE, accrualPeriod.getEndDate()); builder.put(ExplainKey.UNADJUSTED_END_DATE, accrualPeriod.getUnadjustedEndDate()); builder.put(ExplainKey.ACCRUAL_YEAR_FRACTION, accrualPeriod.getYearFraction()); builder.put(ExplainKey.ACCRUAL_DAYS, dayCount.days(accrualPeriod.getStartDate(), accrualPeriod.getEndDate())); builder.put(ExplainKey.DAYS, (int) DAYS.between(accrualPeriod.getStartDate(), accrualPeriod.getEndDate())); builder.put(ExplainKey.GEARING, accrualPeriod.getGearing()); builder.put(ExplainKey.SPREAD, accrualPeriod.getSpread()); builder.put(ExplainKey.PAY_OFF_RATE, accrualPeriod.getNegativeRateMethod().adjust(payOffRate)); builder.put(ExplainKey.UNIT_AMOUNT, ua); }
FIXING_OFFSET_ADJ_CAL_FIELD); fixingAdjOpt.ifPresent(v -> builder.fixingDateOffset(v)); findValue(row, leg, NEGATIVE_RATE_METHOD_FIELD).map(s -> NegativeRateMethod.of(s)) .ifPresent(v -> builder.negativeRateMethod(v)); findValue(row, leg, FIRST_RATE_FIELD)