Search in sources :

Example 46 with TestCurrencyConverter

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

the class SecurityPositionTest method testThatOnlyMatchingTransfersAreRemoved_OutRemains.

@Test
public void testThatOnlyMatchingTransfersAreRemoved_OutRemains() {
    SecurityPrice price = new SecurityPrice(LocalDate.of(2012, Month.DECEMBER, 2), Values.Quote.factorize(20));
    List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
    tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 50000, null, 50 * Values.Share.factor(), Type.BUY, 0, 0));
    tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.FEBRUARY, 1, 0, 0), CurrencyUnit.EUR, 55000, null, 50 * Values.Share.factor(), Type.TRANSFER_OUT, 0, 0));
    tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.FEBRUARY, 1, 0, 0), CurrencyUnit.EUR, 55000, null, 50 * Values.Share.factor(), Type.TRANSFER_IN, 0, 0));
    tx.add(new PortfolioTransaction(LocalDateTime.of(2012, Month.FEBRUARY, 2, 0, 0), CurrencyUnit.EUR, 55000, null, 25 * Values.Share.factor(), Type.TRANSFER_OUT, 0, 0));
    SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), price, tx);
    assertThat(position.getShares(), is(25L * Values.Share.factor()));
    assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 250_00)));
    assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(position.getMovingAveragePurchaseValue(), is(Money.of(CurrencyUnit.EUR, 250_00)));
    assertThat(position.calculateValue(), is(Money.of(CurrencyUnit.EUR, 500_00)));
    assertThat(position.getProfitLoss(), is(Money.of(CurrencyUnit.EUR, 250_00)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 47 with TestCurrencyConverter

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

the class SecurityPositionTest method testFIFOPurchasePriceWithOnlySell.

@Test
public void testFIFOPurchasePriceWithOnlySell() {
    List<PortfolioTransaction> tx = new ArrayList<PortfolioTransaction>();
    tx.add(new PortfolioTransaction(LocalDateTime.now(), CurrencyUnit.EUR, 50000, null, 50 * Values.Share.factor(), Type.SELL, 0, 0));
    SecurityPosition position = new SecurityPosition(new Security(), new TestCurrencyConverter(), new SecurityPrice(), tx);
    assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.EUR, 0)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 48 with TestCurrencyConverter

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

the class ClientSecurityFilterTest method testThatAllSecuritiesHaveIdendicalPerformanceToClient.

@Test
public void testThatAllSecuritiesHaveIdendicalPerformanceToClient() {
    Client filtered = new ClientSecurityFilter(securityEUR, securityUSD).filter(client);
    assertThat(filtered.getAccounts(), hasSize(2));
    assertThat(filtered.getPortfolios(), hasSize(1));
    List<Exception> warnings = new ArrayList<>();
    TestCurrencyConverter converter = new TestCurrencyConverter();
    ReportingPeriod interval = new ReportingPeriod.FromXtoY(LocalDate.parse("2015-12-31"), LocalDate.parse("2017-01-31"));
    PerformanceIndex all = PerformanceIndex.forClient(client, converter, interval, warnings);
    assertThat(warnings, empty());
    PerformanceIndex filteredAll = PerformanceIndex.forClient(filtered, converter, interval, warnings);
    assertThat(warnings, empty());
    assertThat(all.getFinalAccumulatedPercentage(), is(filteredAll.getFinalAccumulatedPercentage()));
    assertThat(all.getDeltaPercentage(), is(filteredAll.getDeltaPercentage()));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 49 with TestCurrencyConverter

use of name.abuchen.portfolio.TestCurrencyConverter 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 50 with TestCurrencyConverter

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

the class CostCalculationTest method testThatRoundingDifferencesAreRemovedIfZeroSharesHeld.

@Test
public void testThatRoundingDifferencesAreRemovedIfZeroSharesHeld() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addTo(client);
    Portfolio portfolio = // 
    new PortfolioBuilder().buy(security, "2010-01-01", 10 * Values.Share.factor(), // 
    1).sell(security, "2010-02-01", 3 * Values.Share.factor(), // 
    1).sell(security, "2010-03-01", 3 * Values.Share.factor(), // 
    1).sell(security, "2010-03-01", 4 * Values.Share.factor(), // 
    1).addTo(client);
    CostCalculation cost = new CostCalculation();
    cost.setTermCurrency(CurrencyUnit.EUR);
    cost.visitAll(new TestCurrencyConverter(), portfolio.getTransactions());
    assertThat(cost.getFifoCost(), is(Money.of(CurrencyUnit.EUR, 0L)));
    assertThat(cost.getMovingAverageCost(), is(Money.of(CurrencyUnit.EUR, 0L)));
}
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)

Aggregations

TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)74 Test (org.junit.Test)72 Client (name.abuchen.portfolio.model.Client)55 Security (name.abuchen.portfolio.model.Security)46 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)38 ArrayList (java.util.ArrayList)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)26 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)23 Portfolio (name.abuchen.portfolio.model.Portfolio)21 AccountBuilder (name.abuchen.portfolio.AccountBuilder)19 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)19 LocalDate (java.time.LocalDate)18 Account (name.abuchen.portfolio.model.Account)18 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)15 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)13 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)10 Taxonomy (name.abuchen.portfolio.model.Taxonomy)8 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)8 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)8 IOException (java.io.IOException)7