use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PortfolioSnapshot method merge.
public static PortfolioSnapshot merge(List<PortfolioSnapshot> snapshots, CurrencyConverter converter) {
if (snapshots.isEmpty())
// $NON-NLS-1$
throw new IllegalArgumentException("Error: PortfolioSnapshots to be merged must not be empty");
Portfolio portfolio = new Portfolio() {
@Override
public void shallowDeleteTransaction(PortfolioTransaction transaction, Client client) {
throw new UnsupportedOperationException();
}
@Override
public void deleteTransaction(PortfolioTransaction transaction, Client client) {
throw new UnsupportedOperationException();
}
};
portfolio.setName(Messages.LabelJointPortfolio);
Account referenceAccount = new Account(Messages.LabelJointPortfolio);
referenceAccount.setCurrencyCode(converter.getTermCurrency());
portfolio.setReferenceAccount(referenceAccount);
snapshots.forEach(s -> portfolio.addAllTransaction(s.getSource().getTransactions()));
return create(portfolio, snapshots.get(0).getCurrencyConverter(), snapshots.get(0).getTime());
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ClientClassificationFilter method filter.
@Override
public Client filter(Client client) {
ReadOnlyClient pseudoClient = new ReadOnlyClient(client);
CalculationState state = new CalculationState(classification);
for (Account account : client.getAccounts()) {
ReadOnlyAccount pseudo = new ReadOnlyAccount(account);
pseudoClient.internalAddAccount(pseudo);
state.putReadOnly(account, pseudo);
}
for (Portfolio portfolio : client.getPortfolios()) {
ReadOnlyPortfolio pseudoPortfolio = new ReadOnlyPortfolio(portfolio);
pseudoPortfolio.setReferenceAccount(state.asReadOnly(portfolio.getReferenceAccount()));
pseudoClient.internalAddPortfolio(pseudoPortfolio);
state.putReadOnly(portfolio, pseudoPortfolio);
}
for (Portfolio portfolio : client.getPortfolios()) adaptPortfolioTransactions(state, portfolio);
for (Account account : client.getAccounts()) {
if (state.isCategorized(account))
adaptAccountTransactions(state, account);
else
collectSecurityRelatedTx(state, account);
}
for (Security security : state.categorizedSecurities) pseudoClient.internalAddSecurity(security);
return pseudoClient;
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ConvertDeliveryToBuySellAction method run.
@Override
public void run() {
// delete existing transaction
PortfolioTransaction deliveryTransaction = transaction.getTransaction();
transaction.getOwner().deleteTransaction(deliveryTransaction, client);
// create new buy / sell
Portfolio portfolio = (Portfolio) transaction.getOwner();
Account account = portfolio.getReferenceAccount();
BuySellEntry entry = new BuySellEntry(portfolio, account);
entry.setType(deliveryTransaction.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND ? PortfolioTransaction.Type.BUY : PortfolioTransaction.Type.SELL);
entry.setDate(deliveryTransaction.getDateTime());
entry.setMonetaryAmount(deliveryTransaction.getMonetaryAmount());
entry.setSecurity(deliveryTransaction.getSecurity());
entry.setNote(deliveryTransaction.getNote());
entry.setShares(deliveryTransaction.getShares());
deliveryTransaction.getUnits().forEach(entry.getPortfolioTransaction()::addUnit);
entry.insert();
client.markDirty();
}
use of name.abuchen.portfolio.model.Portfolio 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;
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class DanglingAccountsCheck method execute.
@Override
public List<Issue> execute(Client client) {
Set<Account> accounts = new HashSet<Account>(client.getAccounts());
for (Portfolio portfolio : client.getPortfolios()) {
Account referenceAccount = portfolio.getReferenceAccount();
check(client, accounts, referenceAccount);
for (PortfolioTransaction transaction : portfolio.getTransactions()) {
CrossEntry entry = transaction.getCrossEntry();
if (!(entry instanceof BuySellEntry))
continue;
Account account = (Account) entry.getCrossOwner(transaction);
check(client, accounts, account);
}
}
return Collections.emptyList();
}
Aggregations