use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testThatInterstWithoutInvestmentDoesNotCorruptResultAndIsReported.
@Test
public void testThatInterstWithoutInvestmentDoesNotCorruptResultAndIsReported() {
Client client = new Client();
//
new AccountBuilder().interest(LocalDateTime.of(2012, 01, 02, 0, 0), //
100).addTo(client);
ReportingPeriod.FromXtoY period = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 9));
List<Exception> errors = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, errors);
double[] accumulated = index.getAccumulatedPercentage();
for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(0d, PRECISION));
assertThat(errors.size(), is(1));
assertThat(errors.get(0).getMessage(), startsWith(Messages.MsgDeltaWithoutAssets.substring(0, Messages.MsgDeltaWithoutAssets.indexOf('{'))));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testChangesOnFirstDayOfInvestment.
@Test
public void testChangesOnFirstDayOfInvestment() {
Client client = new Client();
//
new AccountBuilder().deposit_("2012-01-01", //
10000).interest("2012-01-02", //
1000).addTo(client);
ReportingPeriod.FromXtoY reportInterval = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 10));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());
double[] accumulated = index.getAccumulatedPercentage();
assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(0.1d, PRECISION));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testExcelSample.
@Test
public void testExcelSample() {
Client client = createClient();
ReportingPeriod.FromXtoY period = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2011, Month.DECEMBER, 31), LocalDate.of(2012, Month.JANUARY, 8));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, new ArrayList<Exception>());
assertNotNull(index);
assertThat(period.toInterval(), is(index.getReportInterval().toInterval()));
assertThat(client, is(index.getClient()));
LocalDate[] dates = index.getDates();
assertThat(dates.length, is(Dates.daysBetween(period.getStartDate(), period.getEndDate()) + 1));
double[] delta = index.getDeltaPercentage();
assertThat(delta[0], is(0d));
assertThat(delta[1], IsCloseTo.closeTo(0.023d, PRECISION));
assertThat(delta[2], IsCloseTo.closeTo(0.019175455d, PRECISION));
assertThat(delta[3], IsCloseTo.closeTo(-0.0220517d, PRECISION));
assertThat(delta[4], IsCloseTo.closeTo(0.0294117647d, PRECISION));
assertThat(delta[5], IsCloseTo.closeTo(0.0285714286d, PRECISION));
assertThat(delta[6], IsCloseTo.closeTo(0.012261967d, PRECISION));
assertThat(delta[7], IsCloseTo.closeTo(-0.0545454545d, PRECISION));
assertThat(delta[8], IsCloseTo.closeTo(-0.0865384615d, PRECISION));
double[] accumulated = index.getAccumulatedPercentage();
assertThat(accumulated[0], is(0d));
assertThat(accumulated[1], IsCloseTo.closeTo(0.023d, PRECISION));
assertThat(accumulated[2], IsCloseTo.closeTo(0.042616491d, PRECISION));
assertThat(accumulated[3], IsCloseTo.closeTo(0.019624983d, PRECISION));
assertThat(accumulated[4], IsCloseTo.closeTo(0.049614163d, PRECISION));
assertThat(accumulated[5], IsCloseTo.closeTo(0.079603343d, PRECISION));
assertThat(accumulated[6], IsCloseTo.closeTo(0.092841403d, PRECISION));
assertThat(accumulated[7], IsCloseTo.closeTo(0.03323197d, PRECISION));
assertThat(accumulated[8], IsCloseTo.closeTo(-0.056182678d, PRECISION));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testFirstDataPointWhenInsideReportingInterval.
@Test
public void testFirstDataPointWhenInsideReportingInterval() {
Client client = createClient();
ReportingPeriod.FromXtoY period = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2011, Month.DECEMBER, 20), LocalDate.of(2012, Month.JANUARY, 8));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, new ArrayList<Exception>());
assertThat(index.getFirstDataPoint().get(), is(LocalDate.of(2011, 12, 31)));
assertThat(index.getFirstDataPoint().get(), not(period.toInterval().getStart()));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testThatTransferalsDoNotChangePerformance.
@Test
public void testThatTransferalsDoNotChangePerformance() {
double[] delta = { 0d, 0.023d, 0.043d, 0.02d, 0.05d, 0.08d, 0.1d, 0.04d, -0.05d };
long[] transferals = { 1000000, 0, 20000, -40000, 0, 0, 540000, -369704, 0 };
long[] transferals2 = { 1000000, 0, 0, 0, 0, 0, 0, 0, 0 };
Client client = createClient(delta, transferals);
ReportingPeriod.FromXtoY period = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 9));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, new ArrayList<Exception>());
double[] accumulated = index.getAccumulatedPercentage();
for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(delta[ii], PRECISION));
Client anotherClient = createClient(delta, transferals2);
index = PerformanceIndex.forClient(anotherClient, converter, period, new ArrayList<Exception>());
accumulated = index.getAccumulatedPercentage();
for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(delta[ii], PRECISION));
}
Aggregations