use of name.abuchen.portfolio.model.PortfolioTransferEntry in project portfolio by buchen.
the class CSVPortfolioTransactionExtractor method createTransfer.
private Item createTransfer(Security security, Money amount, Long fees, Long taxes, LocalDateTime date, String note, Long shares, Unit grossAmount) {
PortfolioTransferEntry entry = new PortfolioTransferEntry();
entry.setSecurity(security);
entry.setDate(date);
entry.setAmount(Math.abs(amount.getAmount()));
entry.setCurrencyCode(amount.getCurrencyCode());
entry.setShares(shares);
entry.setNote(note);
return new PortfolioTransferItem(entry);
}
use of name.abuchen.portfolio.model.PortfolioTransferEntry in project portfolio by buchen.
the class TransactionCurrencyCheck method execute.
@Override
public List<Issue> execute(Client client) {
Set<Object> transactions = new HashSet<Object>();
for (Account account : client.getAccounts()) {
account.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<AccountTransaction>(account, t)));
}
for (Portfolio portfolio : client.getPortfolios()) {
portfolio.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<PortfolioTransaction>(portfolio, t)));
}
List<Issue> issues = new ArrayList<Issue>();
for (Object t : transactions) {
if (t instanceof TransactionPair<?>) {
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = (TransactionPair<Transaction>) t;
issues.add(new TransactionMissingCurrencyIssue(client, pair));
} else if (t instanceof BuySellEntry) {
// attempt to fix it if both currencies are identical. If a fix
// involves currency conversion plus exchange rates, just offer
// to delete the transaction.
BuySellEntry entry = (BuySellEntry) t;
String accountCurrency = entry.getAccount().getCurrencyCode();
String securityCurrency = entry.getPortfolioTransaction().getSecurity().getCurrencyCode();
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getAccountTransaction()), entry.getAccountTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(accountCurrency, securityCurrency)));
} else if (t instanceof AccountTransferEntry) {
// same story as with purchases: only offer to fix if currencies
// match
AccountTransferEntry entry = (AccountTransferEntry) t;
String sourceCurrency = entry.getSourceAccount().getCurrencyCode();
String targetCurrency = entry.getTargetAccount().getCurrencyCode();
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(sourceCurrency, targetCurrency)));
} else if (t instanceof PortfolioTransferEntry) {
// transferring a security involves no currency change because
// the currency is defined the security itself
PortfolioTransferEntry entry = (PortfolioTransferEntry) t;
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair));
} else {
throw new IllegalArgumentException();
}
}
return issues;
}
use of name.abuchen.portfolio.model.PortfolioTransferEntry in project portfolio by buchen.
the class CSVPortfolioTransactionExtractorTest method testTransferTransaction.
@Test
public void testTransferTransaction() throws ParseException {
Client client = new Client();
Security security = new Security();
security.setTickerSymbol("SAP.DE");
client.addSecurity(security);
CSVExtractor extractor = new CSVPortfolioTransactionExtractor(client);
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(0, Arrays.<String[]>asList(new String[] { "2013-01-01", "DE0007164600", "SAP.DE", "", "SAP SE", "100", "EUR", "11", "10", "", "", "", "1,2", "TRANSFER_IN", "Notiz" }), buildField2Column(extractor), errors);
assertThat(errors, empty());
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);
PortfolioTransferEntry entry = (PortfolioTransferEntry) results.stream().filter(i -> i instanceof PortfolioTransferItem).findAny().get().getSubject();
PortfolioTransaction source = entry.getSourceTransaction();
assertThat(source.getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));
assertThat(source.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(source.getNote(), is("Notiz"));
assertThat(source.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
assertThat(source.getShares(), is(Values.Share.factorize(1.2)));
assertThat(source.getSecurity(), is(security));
// security transfers do not support fees and taxes at the moment
assertThat(source.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
assertThat(source.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 0)));
PortfolioTransaction target = entry.getTargetTransaction();
assertThat(target.getType(), is(PortfolioTransaction.Type.TRANSFER_IN));
assertThat(target.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
assertThat(target.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 0)));
}
use of name.abuchen.portfolio.model.PortfolioTransferEntry in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossPortfolioTransfersAreKept.
@Test
public void testCrossPortfolioTransfersAreKept() {
Portfolio portfolioA = client.getPortfolios().get(0);
Portfolio portfolioB = client.getPortfolios().get(1);
PortfolioTransferEntry entry = new PortfolioTransferEntry(portfolioA, portfolioB);
entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
entry.setAmount(Values.Amount.factorize(10));
entry.setShares(Values.Share.factorize(1));
entry.setSecurity(client.getSecurities().get(0));
entry.insert();
Client result = new PortfolioClientFilter(Arrays.asList(portfolioA, portfolioB), Collections.emptyList()).filter(client);
assertThat(result.getPortfolios().size(), is(2));
assertThat(result.getAccounts().size(), is(2));
Portfolio portfolio = result.getPortfolios().get(0);
// check that the 4 transactions are transformed:
// - buy -> inbound delivery
// - transfer must exist
assertThat(portfolio.getTransactions().size(), is(2));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.TRANSFER_OUT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
use of name.abuchen.portfolio.model.PortfolioTransferEntry in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossPortfolioTransfersAreConvertedToDeliveries.
@Test
public void testCrossPortfolioTransfersAreConvertedToDeliveries() {
Portfolio portfolioA = client.getPortfolios().get(0);
Portfolio portfolioB = client.getPortfolios().get(1);
PortfolioTransferEntry entry = new PortfolioTransferEntry(portfolioA, portfolioB);
entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
entry.setAmount(Values.Amount.factorize(10));
entry.setShares(Values.Share.factorize(1));
entry.setSecurity(client.getSecurities().get(0));
entry.insert();
Client result = new PortfolioClientFilter(Arrays.asList(portfolioA), Collections.emptyList()).filter(client);
assertThat(result.getPortfolios().size(), is(1));
assertThat(result.getAccounts().size(), is(1));
Portfolio portfolio = result.getPortfolios().get(0);
// check that the 4 transactions are transformed:
// - buy -> inbound delivery
// - transfer -> outbound delivery
assertThat(portfolio.getTransactions().size(), is(2));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
portfolio.getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
// check the other portfolio
result = new PortfolioClientFilter(Arrays.asList(portfolioB), Collections.emptyList()).filter(client);
assertThat(//
result.getPortfolios().get(0).getTransactions().stream().filter(//
t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
Aggregations