Skip to content

Commit

Permalink
Performance calculation on the first day of influx of funds
Browse files Browse the repository at this point in the history
Issue: #62
  • Loading branch information
buchen committed Apr 7, 2013
1 parent d5466cb commit 7f2c0bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,23 @@ public void testThatDepositsOnTheLastDayArePerformanceNeutral()
assertThat(accumulated[accumulated.length - 2], IsCloseTo.closeTo(0.1d, PRECISION));
assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(0.1d, PRECISION));
}

@Test
public void testChangesOnFirstDayOfInvestment()
{
Client client = new Client();
Account account = new Account();
client.addAccount(account);

addT(account, 2012, Calendar.JANUARY, 2, Type.DEPOSIT, 10000);
addT(account, 2012, Calendar.JANUARY, 2, Type.INTEREST, 1000);

ReportingPeriod.FromXtoY reportInterval = new ReportingPeriod.FromXtoY(Dates.date(2012, Calendar.JANUARY, 1), //
Dates.date(2012, Calendar.JANUARY, 10));
PerformanceIndex index = ClientIndex.forPeriod(client, reportInterval, new ArrayList<Exception>());

double[] accumulated = index.getAccumulatedPercentage();
assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(0.1d, PRECISION));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ private void calculate(List<Exception> warnings)

if (thisDelta != 0d)
{
warnings.add(new RuntimeException(MessageFormat.format(Messages.MsgDeltaWithoutAssets, thisDelta,
date.toDate())));
if (transferals[index] != 0)
delta[index] = (double) thisDelta / (double) transferals[index];
else
warnings.add(new RuntimeException(MessageFormat.format(Messages.MsgDeltaWithoutAssets,
thisDelta, date.toDate())));
}
}
else
Expand Down

0 comments on commit 7f2c0bd

Please sign in to comment.