Search in sources :

Example 41 with Account

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

the class PortfolioClientFilterTest method testThatDividendTransactionAreIncluded.

@Test
public void testThatDividendTransactionAreIncluded() {
    Portfolio portfolio = client.getPortfolios().get(0);
    Client result = new PortfolioClientFilter(portfolio).filter(client);
    assertThat(result.getPortfolios().size(), is(1));
    assertThat(result.getAccounts().size(), is(1));
    Account account = result.getAccounts().get(0);
    assertThat(account.getTransactions().size(), is(2));
    assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DIVIDENDS).findAny().isPresent(), is(true));
    assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.REMOVAL).findAny().isPresent(), is(true));
    assertThat(AccountSnapshot.create(account, new TestCurrencyConverter(), LocalDate.parse("2016-09-03")).getFunds(), is(Money.of(CurrencyUnit.EUR, 0)));
}
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) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 42 with Account

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

the class PortfolioClientFilterTest method testThatFullReferenceAccountIsIncluded.

@Test
public void testThatFullReferenceAccountIsIncluded() {
    Portfolio portfolio = client.getPortfolios().get(0);
    Client result = new PortfolioClientFilter(portfolio, portfolio.getReferenceAccount()).filter(client);
    assertThat(result.getPortfolios().size(), is(1));
    assertThat(result.getAccounts().size(), is(1));
    Account account = result.getAccounts().get(0);
    // 3 transactions: buy, dividend, and deposit
    assertThat(account.getTransactions().size(), is(3));
    assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.BUY).findAny().isPresent(), is(true));
    assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DIVIDENDS).findAny().isPresent(), is(true));
    assertThat(account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DEPOSIT).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) Portfolio(name.abuchen.portfolio.model.Portfolio) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 43 with Account

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

the class PortfolioClientFilterTest method testCrossAccountTransfersAreConvertedIfAccountIsNotIncluded.

@Test
public void testCrossAccountTransfersAreConvertedIfAccountIsNotIncluded() {
    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)).filter(client);
    assertThat(result.getPortfolios(), empty());
    assertThat(result.getAccounts().size(), is(1));
    Account account = result.getAccounts().get(0);
    // check that the 4 transactions are transformed:
    // - buy -> removal
    // - deposit
    // - dividend -> deposit
    // - transfer -> removal
    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.REMOVAL).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
    // check other account
    result = new PortfolioClientFilter(Collections.emptyList(), Arrays.asList(accountB)).filter(client);
    assertThat(// 
    result.getAccounts().get(0).getTransactions().stream().filter(// 
    t -> t.getType() == AccountTransaction.Type.DEPOSIT).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)

Example 44 with Account

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

the class PortfolioClientFilterTest method setupClient.

/**
 * Creates three portfolios (A-C) with a reference account each.
 */
@Before
public void setupClient() {
    client = new Client();
    Security security = new SecurityBuilder().addTo(client);
    // 2016-01-01 deposit
    // 2016-02-01 buy
    // 2016-03-01 dividend
    Arrays.asList("A", "B", "C").forEach(index -> {
        Account a = // 
        new AccountBuilder().deposit_("2016-01-01", Values.Amount.factorize(100)).dividend("2016-03-01", Values.Amount.factorize(10), // 
        security).addTo(client);
        a.setName(index);
        Portfolio p = // 
        new PortfolioBuilder(a).buy(security, "2016-02-01", Values.Share.factorize(1), Values.Amount.factorize(100)).addTo(client);
        p.setName(index);
    });
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountBuilder(name.abuchen.portfolio.AccountBuilder) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Before(org.junit.Before)

Example 45 with Account

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

the class ClientIndexTest method testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex.

@Test
public void testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex() {
    LocalDate startDate = LocalDate.of(2012, 1, 1);
    // a weekend
    LocalDate endDate = LocalDate.of(2012, 4, 29);
    long startPrice = Values.Quote.factorize(100);
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().generatePrices(startPrice, startDate, // 
    endDate).addTo(client);
    PortfolioBuilder portfolio = new PortfolioBuilder(new Account());
    // add some buy transactions
    LocalDate date = startDate;
    while (date.isBefore(endDate)) {
        // performance is only identical if the capital invested
        // additionally has the identical performance on its first day -->
        // use the closing quote of the previous day
        long p = security.getSecurityPrice(date.minusDays(1)).getValue();
        portfolio.inbound_delivery(security, date.atStartOfDay(), Values.Share.factorize(100), p);
        date = date.plusDays(20);
    }
    portfolio.addTo(client);
    ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
    assertTrue(warnings.isEmpty());
    double[] accumulated = index.getAccumulatedPercentage();
    long lastPrice = security.getSecurityPrice(endDate).getValue();
    assertThat((double) (lastPrice - startPrice) / (double) startPrice, IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));
    PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
    assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
}
Also used : Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Aggregations

Account (name.abuchen.portfolio.model.Account)75 Security (name.abuchen.portfolio.model.Security)39 Client (name.abuchen.portfolio.model.Client)38 Portfolio (name.abuchen.portfolio.model.Portfolio)37 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)35 Test (org.junit.Test)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)25 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)21 ArrayList (java.util.ArrayList)17 LocalDate (java.time.LocalDate)16 AccountBuilder (name.abuchen.portfolio.AccountBuilder)14 Unit (name.abuchen.portfolio.model.Transaction.Unit)14 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)13 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)12 Money (name.abuchen.portfolio.money.Money)12 Collections (java.util.Collections)11 List (java.util.List)11 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)11 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11