use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientSnapshot method getJointPortfolio.
public PortfolioSnapshot getJointPortfolio() {
if (this.jointPortfolio == null) {
if (portfolios.isEmpty()) {
Portfolio portfolio = new Portfolio();
portfolio.setName(Messages.LabelJointPortfolio);
portfolio.setReferenceAccount(new Account(Messages.LabelJointPortfolio));
this.jointPortfolio = PortfolioSnapshot.create(portfolio, converter, date);
} else if (portfolios.size() == 1) {
this.jointPortfolio = portfolios.get(0);
} else {
this.jointPortfolio = PortfolioSnapshot.merge(portfolios, converter);
}
}
return this.jointPortfolio;
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class PerformanceIndex method calculateAbsoluteInvestedCapital.
/**
* Calculates the absolute invested capital, i.e. starting with the first
* transaction recorded for the client.
*/
public long[] calculateAbsoluteInvestedCapital() {
ToLongBiFunction<Money, LocalDateTime> convertIfNecessary = (amount, date) -> {
if (amount.getCurrencyCode().equals(getCurrencyConverter().getTermCurrency()))
return amount.getAmount();
else
return getCurrencyConverter().convert(date, amount).getAmount();
};
long startValue = 0;
Interval interval = getActualInterval();
LocalDateTime intervalStart = interval.getStart().atStartOfDay();
for (Account account : getClient().getAccounts()) startValue += //
account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DEPOSIT || t.getType() == AccountTransaction.Type.REMOVAL).filter(//
t -> t.getDateTime().isBefore(intervalStart)).mapToLong(t -> {
if (t.getType() == AccountTransaction.Type.DEPOSIT)
return convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else if (t.getType() == AccountTransaction.Type.REMOVAL)
return -convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else
return 0;
}).sum();
for (Portfolio portfolio : getClient().getPortfolios()) startValue += //
portfolio.getTransactions().stream().filter(t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND).filter(//
t -> t.getDateTime().isBefore(intervalStart)).mapToLong(t -> {
if (t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND)
return convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else if (t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND)
return -convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else
return 0;
}).sum();
return calculateInvestedCapital(startValue);
}
use of name.abuchen.portfolio.model.Account 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.Account 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.Account in project portfolio by buchen.
the class ClientClassificationFilter method adaptAccountTransactions.
private void adaptAccountTransactions(CalculationState state, Account account) {
int accountWeight = state.getWeight(account);
for (AccountTransaction t : account.getTransactions()) {
long amount = value(t.getAmount(), accountWeight);
switch(t.getType()) {
case SELL:
// removal in the account
if (!state.isCategorized(t.getSecurity()))
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.DEPOSIT));
break;
case BUY:
if (!state.isCategorized(t.getSecurity()))
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.REMOVAL));
break;
case DIVIDENDS:
if (!state.isCategorized(t.getSecurity()))
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.DEPOSIT));
else
addSecurityRelatedAccountT(state, account, t);
break;
case FEES_REFUND:
if (t.getSecurity() != null && state.isCategorized(t.getSecurity()))
addSecurityRelatedAccountT(state, account, t);
else if (t.getSecurity() != null)
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.DEPOSIT));
else
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, t.getType()));
break;
case FEES:
if (t.getSecurity() != null && state.isCategorized(t.getSecurity()))
addSecurityRelatedAccountT(state, account, t);
else if (t.getSecurity() != null)
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.REMOVAL));
else
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, t.getType()));
break;
case TRANSFER_IN:
// is created.
if (!state.isCategorized((Account) t.getCrossEntry().getCrossOwner(t)))
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.DEPOSIT));
else
addTransferT(state, account, t);
break;
case TRANSFER_OUT:
// then create a removal transaction
if (!state.isCategorized((Account) t.getCrossEntry().getCrossOwner(t)))
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.REMOVAL));
break;
case TAX_REFUND:
// taxes are never included
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.DEPOSIT));
break;
case TAXES:
// taxes are never included
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, AccountTransaction.Type.REMOVAL));
break;
case DEPOSIT:
case REMOVAL:
case INTEREST:
case INTEREST_CHARGE:
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount, null, t.getType()));
break;
default:
throw new UnsupportedOperationException();
}
}
}
Aggregations