Search in sources :

Example 6 with Portfolio

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

Example 7 with Portfolio

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

Example 8 with Portfolio

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

Example 9 with Portfolio

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;
            }
        });
    }
}
Also used : Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Account(name.abuchen.portfolio.model.Account) FormatStyle(java.time.format.FormatStyle) Messages(name.abuchen.portfolio.Messages) MessageFormat(java.text.MessageFormat) List(java.util.List) Dates(name.abuchen.portfolio.util.Dates) Unit(name.abuchen.portfolio.model.Transaction.Unit) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Interval(name.abuchen.portfolio.util.Interval) Portfolio(name.abuchen.portfolio.model.Portfolio) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) LocalDate(java.time.LocalDate)

Example 10 with Portfolio

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()));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Account(name.abuchen.portfolio.model.Account) EnumMap(java.util.EnumMap) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) HashMap(java.util.HashMap) Security(name.abuchen.portfolio.model.Security) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Unit(name.abuchen.portfolio.model.Transaction.Unit) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) MoneyCollectors(name.abuchen.portfolio.money.MoneyCollectors) LocalDate(java.time.LocalDate) Map(java.util.Map) Collections(java.util.Collections) Portfolio(name.abuchen.portfolio.model.Portfolio) Account(name.abuchen.portfolio.model.Account) HashMap(java.util.HashMap) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction)

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