Search in sources :

Example 21 with AccountBuilder

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

the class ClientPerformanceSnapshotTest method testFeesRefund.

@Test
public void testFeesRefund() {
    Client client = new Client();
    // 
    new AccountBuilder().fees_refund("2011-01-01", // 
    Values.Amount.factorize(100)).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThat(snapshot.getFees().size(), is(1));
    assertThat(snapshot.getFees().get(0).getTransaction().getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100))));
    assertThatCalculationWorksOut(snapshot, converter);
}
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)

Example 22 with AccountBuilder

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

the class ClientPerformanceSnapshotTest method testInterestCharge.

@Test
public void testInterestCharge() {
    Client client = new Client();
    Account account = // 
    new AccountBuilder().interest_charge("2011-01-01", // 
    Values.Amount.factorize(100)).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().size(), is(1));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().get(0).getValuation(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThat(snapshot.getEarnings().size(), is(1));
    assertThat(snapshot.getEarnings().get(0).getTransaction().getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100))));
    GroupEarningsByAccount grouping = new GroupEarningsByAccount(snapshot);
    assertThat(grouping.getItems().size(), is(1));
    assertThat(grouping.getItems().get(0).getAccount(), is(account));
    assertThat(grouping.getItems().get(0).getSum(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThatCalculationWorksOut(snapshot, converter);
}
Also used : Account(name.abuchen.portfolio.model.Account) 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)

Example 23 with AccountBuilder

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

the class ClientPerformanceSnapshotTest method testCapitalGainsWithPartialSellDuringReportPeriod.

@Test
public void testCapitalGainsWithPartialSellDuringReportPeriod() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(100)).addPrice("2011-06-01", // 
    Values.Quote.factorize(110)).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2010-01-01", // 
    1_00).withdraw("2011-01-15", // 
    99_00).addTo(client);
    // 
    new PortfolioBuilder(account).buy(security, "2010-01-01", Values.Share.factorize(10), // 
    1_00).sell(security, "2011-01-15", Values.Share.factorize(1), // 
    99_00).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 10_00 * 9 + (99_00 - 100_00))));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 110_00 * 9)));
    assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Also used : Account(name.abuchen.portfolio.model.Account) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) 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) 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