InterestRate { public abstract double getDiscountFactor(double t); InterestRate(final double rate); double getRate(); abstract double getDiscountFactor(double t); abstract InterestRate fromContinuous(ContinuousInterestRate continuous); abstract double fromContinuousDerivative(ContinuousInterestRate continuous); abstract InterestRate fromPeriodic(PeriodicInterestRate periodic); abstract ContinuousInterestRate toContinuous(); abstract PeriodicInterestRate toPeriodic(int periodsPerYear); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void simpleDiscountingNegativeDf() { SIMPLE_DSC.getDiscountFactor(10000); }
@Test public void testGetDiscountFactor() { double[] time = {0.01, 1.0, 2.5, 10.0}; for (int looptime = 0; looptime < time.length; looptime++) { assertEquals(1. / ANNUAL.getDiscountFactor(time[looptime]), Math.pow(1 + RATE, time[looptime]), EPS); assertEquals(1. / CONTINUOUS.getDiscountFactor(time[looptime]), Math.exp(RATE * time[looptime]), EPS); assertEquals(1. / QUARTERLY.getDiscountFactor(time[looptime]), Math.pow(1 + RATE / 4, 4 * time[looptime]), EPS); assertEquals("InterestRate: simple money market basis - discount factor", SIMPLE_MM.getDiscountFactor(time[looptime]), 1.0 / (1.0 + RATE * time[looptime]), EPS); assertEquals("InterestRate: simple discounting basis - discount factor", SIMPLE_DSC.getDiscountFactor(time[looptime]), 1.0 - RATE * time[looptime], EPS); } }