use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class DetectDuplicatesActionTest method account.
private Account account(AccountTransaction t) {
Account a = new Account();
a.setCurrencyCode(t.getCurrencyCode());
a.addTransaction(t);
return a;
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientIndex method collectTransferalsAndTaxes.
private void collectTransferalsAndTaxes(Interval interval) {
for (Account account : getClient().getAccounts()) {
//
account.getTransactions().stream().filter(t -> !t.getDateTime().toLocalDate().isBefore(interval.getStart()) && !t.getDateTime().toLocalDate().isAfter(interval.getEnd())).forEach(t -> {
// NOSONAR
LocalDate d = t.getDateTime().toLocalDate();
switch(t.getType()) {
case DEPOSIT:
addValue(inboundTransferals, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
case REMOVAL:
addValue(outboundTransferals, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
case TAXES:
addValue(taxes, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
case TAX_REFUND:
addValue(taxes, t.getCurrencyCode(), -t.getAmount(), interval, d);
break;
case DIVIDENDS:
addValue(taxes, t.getCurrencyCode(), t.getUnitSum(Unit.Type.TAX).getAmount(), interval, d);
addValue(dividends, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
case INTEREST:
addValue(interest, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
case INTEREST_CHARGE:
addValue(interest, t.getCurrencyCode(), -t.getAmount(), interval, d);
addValue(interestCharge, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
default:
// do nothing
break;
}
});
}
for (Portfolio portfolio : getClient().getPortfolios()) {
//
portfolio.getTransactions().stream().filter(t -> !t.getDateTime().toLocalDate().isBefore(interval.getStart()) && !t.getDateTime().toLocalDate().isAfter(interval.getEnd())).forEach(t -> {
LocalDate d = t.getDateTime().toLocalDate();
// collect taxes
addValue(//
taxes, //
t.getCurrencyCode(), //
t.getUnitSum(Unit.Type.TAX).getAmount(), interval, d);
// collect transferals
switch(t.getType()) {
case DELIVERY_INBOUND:
addValue(inboundTransferals, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
case DELIVERY_OUTBOUND:
addValue(outboundTransferals, t.getCurrencyCode(), t.getAmount(), interval, d);
break;
default:
break;
}
});
}
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshot method addEarnings.
private void addEarnings() {
MutableMoney mEarnings = MutableMoney.of(converter.getTermCurrency());
MutableMoney mOtherEarnings = MutableMoney.of(converter.getTermCurrency());
MutableMoney mFees = MutableMoney.of(converter.getTermCurrency());
MutableMoney mTaxes = MutableMoney.of(converter.getTermCurrency());
MutableMoney mDeposits = MutableMoney.of(converter.getTermCurrency());
MutableMoney mRemovals = MutableMoney.of(converter.getTermCurrency());
Map<Security, MutableMoney> earningsBySecurity = new HashMap<>();
for (Account account : client.getAccounts()) {
for (AccountTransaction t : account.getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
switch(t.getType()) {
case DIVIDENDS:
case INTEREST:
addEarningTransaction(account, t, mEarnings, mOtherEarnings, mTaxes, earningsBySecurity);
break;
case INTEREST_CHARGE:
Money charged = t.getMonetaryAmount().with(converter.at(t.getDateTime()));
mEarnings.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
earnings.add(new TransactionPair<AccountTransaction>(account, t));
mOtherEarnings.subtract(charged);
break;
case DEPOSIT:
mDeposits.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case REMOVAL:
mRemovals.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case FEES:
mFees.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
fees.add(new TransactionPair<AccountTransaction>(account, t));
break;
case FEES_REFUND:
mFees.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
fees.add(new TransactionPair<AccountTransaction>(account, t));
break;
case TAXES:
mTaxes.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
taxes.add(new TransactionPair<AccountTransaction>(account, t));
break;
case TAX_REFUND:
mTaxes.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
taxes.add(new TransactionPair<AccountTransaction>(account, t));
break;
case BUY:
case SELL:
case TRANSFER_IN:
case TRANSFER_OUT:
// no operation
break;
default:
throw new UnsupportedOperationException();
}
}
}
for (Portfolio portfolio : client.getPortfolios()) {
for (PortfolioTransaction t : portfolio.getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
Money unit = t.getUnitSum(Unit.Type.FEE, converter);
if (!unit.isZero()) {
mFees.add(unit);
fees.add(new TransactionPair<PortfolioTransaction>(portfolio, t));
}
unit = t.getUnitSum(Unit.Type.TAX, converter);
if (!unit.isZero()) {
mTaxes.add(unit);
taxes.add(new TransactionPair<PortfolioTransaction>(portfolio, t));
}
switch(t.getType()) {
case DELIVERY_INBOUND:
mDeposits.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case DELIVERY_OUTBOUND:
mRemovals.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case BUY:
case SELL:
case TRANSFER_IN:
case TRANSFER_OUT:
break;
default:
throw new UnsupportedOperationException();
}
}
}
Category earningsCategory = categories.get(CategoryType.EARNINGS);
earningsCategory.valuation = mEarnings.toMoney();
earningsCategory.positions = earningsBySecurity.entrySet().stream().filter(entry -> !entry.getValue().isZero()).map(entry -> new Position(entry.getKey(), entry.getValue().toMoney())).sorted(//
(p1, p2) -> p1.getLabel().compareToIgnoreCase(p2.getLabel())).collect(Collectors.toList());
if (!mOtherEarnings.isZero())
earningsCategory.positions.add(new Position(Messages.LabelInterest, mOtherEarnings.toMoney()));
categories.get(CategoryType.FEES).valuation = mFees.toMoney();
categories.get(CategoryType.TAXES).valuation = mTaxes.toMoney();
categories.get(CategoryType.TRANSFERS).valuation = mDeposits.toMoney().subtract(mRemovals.toMoney());
categories.get(CategoryType.TRANSFERS).positions.add(new Position(Messages.LabelDeposits, mDeposits.toMoney()));
categories.get(CategoryType.TRANSFERS).positions.add(new Position(Messages.LabelRemovals, mRemovals.toMoney()));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientClassificationFilter method addTransferT.
private void addTransferT(CalculationState state, Account inboundAccount, AccountTransaction t) {
Account outboundAccount = (Account) t.getCrossEntry().getCrossOwner(t);
int inboundWeight = state.getWeight(inboundAccount);
int outboundWeight = state.getWeight(outboundAccount);
if (inboundWeight == outboundWeight && inboundWeight == Classification.ONE_HUNDRED_PERCENT) {
state.asReadOnly(inboundAccount).internalAddTransaction(t);
state.asReadOnly(outboundAccount).internalAddTransaction((AccountTransaction) t.getCrossEntry().getCrossTransaction(t));
} else if (inboundWeight == outboundWeight) {
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), inboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
} else if (inboundWeight < outboundWeight) {
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), inboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
AccountTransaction ot = (AccountTransaction) t.getCrossEntry().getCrossTransaction(t);
state.asReadOnly(outboundAccount).internalAddTransaction(new AccountTransaction(ot.getDateTime(), ot.getCurrencyCode(), value(ot.getAmount(), outboundWeight - inboundWeight), null, AccountTransaction.Type.REMOVAL));
} else // inboundWeight > outboundWeight
{
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), outboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
state.asReadOnly(inboundAccount).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), value(t.getAmount(), inboundWeight - outboundWeight), null, AccountTransaction.Type.DEPOSIT));
}
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientClassificationFilter method addBuySellT.
private void addBuySellT(CalculationState state, Portfolio portfolio, PortfolioTransaction t) {
int securityWeight = state.getWeight(t.getSecurity());
long taxes = value(t.getUnitSum(Unit.Type.TAX).getAmount(), securityWeight);
long securityAmount = value(t.getAmount(), securityWeight);
securityAmount = t.getType() == PortfolioTransaction.Type.BUY ? securityAmount - taxes : securityAmount + taxes;
Account account = (Account) t.getCrossEntry().getCrossOwner(t);
int accountWeight = state.getWeight(account);
long accountAmount = value(t.getAmount(), accountWeight);
long commonAmount = Math.min(securityAmount, accountAmount);
int commonWeight = (int) Math.round(((double) commonAmount / (double) securityAmount) * securityWeight);
// create a buy/sell transactions with the amount shared by the account
// assignment and the security assignment
BuySellEntry copy = new BuySellEntry(state.asReadOnly(portfolio), state.account2readonly.get(account));
copy.setDate(t.getDateTime());
copy.setCurrencyCode(t.getCurrencyCode());
copy.setSecurity(t.getSecurity());
copy.setType(t.getType());
copy.setNote(t.getNote());
copy.setShares(value(t.getShares(), commonWeight));
copy.setAmount(commonAmount);
// copy all units (except for taxes) over to the new transaction
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> copy.getPortfolioTransaction().addUnit(value(u, commonWeight)));
state.asReadOnly(portfolio).internalAddTransaction(copy.getPortfolioTransaction());
state.asReadOnly(account).internalAddTransaction(copy.getAccountTransaction());
if (accountAmount - commonAmount > 0) {
AccountTransaction ta = new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), accountAmount - commonAmount, null, t.getType() == PortfolioTransaction.Type.BUY ? AccountTransaction.Type.REMOVAL : AccountTransaction.Type.DEPOSIT);
state.asReadOnly(account).internalAddTransaction(ta);
}
if (securityAmount - commonAmount > 0) {
PortfolioTransaction tp = new PortfolioTransaction();
tp.setDateTime(t.getDateTime());
tp.setCurrencyCode(t.getCurrencyCode());
tp.setSecurity(t.getSecurity());
tp.setShares(value(t.getShares(), securityWeight - commonWeight));
tp.setType(t.getType() == PortfolioTransaction.Type.BUY ? PortfolioTransaction.Type.DELIVERY_INBOUND : PortfolioTransaction.Type.DELIVERY_OUTBOUND);
tp.setAmount(securityAmount - commonAmount);
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> tp.addUnit(value(u, securityWeight - commonWeight)));
state.asReadOnly(portfolio).internalAddTransaction(tp);
}
}
Aggregations