use of name.abuchen.portfolio.AccountBuilder in project portfolio by buchen.
the class PortfolioClientFilterTest method setupClient.
/**
* Creates three portfolios (A-C) with a reference account each.
*/
@Before
public void setupClient() {
client = new Client();
Security security = new SecurityBuilder().addTo(client);
// 2016-01-01 deposit
// 2016-02-01 buy
// 2016-03-01 dividend
Arrays.asList("A", "B", "C").forEach(index -> {
Account a = //
new AccountBuilder().deposit_("2016-01-01", Values.Amount.factorize(100)).dividend("2016-03-01", Values.Amount.factorize(10), //
security).addTo(client);
a.setName(index);
Portfolio p = //
new PortfolioBuilder(a).buy(security, "2016-02-01", Values.Share.factorize(1), Values.Amount.factorize(100)).addTo(client);
p.setName(index);
});
}
use of name.abuchen.portfolio.AccountBuilder in project portfolio by buchen.
the class ClientIndexTest method createClient.
private Client createClient() {
Client client = new Client();
//
new AccountBuilder().deposit_("2011-12-31", //
10000 * Values.Amount.factor()).interest("2012-01-01", //
230 * Values.Amount.factor()).deposit_("2012-01-02", //
200 * Values.Amount.factor()).interest("2012-01-02", //
200 * Values.Amount.factor()).withdraw("2012-01-03", //
400 * Values.Amount.factor()).fees____("2012-01-03", //
23441).interest("2012-01-04", //
29399).interest("2012-01-05", //
29399).deposit_("2012-01-06", //
5400 * Values.Amount.factor()).interest("2012-01-06", //
19599).withdraw("2012-01-07", //
369704).fees____("2012-01-07", //
88252).fees____("2012-01-08", //
100385).addTo(client);
return client;
}
use of name.abuchen.portfolio.AccountBuilder 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.AccountBuilder in project portfolio by buchen.
the class ClientIndexTest method createClient.
private Client createClient(double[] delta, long[] transferals) {
Client client = new Client();
AccountBuilder account = new AccountBuilder();
LocalDateTime time = LocalDateTime.of(2012, Month.JANUARY, 1, 0, 0);
long valuation = 0;
double quote = 1;
for (int ii = 0; ii < delta.length; ii++) {
// the idea: inbound transferals are added at the beginning of the
// day and hence contribute to the performance. Outbound transferals
// are deducted at the end of the day.
long inbound = transferals[ii] > 0 ? transferals[ii] : 0;
long v = (long) Math.round((double) (valuation + inbound) * (delta[ii] + 1) / quote) - inbound;
long d = v - valuation;
if (transferals[ii] > 0)
account.deposit_(time, transferals[ii]);
else if (transferals[ii] < 0)
account.withdraw(time, Math.abs(transferals[ii]));
if (v > 0)
account.interest(time, d);
else if (v < 0)
account.fees____(time, Math.abs(d));
valuation = v + transferals[ii];
quote = 1 + delta[ii];
time = time.plusDays(1);
}
account.addTo(client);
return client;
}
use of name.abuchen.portfolio.AccountBuilder 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));
}
Aggregations