use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClassificationIndexTest method testThatTaxesAreNotIncludedInTTWRORCalculation.
@Test
public void testThatTaxesAreNotIncludedInTTWRORCalculation() {
Client client = new Client();
Security security = //
new SecurityBuilder().addPrice("2015-12-31", //
Values.Quote.factorize(100)).addPrice("2016-12-31", //
Values.Quote.factorize(110)).addTo(client);
Account account = //
new AccountBuilder().deposit_("2014-01-01", Values.Amount.factorize(1000)).addTo(client);
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DIVIDENDS);
t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
t.setSecurity(security);
t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
t.setShares(Values.Share.factorize(10));
account.addTransaction(t);
Portfolio portfolio = //
new PortfolioBuilder(account).addTo(client);
BuySellEntry buy = new BuySellEntry(portfolio, account);
buy.setType(PortfolioTransaction.Type.BUY);
buy.setDate(LocalDateTime.parse("2015-12-31T00:00"));
buy.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1000)));
buy.setShares(Values.Share.factorize(10));
buy.setSecurity(security);
buy.insert();
BuySellEntry sell = new BuySellEntry(portfolio, account);
sell.setType(PortfolioTransaction.Type.SELL);
sell.setDate(LocalDateTime.parse("2016-12-31T00:00"));
sell.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1070)));
sell.setShares(Values.Share.factorize(10));
sell.setSecurity(security);
sell.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(30))));
sell.insert();
Classification classification = new Classification(null, null);
classification.addAssignment(new Assignment(security));
List<Exception> warnings = new ArrayList<Exception>();
PerformanceIndex index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
assertThat(warnings.isEmpty(), is(true));
// dividend payment 10% * quote change 10%
assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.1 * 1.1) - 1, 0.000000001d));
// add taxes to dividend payment
t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
// dividend payment 15% * quote change 10%
assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.15 * 1.1) - 1, 0.000000001d));
}
use of name.abuchen.portfolio.TestCurrencyConverter 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.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testExcelSampleAggregatedWeekly.
@Test
public void testExcelSampleAggregatedWeekly() {
// first day of week is locale dependent
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.GERMAN);
try {
Client client = createClient();
ReportingPeriod.FromXtoY reportInterval = new //
ReportingPeriod.FromXtoY(LocalDate.of(2011, Month.DECEMBER, 31), LocalDate.of(2012, Month.JANUARY, 8));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());
index = Aggregation.aggregate(index, Aggregation.Period.WEEKLY);
assertNotNull(index);
double[] delta = index.getDeltaPercentage();
assertThat(delta.length, is(2));
assertThat(delta[0], IsCloseTo.closeTo(0.023d, PRECISION));
assertThat(delta[1], IsCloseTo.closeTo(-0.077402422d, PRECISION));
double[] accumulated = index.getAccumulatedPercentage();
assertThat(accumulated[0], IsCloseTo.closeTo(0.023d, PRECISION));
assertThat(accumulated[1], IsCloseTo.closeTo(-0.056182678d, PRECISION));
} finally {
Locale.setDefault(locale);
}
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testThatNoValuationResultsInZeroPerformance.
@Test
public void testThatNoValuationResultsInZeroPerformance() {
Client client = new Client();
ReportingPeriod.FromXtoY period = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 9));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, new ArrayList<Exception>());
double[] accumulated = index.getAccumulatedPercentage();
for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(0d, PRECISION));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClientIndexTest method testThatDepositsOnTheLastDayArePerformanceNeutral.
@Test
public void testThatDepositsOnTheLastDayArePerformanceNeutral() {
Client client = new Client();
//
new AccountBuilder().deposit_("2012-01-01", //
10000).interest("2012-01-02", //
1000).deposit_("2012-01-10", //
10000).addTo(client);
ReportingPeriod.FromXtoY reportInterval = new //
ReportingPeriod.FromXtoY(//
LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 10));
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex index = PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());
double[] accumulated = index.getAccumulatedPercentage();
assertThat(accumulated[accumulated.length - 2], IsCloseTo.closeTo(0.1d, PRECISION));
assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(0.1d, PRECISION));
}
Aggregations