use of name.abuchen.portfolio.money.CurrencyConverter 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.money.CurrencyConverter 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.money.CurrencyConverter 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));
}
use of name.abuchen.portfolio.money.CurrencyConverter 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.money.CurrencyConverter 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))));
}
Aggregations