use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClassificationIndexTest method createClient.
private Client createClient(int weight) {
Client client = new Client();
Taxonomy taxonomy = //
new TaxonomyBuilder().addClassification(//
"one").addTo(client);
Security security = //
new SecurityBuilder().addPrice("2011-12-31", //
100 * Values.Quote.factor()).addPrice("2012-01-03", //
106 * Values.Quote.factor()).addPrice("2012-01-08", //
112 * Values.Quote.factor()).assign(taxonomy, "one", //
weight).addTo(client);
Account account = //
new AccountBuilder().deposit_("2011-12-31", //
10000 * Values.Amount.factor()).interest("2012-01-01", //
230 * Values.Amount.factor()).deposit_("2012-01-02", //
200 * Values.Amount.factor()).interest("2012-01-02", //
200 * Values.Amount.factor()).withdraw("2012-01-03", //
400 * Values.Amount.factor()).fees____("2012-01-03", //
234 * Values.Amount.factor()).interest("2012-01-04", //
293 * Values.Amount.factor()).interest("2012-01-05", //
293 * Values.Amount.factor()).deposit_("2012-01-06", //
5400 * Values.Amount.factor()).interest("2012-01-06", //
195 * Values.Amount.factor()).withdraw("2012-01-07", //
3697 * Values.Amount.factor()).fees____("2012-01-07", //
882 * Values.Amount.factor()).fees____("2012-01-08", //
1003 * Values.Amount.factor()).dividend("2012-01-08", 100 * Values.Amount.factor(), //
security).assign(taxonomy, "one", //
weight).addTo(client);
//
new PortfolioBuilder(account).buy(security, "2012-01-01", 50 * Values.Share.factor(), //
50 * 101 * Values.Amount.factor()).inbound_delivery(security, "2012-01-01", 100 * Values.Share.factor(), //
100 * 100 * Values.Amount.factor()).sell(security, "2012-01-05", 50 * Values.Share.factor(), //
50 * 105 * Values.Amount.factor()).addTo(client);
return client;
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientIndexTest method testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency.
@Test
public void testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency() {
LocalDate startDate = LocalDate.of(2015, 1, 1);
LocalDate endDate = LocalDate.of(2015, 8, 1);
long startPrice = Values.Quote.factorize(100);
Client client = new Client();
Security security = //
new SecurityBuilder("USD").generatePrices(startPrice, startDate, //
endDate).addTo(client);
Account account = new AccountBuilder().addTo(client);
//
new PortfolioBuilder(account).inbound_delivery(security, LocalDateTime.of(2014, 01, 01, 0, 0), Values.Share.factorize(100), //
100).addTo(client);
ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter().with(CurrencyUnit.EUR);
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
assertTrue(warnings.isEmpty());
PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
assertTrue(warnings.isEmpty());
assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
PerformanceIndex investment = PerformanceIndex.forInvestment(client, converter, security, period, warnings);
assertTrue(warnings.isEmpty());
assertThat(investment.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testEarningsFromSecurity.
@Test
public void testEarningsFromSecurity() {
Client client = new Client();
Security security = new Security();
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));
client.addPortfolio(portfolio);
Account account = new Account();
account.addTransaction(new AccountTransaction(LocalDateTime.of(2011, Month.JANUARY, 31, 0, 0), CurrencyUnit.EUR, 50_00, security, AccountTransaction.Type.INTEREST));
client.addAccount(account);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 50_00)));
assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().size(), is(1));
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.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCapitalGainsWithPartialSellDuringReportPeriodWithFees.
@Test
public void testCapitalGainsWithPartialSellDuringReportPeriodWithFees() {
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, //
1).addTo(client);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 1000 * 9 + (9900 - 10000) + 1)));
assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, 1)));
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.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testDividendTransactionWithTaxes.
@Test
public void testDividendTransactionWithTaxes() {
Client client = new Client();
Security security = new SecurityBuilder().addTo(client);
Account account = new AccountBuilder().addTo(client);
AccountTransaction dividend = new AccountTransaction();
dividend.setDateTime(LocalDateTime.parse("2011-03-01T00:00"));
dividend.setType(AccountTransaction.Type.DIVIDENDS);
dividend.setSecurity(security);
dividend.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 100_00));
dividend.addUnit(new Transaction.Unit(Transaction.Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(dividend.getGrossValue(), is(Money.of(CurrencyUnit.EUR, 110_00)));
account.addTransaction(dividend);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 110_00)));
assertThat(snapshot.getValue(CategoryType.TAXES), is(Money.of(CurrencyUnit.EUR, 10_00)));
assertThat(snapshot.getEarnings().size(), is(1));
assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().get(0).getValuation(), is(Money.of(CurrencyUnit.EUR, 110_00)));
GroupEarningsByAccount.Item item = new GroupEarningsByAccount(snapshot).getItems().get(0);
assertThat(item.getSum(), is(Money.of(CurrencyUnit.EUR, 110_00)));
assertThatCalculationWorksOut(snapshot, converter);
}
Aggregations