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)));
}
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)));
}
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()));
}
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)));
}
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)));
}
Aggregations