Search in sources :

Example 1 with AccountTransferEntry

use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.

the class CSVAccountTransactionExtractorTest method testTransferTransaction.

@Test
public void testTransferTransaction() {
    Client client = new Client();
    CSVExtractor extractor = new CSVAccountTransactionExtractor(client);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, // 
    Arrays.<String[]>asList(new String[] { "2013-01-01", "", "", "", "100", "EUR", "TRANSFER_OUT", "", "", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(results.size(), is(1));
    assertThat(errors, empty());
    AccountTransferEntry entry = (AccountTransferEntry) results.get(0).getSubject();
    AccountTransaction t = entry.getSourceTransaction();
    assertThat(t.getType(), is(AccountTransaction.Type.TRANSFER_OUT));
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(t.getNote(), is("Notiz"));
    assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
    assertThat(t.getShares(), is(0L));
    assertThat(t.getSecurity(), is(nullValue()));
}
Also used : Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 2 with AccountTransferEntry

use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.

the class ClientClassificationFilter method createTransferEntry.

private AccountTransferEntry createTransferEntry(AccountTransferEntry entry, int weight) {
    AccountTransferEntry copy = new AccountTransferEntry();
    copy.setDate(entry.getSourceTransaction().getDateTime());
    copy.setNote(entry.getSourceTransaction().getNote());
    copy.getSourceTransaction().setCurrencyCode(entry.getSourceTransaction().getCurrencyCode());
    copy.getTargetTransaction().setCurrencyCode(entry.getTargetTransaction().getCurrencyCode());
    copy.getSourceTransaction().setAmount(value(entry.getSourceTransaction().getAmount(), weight));
    copy.getTargetTransaction().setAmount(value(entry.getTargetTransaction().getAmount(), weight));
    return copy;
}
Also used : AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry)

Example 3 with AccountTransferEntry

use of name.abuchen.portfolio.model.AccountTransferEntry 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));
    }
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 4 with AccountTransferEntry

use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.

the class ClientPerformanceSnapshotTest method testCurrencyGainsWithTransferalInOtherCurrencies.

@Test
public void testCurrencyGainsWithTransferalInOtherCurrencies() {
    Client client = new Client();
    Account usd = // 
    new AccountBuilder("USD").deposit_("2015-01-01", // 
    1000_00).addTo(client);
    Account cad = // 
    new AccountBuilder("CAD").deposit_("2015-01-01", // 
    1000_00).addTo(client);
    // insert account transfer
    AccountTransferEntry entry = new AccountTransferEntry(usd, cad);
    entry.setDate(LocalDateTime.parse("2015-01-10T00:00"));
    AccountTransaction source = entry.getSourceTransaction();
    AccountTransaction target = entry.getTargetTransaction();
    source.setMonetaryAmount(Money.of("USD", 500_00));
    target.setMonetaryAmount(Money.of("CAD", 1000_00));
    source.addUnit(new Unit(Unit.Type.GROSS_VALUE, source.getMonetaryAmount(), target.getMonetaryAmount(), BigDecimal.valueOf(.5)));
    entry.insert();
    // check currency gain calculation of client performance snapshot
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new // 
    ClientPerformanceSnapshot(// 
    client, // 
    converter, LocalDate.parse("2015-01-01"), LocalDate.parse("2015-01-15"));
    MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
    currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
    currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
    currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
    currencyGains.add(snapshot.getValue(CategoryType.FEES));
    currencyGains.add(snapshot.getValue(CategoryType.TAXES));
    currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
    currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
    assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
Also used : Account(name.abuchen.portfolio.model.Account) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountBuilder(name.abuchen.portfolio.AccountBuilder) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 5 with AccountTransferEntry

use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.

the class PortfolioClientFilterTest method testCrossAccountTransfersAreKept.

@Test
public void testCrossAccountTransfersAreKept() {
    Account accountA = client.getAccounts().get(0);
    Account accountB = client.getAccounts().get(1);
    AccountTransferEntry entry = new AccountTransferEntry(accountA, accountB);
    entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
    entry.setAmount(Values.Amount.factorize(10));
    entry.setCurrencyCode(accountA.getCurrencyCode());
    entry.insert();
    Client result = new PortfolioClientFilter(Collections.emptyList(), Arrays.asList(accountA, accountB)).filter(client);
    assertThat(result.getPortfolios(), empty());
    assertThat(result.getAccounts().size(), is(2));
    Account account = result.getAccounts().get(0);
    // check that the 4 transactions are transformed:
    // - buy -> removal
    // - deposit
    // - dividend -> deposit
    // - transfer must exist
    assertThat(account.getTransactions().size(), is(4));
    assertThat(// 
    account.getTransactions().stream().filter(// 
    t -> t.getType() == AccountTransaction.Type.REMOVAL).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
    assertThat(// 
    account.getTransactions().stream().filter(// 
    t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-01-01T00:00"))).findAny().isPresent(), is(true));
    assertThat(// 
    account.getTransactions().stream().filter(// 
    t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-03-01T00:00"))).findAny().isPresent(), is(true));
    assertThat(// 
    account.getTransactions().stream().filter(// 
    t -> t.getType() == AccountTransaction.Type.TRANSFER_OUT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Arrays(java.util.Arrays) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) AccountSnapshot(name.abuchen.portfolio.snapshot.AccountSnapshot) LocalDateTime(java.time.LocalDateTime) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Assert.assertThat(org.junit.Assert.assertThat) AccountBuilder(name.abuchen.portfolio.AccountBuilder) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Before(org.junit.Before) Portfolio(name.abuchen.portfolio.model.Portfolio) Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) LocalDate(java.time.LocalDate) Collections(java.util.Collections) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Account(name.abuchen.portfolio.model.Account) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Aggregations

AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)10 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)9 Account (name.abuchen.portfolio.model.Account)5 Client (name.abuchen.portfolio.model.Client)5 LocalDateTime (java.time.LocalDateTime)4 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)4 PortfolioTransferEntry (name.abuchen.portfolio.model.PortfolioTransferEntry)4 Security (name.abuchen.portfolio.model.Security)4 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)4 Money (name.abuchen.portfolio.money.Money)4 Test (org.junit.Test)4 LocalDate (java.time.LocalDate)3 AccountBuilder (name.abuchen.portfolio.AccountBuilder)3 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)3 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)3 Portfolio (name.abuchen.portfolio.model.Portfolio)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2