use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class CheckCurrenciesPortfolioTransactionTest method testTransactionIfSecurityIsIndex.
@Test
public void testTransactionIfSecurityIsIndex() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", null);
PortfolioTransaction t = new PortfolioTransaction();
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setType(Type.DELIVERY_OUTBOUND);
t.setSecurity(security);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class CheckValidTypesActionTest method testPortfolioTransaction.
@Test
public void testPortfolioTransaction() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", "EUR");
PortfolioTransaction t = new PortfolioTransaction();
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setSecurity(security);
t.setType(PortfolioTransaction.Type.BUY);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.SELL);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.TRANSFER_IN);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.TRANSFER_OUT);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
t.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class DetectDuplicatesActionTest method portfolio.
private Portfolio portfolio(PortfolioTransaction t) {
Portfolio p = new Portfolio();
p.addTransaction(t);
return p;
}
use of name.abuchen.portfolio.model.Portfolio 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.Portfolio 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()));
}
Aggregations