Search in sources :

Example 71 with Portfolio

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());
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ReadOnlyPortfolio(name.abuchen.portfolio.snapshot.filter.ReadOnlyPortfolio) Portfolio(name.abuchen.portfolio.model.Portfolio) Client(name.abuchen.portfolio.model.Client)

Example 72 with Portfolio

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;
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security)

Example 73 with Portfolio

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();
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio)

Example 74 with Portfolio

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;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Issue(name.abuchen.portfolio.checks.Issue) Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security)

Example 75 with Portfolio

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();
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) CrossEntry(name.abuchen.portfolio.model.CrossEntry) HashSet(java.util.HashSet)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8