use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class TransactionComparatorTest method testBuyIsPreferredOverSell2.
@Test
public void testBuyIsPreferredOverSell2() {
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 100, //
100).sell(security, "2010-01-01", 100, //
100).addTo(client);
List<PortfolioTransaction> list = portfolio.getTransactions();
Collections.sort(list, new TransactionComparator());
assertThat(list.get(0).getType(), is(Type.BUY));
assertThat(list.get(1).getType(), is(Type.SELL));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class TransactionComparatorTest method testBuyIsPreferredOverSell.
@Test
public void testBuyIsPreferredOverSell() {
Portfolio portfolio = //
new PortfolioBuilder().sell(security, "2010-01-01", 100, //
100).buy(security, "2010-01-01", 100, //
100).addTo(client);
List<PortfolioTransaction> list = portfolio.getTransactions();
Collections.sort(list, new TransactionComparator());
assertThat(list.get(0).getType(), is(Type.BUY));
assertThat(list.get(1).getType(), is(Type.SELL));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCapitalGainsWithBuyDuringReportPeriod.
@Test
public void testCapitalGainsWithBuyDuringReportPeriod() {
Client client = new Client();
Security security = new Security();
security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
client.addSecurity(security);
Portfolio portfolio = new Portfolio();
portfolio.setReferenceAccount(new Account());
portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1_00, security, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2011, Month.JANUARY, 15, 0, 0), CurrencyUnit.EUR, 99_00, security, Values.Share.factorize(1), PortfolioTransaction.Type.DELIVERY_INBOUND, 0, 0));
client.addPortfolio(portfolio);
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, 100_00 + (110_00 - 99_00))));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1210_00)));
assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class GroupByTaxonomyTest method testSecuritiesWithPartialAssignment.
@SuppressWarnings("null")
@Test
public void testSecuritiesWithPartialAssignment() {
Client client = new Client();
Taxonomy taxonomy = //
new TaxonomyBuilder().addClassification(//
"debt").addTo(client);
Security a = //
new SecurityBuilder().addPrice("2010-01-01", //
Values.Quote.factorize(10)).assign(taxonomy, "debt", //
Classification.ONE_HUNDRED_PERCENT / 2).addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), //
10000).addTo(client);
LocalDate date = LocalDate.parse("2010-01-01");
PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
assertNotNull(snapshot);
GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
assertThat(grouping.asList().size(), is(2));
AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
assertThat(debt.getPositions().size(), is(1));
AssetCategory unassigned = null;
for (AssetCategory category : grouping.asList()) if (category.getClassification().getId().equals(Classification.UNASSIGNED_ID))
unassigned = category;
assertThat(unassigned, notNullValue());
assertThat(unassigned.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
assertThat(unassigned.getPositions().size(), is(1));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class GroupByTaxonomyTest method testThatPartialAssignmentsAreSeparated.
@Test
public void testThatPartialAssignmentsAreSeparated() {
Client client = new Client();
Taxonomy taxonomy = //
new TaxonomyBuilder().addClassification(//
"debt").addClassification(//
"equity").addTo(client);
Security a = //
new SecurityBuilder().addPrice("2010-01-01", //
Values.Quote.factorize(10)).assign(taxonomy, "debt", //
Classification.ONE_HUNDRED_PERCENT / 2).assign(taxonomy, "equity", //
Classification.ONE_HUNDRED_PERCENT / 2).addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().inbound_delivery(a, "2010-01-01", Values.Share.factorize(10), //
10000).addTo(client);
LocalDate date = LocalDate.parse("2010-01-01");
PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
assertNotNull(snapshot);
GroupByTaxonomy grouping = snapshot.groupByTaxonomy(taxonomy);
AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
assertThat(debt.getPositions().size(), is(1));
AssetCategory equity = grouping.byClassification(taxonomy.getClassificationById("equity"));
assertThat(equity.getValuation(), is(Money.of(CurrencyUnit.EUR, 50_00)));
assertThat(equity.getPositions().size(), is(1));
}
Aggregations