use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class GroupByTaxonomyTest method testSecuritiesWithoutAssignment.
@Test
public void testSecuritiesWithoutAssignment() {
Client client = new Client();
Taxonomy taxonomy = //
new TaxonomyBuilder().addClassification(//
"debt").addTo(client);
Security a = //
new SecurityBuilder().addPrice("2010-01-01", //
Values.Quote.factorize(10)).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, nullValue());
List<AssetCategory> categories = grouping.asList();
assertThat(categories.size(), is(1));
AssetCategory unassigned = categories.get(0);
assertThat(unassigned.getValuation(), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(unassigned.getPositions().size(), is(1));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class GroupByTaxonomyTest method testThatPartialAssignmentsInSubClassificationsAreMerged.
@Test
public void testThatPartialAssignmentsInSubClassificationsAreMerged() {
Client client = new Client();
Taxonomy taxonomy = //
new TaxonomyBuilder().addClassification(//
"debt").addClassification("debt", //
"cat1").addClassification("debt", //
"cat2").addTo(client);
Security a = //
new SecurityBuilder().addPrice("2010-01-01", //
Values.Quote.factorize(10)).assign(taxonomy, "cat1", //
Classification.ONE_HUNDRED_PERCENT / 2).assign(taxonomy, "cat2", //
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(1));
AssetCategory debt = grouping.byClassification(taxonomy.getClassificationById("debt"));
assertThat(debt.getPositions().size(), is(1));
assertThat(debt.getValuation(), is(Money.of(CurrencyUnit.EUR, 100_00)));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class PortfolioSnapshotTest method testBuyAndSellLeavesNoEntryInSnapshot.
@Test
public void testBuyAndSellLeavesNoEntryInSnapshot() {
Client client = new Client();
Security a = //
new SecurityBuilder().addPrice("2010-01-01", //
1000).addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().buy(a, "2010-01-01", 1000000, //
10000).sell(a, "2010-01-02", 700000, //
12000).sell(a, "2010-01-03", 300000, //
12000).addTo(client);
LocalDate date = LocalDate.parse("2010-01-31");
PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
assertTrue(snapshot.getPositions().isEmpty());
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class SecurityIndexTest method testWhenQuotesAreOnlyAvailableUntilTheMiddleOfTheReportInterval.
@Test
public void testWhenQuotesAreOnlyAvailableUntilTheMiddleOfTheReportInterval() {
LocalDate startDate = LocalDate.of(2012, 12, 31);
LocalDate middleDate = LocalDate.of(2013, 2, 18);
LocalDate endDate = LocalDate.of(2013, 3, 31);
// create model
Client client = new Client();
//
new AccountBuilder().deposit_(startDate.atStartOfDay(), //
100 * Values.Amount.factor()).interest(startDate.atStartOfDay().plusDays(10), //
10 * Values.Amount.factor()).addTo(client);
int startPrice = 50 * Values.Amount.factor();
Security security = //
new SecurityBuilder().generatePrices(startPrice, startDate, //
middleDate).addTo(client);
// calculate performance indices
List<Exception> warnings = new ArrayList<Exception>();
ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate, endDate);
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, reportInterval, warnings);
PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security);
// asserts
assertTrue(warnings.isEmpty());
LocalDate[] clientDates = clientIndex.getDates();
LocalDate[] securityDates = securityIndex.getDates();
assertThat(securityDates[0], is(startDate));
assertThat(securityDates[securityDates.length - 1], is(middleDate));
assertThat(clientDates[0], is(securityDates[0]));
double[] securityAccumulated = securityIndex.getAccumulatedPercentage();
int index = Dates.daysBetween(startDate, middleDate);
assertThat(clientDates[index], is(middleDate));
assertThat(securityAccumulated[0], IsCloseTo.closeTo(0d, 0.000001d));
long middlePrice = security.getSecurityPrice(middleDate).getValue();
double performance = (double) (middlePrice - startPrice) / (double) startPrice;
assertThat(securityAccumulated[securityAccumulated.length - 1], IsCloseTo.closeTo(performance, 0.000001d));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class SecurityIndexTest method testIndexWhenNoQuotesExist.
@Test
public void testIndexWhenNoQuotesExist() {
LocalDate startDate = LocalDate.of(2012, 12, 31);
LocalDate endDate = LocalDate.of(2013, 3, 31);
// create model
Client client = new Client();
//
new AccountBuilder().deposit_(startDate.atStartOfDay(), //
100 * Values.Amount.factor()).addTo(client);
Security security = new Security();
client.addSecurity(security);
// calculate performance indices
List<Exception> warnings = new ArrayList<Exception>();
ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate, endDate);
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, reportInterval, warnings);
PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security);
// asserts
assertTrue(warnings.isEmpty());
assertThat(securityIndex.getDates().length, is(1));
assertThat(securityIndex.getDates()[0], is(clientIndex.getFirstDataPoint().get()));
}
Aggregations