use of name.abuchen.portfolio.SecurityBuilder in project portfolio by buchen.
the class CostCalculationTest method testWhenSharesHeldGoToZero.
@Test
public void testWhenSharesHeldGoToZero() {
Client client = new Client();
Security security = //
new SecurityBuilder().addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 100 * Values.Share.factor(), //
314920).sell(security, "2010-02-01", 100 * Values.Share.factor(), //
53150).buy(security, "2010-03-01", 50 * Values.Share.factor(), //
168492).sell(security, "2010-04-01", 50 * Values.Share.factor(), //
53150).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)));
}
use of name.abuchen.portfolio.SecurityBuilder in project portfolio by buchen.
the class ClientIndexTest method testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex.
@Test
public void testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex() {
LocalDate startDate = LocalDate.of(2012, 1, 1);
// a weekend
LocalDate endDate = LocalDate.of(2012, 4, 29);
long startPrice = Values.Quote.factorize(100);
Client client = new Client();
Security security = //
new SecurityBuilder().generatePrices(startPrice, startDate, //
endDate).addTo(client);
PortfolioBuilder portfolio = new PortfolioBuilder(new Account());
// add some buy transactions
LocalDate date = startDate;
while (date.isBefore(endDate)) {
// performance is only identical if the capital invested
// additionally has the identical performance on its first day -->
// use the closing quote of the previous day
long p = security.getSecurityPrice(date.minusDays(1)).getValue();
portfolio.inbound_delivery(security, date.atStartOfDay(), Values.Share.factorize(100), p);
date = date.plusDays(20);
}
portfolio.addTo(client);
ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
assertTrue(warnings.isEmpty());
double[] accumulated = index.getAccumulatedPercentage();
long lastPrice = security.getSecurityPrice(endDate).getValue();
assertThat((double) (lastPrice - startPrice) / (double) startPrice, IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));
PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
}
use of name.abuchen.portfolio.SecurityBuilder 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))));
}
use of name.abuchen.portfolio.SecurityBuilder 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.SecurityBuilder 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