use of name.abuchen.portfolio.SecurityBuilder 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.SecurityBuilder 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.SecurityBuilder 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.SecurityBuilder in project portfolio by buchen.
the class ClientSecurityFilterTest method setupClient.
@Before
public void setupClient() {
client = new Client();
securityUSD = //
new SecurityBuilder().addPrice("2016-06-01", //
Values.Quote.factorize(100)).addTo(client);
securityEUR = //
new SecurityBuilder(CurrencyUnit.USD).addPrice("2016-06-01", //
Values.Quote.factorize(100)).addTo(client);
accountEUR = //
new AccountBuilder(CurrencyUnit.EUR).dividend("2017-01-01", Values.Amount.factorize(20), //
securityEUR).addTo(client);
accountUSD = //
new AccountBuilder(CurrencyUnit.USD).dividend("2017-01-01", Values.Amount.factorize(20), //
securityUSD).addTo(client);
//
new PortfolioBuilder(accountEUR).inbound_delivery(securityEUR, "2016-06-01", Values.Share.factorize(20), //
Values.Amount.factorize(2000)).inbound_delivery(securityUSD, "2016-06-01", Values.Share.factorize(20), //
Values.Amount.factorize(2000)).addTo(client);
}
use of name.abuchen.portfolio.SecurityBuilder in project portfolio by buchen.
the class CostCalculationTest method testFifoBuySellTransactions2.
@Test
public void testFifoBuySellTransactions2() {
Client client = new Client();
Security security = //
new SecurityBuilder().addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 109 * Values.Share.factor(), //
Values.Amount.factorize(3149.20)).buy(security, "2010-02-01", 52 * Values.Share.factor(), //
Values.Amount.factorize(1684.92)).sell(security, "2010-03-01", 15 * Values.Share.factor(), //
Values.Amount.factorize(531.50)).addTo(client);
CostCalculation cost = new CostCalculation();
cost.setTermCurrency(CurrencyUnit.EUR);
cost.visitAll(new TestCurrencyConverter(), portfolio.getTransactions());
// expected:
// 3149,20 + 1684,92 - round(3149,20 * 15/109) = 4400,743853211009174
assertThat(cost.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4400.74))));
// expected moving average is identical because it is only one buy
// transaction
// (3149,20 + 1684.92) * 146/161 = 4383,736149068322981
assertThat(cost.getMovingAverageCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4383.74))));
}
Aggregations