use of name.abuchen.portfolio.checks.Issue in project portfolio by buchen.
the class CrossEntryCheckTest method testThatNotTheSameAccountIsMatched.
@Test
public void testThatNotTheSameAccountIsMatched() {
Account second = new Account();
client.addAccount(second);
LocalDateTime date = LocalDateTime.now();
account.addTransaction(new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.TRANSFER_IN));
AccountTransaction umatched = new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.TRANSFER_OUT);
account.addTransaction(umatched);
second.addTransaction(new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.TRANSFER_OUT));
List<Issue> issues = new CrossEntryCheck().execute(client);
assertThat(issues.size(), is(1));
assertThat(issues.get(0), is(instanceOf(MissingAccountTransferIssue.class)));
assertThat(account.getTransactions(), hasItem(umatched));
assertThat(second.getTransactions().get(0).getCrossEntry(), notNullValue());
assertThat(second.getTransactions().get(0).getType(), is(AccountTransaction.Type.TRANSFER_OUT));
applyFixes(client, issues);
}
use of name.abuchen.portfolio.checks.Issue in project portfolio by buchen.
the class CrossEntryCheckTest method testMissingBuyInAccountIssue.
@Test
public void testMissingBuyInAccountIssue() {
portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 1, security, 1, PortfolioTransaction.Type.SELL, 1, 0));
List<Issue> issues = new CrossEntryCheck().execute(client);
assertThat(issues.size(), is(1));
assertThat(issues.get(0), is(instanceOf(MissingBuySellAccountIssue.class)));
assertThat(issues.get(0).getEntity(), is((Object) portfolio));
applyFixes(client, issues);
}
use of name.abuchen.portfolio.checks.Issue in project portfolio by buchen.
the class SharesHeldConsistencyCheck method execute.
@Override
public List<Issue> execute(Client client) {
List<Issue> issues = new ArrayList<Issue>();
List<Security> securities = client.getSecurities();
for (Portfolio portfolio : client.getPortfolios()) {
long[] shares = new long[securities.size()];
for (PortfolioTransaction t : portfolio.getTransactions()) {
int index = securities.indexOf(t.getSecurity());
// global collection or the security is null -> other checks
if (index < 0)
continue;
switch(t.getType()) {
case BUY:
case TRANSFER_IN:
case DELIVERY_INBOUND:
shares[index] += t.getShares();
break;
case SELL:
case TRANSFER_OUT:
case DELIVERY_OUTBOUND:
shares[index] -= t.getShares();
break;
default:
throw new UnsupportedOperationException();
}
}
for (int ii = 0; ii < shares.length; ii++) {
if (shares[ii] < 0) {
Security security = securities.get(ii);
issues.add(new SharesIssue(portfolio, security, shares[ii]));
}
}
}
return issues;
}
Aggregations