use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCapitalGains.
@Test
public void testCapitalGains() {
Client client = new Client();
Security security = new Security();
security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
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);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1100_00)));
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 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.money.CurrencyConverter 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()));
}
use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class SecuritiesPerformanceView method reportingPeriodUpdated.
@Override
public void reportingPeriodUpdated() {
ReportingPeriod period = dropDown.getPeriods().getFirst();
CurrencyConverter converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
Client filteredClient = clientFilter.filter(getClient());
records.setInput(SecurityPerformanceSnapshot.create(filteredClient, converter, period).getRecords());
records.refresh();
}
use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class StatementOfAssetsView method notifyModelUpdated.
@Override
public void notifyModelUpdated() {
CurrencyConverter converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
Client filteredClient = clientFilter.getSelectedFilter().filter(getClient());
ClientSnapshot snapshot = ClientSnapshot.create(filteredClient, converter, snapshotDate);
assetViewer.setInput(snapshot, clientFilter.getSelectedFilter());
updateTitle(getDefaultTitle());
}
Aggregations