Search in sources :

Example 11 with PortfolioBuilder

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

the class PortfolioSnapshotTest method testBuyAndSellLeavesNoEntryInSnapshot.

@Test
public void testBuyAndSellLeavesNoEntryInSnapshot() {
    Client client = new Client();
    Security a = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    1000).addTo(client);
    Portfolio portfolio = // 
    new PortfolioBuilder().buy(a, "2010-01-01", 1000000, // 
    10000).sell(a, "2010-01-02", 700000, // 
    12000).sell(a, "2010-01-03", 300000, // 
    12000).addTo(client);
    LocalDate date = LocalDate.parse("2010-01-31");
    PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
    assertTrue(snapshot.getPositions().isEmpty());
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 12 with PortfolioBuilder

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

the class ClientSecurityFilterTest method setupClient.

@Before
public void setupClient() {
    client = new Client();
    securityUSD = // 
    new SecurityBuilder().addPrice("2016-06-01", // 
    Values.Quote.factorize(100)).addTo(client);
    securityEUR = // 
    new SecurityBuilder(CurrencyUnit.USD).addPrice("2016-06-01", // 
    Values.Quote.factorize(100)).addTo(client);
    accountEUR = // 
    new AccountBuilder(CurrencyUnit.EUR).dividend("2017-01-01", Values.Amount.factorize(20), // 
    securityEUR).addTo(client);
    accountUSD = // 
    new AccountBuilder(CurrencyUnit.USD).dividend("2017-01-01", Values.Amount.factorize(20), // 
    securityUSD).addTo(client);
    // 
    new PortfolioBuilder(accountEUR).inbound_delivery(securityEUR, "2016-06-01", Values.Share.factorize(20), // 
    Values.Amount.factorize(2000)).inbound_delivery(securityUSD, "2016-06-01", Values.Share.factorize(20), // 
    Values.Amount.factorize(2000)).addTo(client);
}
Also used : AccountBuilder(name.abuchen.portfolio.AccountBuilder) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Before(org.junit.Before)

Example 13 with PortfolioBuilder

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

the class CostCalculationTest method testFifoBuySellTransactions2.

@Test
public void testFifoBuySellTransactions2() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addTo(client);
    Portfolio portfolio = // 
    new PortfolioBuilder().buy(security, "2010-01-01", 109 * Values.Share.factor(), // 
    Values.Amount.factorize(3149.20)).buy(security, "2010-02-01", 52 * Values.Share.factor(), // 
    Values.Amount.factorize(1684.92)).sell(security, "2010-03-01", 15 * Values.Share.factor(), // 
    Values.Amount.factorize(531.50)).addTo(client);
    CostCalculation cost = new CostCalculation();
    cost.setTermCurrency(CurrencyUnit.EUR);
    cost.visitAll(new TestCurrencyConverter(), portfolio.getTransactions());
    // expected:
    // 3149,20 + 1684,92 - round(3149,20 * 15/109) = 4400,743853211009174
    assertThat(cost.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4400.74))));
    // expected moving average is identical because it is only one buy
    // transaction
    // (3149,20 + 1684.92) * 146/161 = 4383,736149068322981
    assertThat(cost.getMovingAverageCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4383.74))));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 14 with PortfolioBuilder

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

the class TransactionComparatorTest method testThatDatePreceedsType.

@Test
public void testThatDatePreceedsType() {
    Portfolio portfolio = // 
    new PortfolioBuilder().sell(security, "2010-01-01", 100, // 
    100).buy(security, "2010-01-02", 100, // 
    100).addTo(client);
    List<PortfolioTransaction> list = portfolio.getTransactions();
    Collections.sort(list, new TransactionComparator());
    assertThat(list.get(0).getType(), is(Type.SELL));
    assertThat(list.get(1).getType(), is(Type.BUY));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Test(org.junit.Test)

Example 15 with PortfolioBuilder

use of name.abuchen.portfolio.PortfolioBuilder 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)

Aggregations

PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)25 Test (org.junit.Test)22 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)21 Client (name.abuchen.portfolio.model.Client)20 Security (name.abuchen.portfolio.model.Security)19 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)18 Portfolio (name.abuchen.portfolio.model.Portfolio)17 LocalDate (java.time.LocalDate)9 AccountBuilder (name.abuchen.portfolio.AccountBuilder)9 Account (name.abuchen.portfolio.model.Account)8 TaxonomyBuilder (name.abuchen.portfolio.TaxonomyBuilder)7 Taxonomy (name.abuchen.portfolio.model.Taxonomy)7 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)5 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)5 ArrayList (java.util.ArrayList)3 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)2 Unit (name.abuchen.portfolio.model.Transaction.Unit)2 Before (org.junit.Before)2 LocalDateTime (java.time.LocalDateTime)1 Month (java.time.Month)1