Search in sources :

Example 16 with AccountBuilder

use of name.abuchen.portfolio.AccountBuilder 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 17 with AccountBuilder

use of name.abuchen.portfolio.AccountBuilder in project portfolio by buchen.

the class ClientIndexTest method createClient.

private Client createClient() {
    Client client = new Client();
    // 
    new AccountBuilder().deposit_("2011-12-31", // 
    10000 * Values.Amount.factor()).interest("2012-01-01", // 
    230 * Values.Amount.factor()).deposit_("2012-01-02", // 
    200 * Values.Amount.factor()).interest("2012-01-02", // 
    200 * Values.Amount.factor()).withdraw("2012-01-03", // 
    400 * Values.Amount.factor()).fees____("2012-01-03", // 
    23441).interest("2012-01-04", // 
    29399).interest("2012-01-05", // 
    29399).deposit_("2012-01-06", // 
    5400 * Values.Amount.factor()).interest("2012-01-06", // 
    19599).withdraw("2012-01-07", // 
    369704).fees____("2012-01-07", // 
    88252).fees____("2012-01-08", // 
    100385).addTo(client);
    return client;
}
Also used : AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client)

Example 18 with AccountBuilder

use of name.abuchen.portfolio.AccountBuilder in project portfolio by buchen.

the class ClientIndexTest method testThatInterstWithoutInvestmentDoesNotCorruptResultAndIsReported.

@Test
public void testThatInterstWithoutInvestmentDoesNotCorruptResultAndIsReported() {
    Client client = new Client();
    // 
    new AccountBuilder().interest(LocalDateTime.of(2012, 01, 02, 0, 0), // 
    100).addTo(client);
    ReportingPeriod.FromXtoY period = new // 
    ReportingPeriod.FromXtoY(// 
    LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 9));
    List<Exception> errors = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, errors);
    double[] accumulated = index.getAccumulatedPercentage();
    for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(0d, PRECISION));
    assertThat(errors.size(), is(1));
    assertThat(errors.get(0).getMessage(), startsWith(Messages.MsgDeltaWithoutAssets.substring(0, Messages.MsgDeltaWithoutAssets.indexOf('{'))));
}
Also used : ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 19 with AccountBuilder

use of name.abuchen.portfolio.AccountBuilder in project portfolio by buchen.

the class ClientIndexTest method createClient.

private Client createClient(double[] delta, long[] transferals) {
    Client client = new Client();
    AccountBuilder account = new AccountBuilder();
    LocalDateTime time = LocalDateTime.of(2012, Month.JANUARY, 1, 0, 0);
    long valuation = 0;
    double quote = 1;
    for (int ii = 0; ii < delta.length; ii++) {
        // the idea: inbound transferals are added at the beginning of the
        // day and hence contribute to the performance. Outbound transferals
        // are deducted at the end of the day.
        long inbound = transferals[ii] > 0 ? transferals[ii] : 0;
        long v = (long) Math.round((double) (valuation + inbound) * (delta[ii] + 1) / quote) - inbound;
        long d = v - valuation;
        if (transferals[ii] > 0)
            account.deposit_(time, transferals[ii]);
        else if (transferals[ii] < 0)
            account.withdraw(time, Math.abs(transferals[ii]));
        if (v > 0)
            account.interest(time, d);
        else if (v < 0)
            account.fees____(time, Math.abs(d));
        valuation = v + transferals[ii];
        quote = 1 + delta[ii];
        time = time.plusDays(1);
    }
    account.addTo(client);
    return client;
}
Also used : LocalDateTime(java.time.LocalDateTime) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client)

Example 20 with AccountBuilder

use of name.abuchen.portfolio.AccountBuilder in project portfolio by buchen.

the class ClientIndexTest method testChangesOnFirstDayOfInvestment.

@Test
public void testChangesOnFirstDayOfInvestment() {
    Client client = new Client();
    // 
    new AccountBuilder().deposit_("2012-01-01", // 
    10000).interest("2012-01-02", // 
    1000).addTo(client);
    ReportingPeriod.FromXtoY reportInterval = new // 
    ReportingPeriod.FromXtoY(// 
    LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 10));
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());
    double[] accumulated = index.getAccumulatedPercentage();
    assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(0.1d, PRECISION));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Aggregations

AccountBuilder (name.abuchen.portfolio.AccountBuilder)23 Client (name.abuchen.portfolio.model.Client)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)18 Test (org.junit.Test)18 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)15 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)13 Security (name.abuchen.portfolio.model.Security)12 Account (name.abuchen.portfolio.model.Account)10 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)9 ArrayList (java.util.ArrayList)7 LocalDate (java.time.LocalDate)6 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)3 Unit (name.abuchen.portfolio.model.Transaction.Unit)3 LocalDateTime (java.time.LocalDateTime)2 TaxonomyBuilder (name.abuchen.portfolio.TaxonomyBuilder)2 Portfolio (name.abuchen.portfolio.model.Portfolio)2 Taxonomy (name.abuchen.portfolio.model.Taxonomy)2 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)2 Before (org.junit.Before)2 Month (java.time.Month)1