private AccountTransaction convertTo(AccountTransaction t, AccountTransaction.Type type) { AccountTransaction clone = new AccountTransaction(); clone.setType(type); clone.setDate(t.getDate()); clone.setCurrencyCode(t.getCurrencyCode()); clone.setSecurity(null); // no security for REMOVAL or DEPOSIT clone.setAmount(t.getAmount()); clone.setShares(t.getShares()); // do *not* copy units as REMOVAL and DEPOSIT have never units return clone; }
private void collectDividends( Portfolio portfolio, ReadOnlyAccount pseudoAccount, Set<Security> usedSecurities) { if (portfolio.getReferenceAccount() == null) return; for (AccountTransaction t : portfolio.getReferenceAccount().getTransactions()) // NOSONAR { if (t.getSecurity() == null) continue; if (!usedSecurities.contains(t.getSecurity())) continue; switch (t.getType()) { case TAX_REFUND: // security must be non-null -> tax refund is relevant for // performance of security case DIVIDENDS: pseudoAccount.internalAddTransaction(t); pseudoAccount.internalAddTransaction( new AccountTransaction( t.getDate(), t.getCurrencyCode(), t.getAmount(), null, AccountTransaction.Type.REMOVAL)); break; case BUY: case TRANSFER_IN: case SELL: case TRANSFER_OUT: case DEPOSIT: case REMOVAL: case INTEREST: case INTEREST_CHARGE: case TAXES: case FEES: // do nothing break; default: throw new UnsupportedOperationException(); } } }
private static void extractSecurityRelatedAccountTransactions( Account account, ReportingPeriod period, Map<Security, SecurityPerformanceRecord> records) { for (AccountTransaction t : account.getTransactions()) { if (t.getSecurity() == null) continue; if (!period.containsTransaction().test(t)) continue; if (t.getType() == AccountTransaction.Type.DIVIDENDS // || t.getType() == AccountTransaction.Type.INTEREST) { DividendTransaction dt = new DividendTransaction(); dt.setDate(t.getDate()); dt.setSecurity(t.getSecurity()); dt.setAccount(account); dt.setCurrencyCode(t.getCurrencyCode()); dt.setAmount(t.getAmount()); dt.setShares(t.getShares()); dt.setNote(t.getNote()); records.get(t.getSecurity()).addTransaction(dt); } else if (t.getType() == AccountTransaction.Type.TAX_REFUND) { records.get(t.getSecurity()).addTransaction(t); } } }