use of name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot in project portfolio by buchen.
the class PerformanceView method createCalculationItem.
private void createCalculationItem(CTabFolder folder, String title) {
Composite container = new Composite(folder, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
container.setLayout(layout);
calculation = new TreeViewer(container, SWT.FULL_SELECTION);
calculation.addSelectionChangedListener(event -> {
Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (selection != null && selection instanceof ClientPerformanceSnapshot.Position && ((ClientPerformanceSnapshot.Position) selection).getSecurity() != null)
selectionService.setSelection(new SecuritySelection(getClient(), ((ClientPerformanceSnapshot.Position) selection).getSecurity()));
});
final Font boldFont = JFaceResources.getFontRegistry().getBold(container.getFont().getFontData()[0].getName());
TreeViewerColumn column = new TreeViewerColumn(calculation, SWT.NONE);
column.getColumn().setText(Messages.ColumnLable);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category) {
ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
return cat.getLabel();
} else if (element instanceof ClientPerformanceSnapshot.Position) {
ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
return pos.getLabel();
}
return null;
}
@Override
public Image getImage(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category) {
return Images.CATEGORY.image();
} else if (element instanceof ClientPerformanceSnapshot.Position) {
ClientPerformanceSnapshot.Position position = (ClientPerformanceSnapshot.Position) element;
if (position.getSecurity() != null) {
ClientPerformanceSnapshot snapshot = ((PerformanceContentProvider) calculation.getContentProvider()).getSnapshot();
boolean hasHoldings = snapshot.getEndClientSnapshot().getPositionsByVehicle().get(position.getSecurity()) != null;
return hasHoldings ? Images.SECURITY.image() : Images.SECURITY_RETIRED.image();
} else {
return null;
}
}
return null;
}
@Override
public Font getFont(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category)
return boldFont;
return null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(350));
column = new TreeViewerColumn(calculation, SWT.RIGHT);
column.getColumn().setText(Messages.ColumnValue);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category) {
ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
return Values.Money.format(cat.getValuation(), getClient().getBaseCurrency());
} else if (element instanceof ClientPerformanceSnapshot.Position) {
ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
return Values.Money.format(pos.getValuation(), getClient().getBaseCurrency());
}
return null;
}
@Override
public Font getFont(Object element) {
if (element instanceof ClientPerformanceSnapshot.Category)
return boldFont;
return null;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(80));
calculation.getTree().setHeaderVisible(true);
calculation.getTree().setLinesVisible(true);
calculation.setContentProvider(new PerformanceContentProvider());
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(title);
item.setControl(container);
hookContextMenu(calculation.getTree(), this::fillContextMenu);
}
use of name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot in project portfolio by buchen.
the class CurrencyTestCase method testClientPerformanceSnapshot.
@Test
public void testClientPerformanceSnapshot() {
ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-02"), LocalDate.parse("2015-01-14"));
ClientPerformanceSnapshot performance = new ClientPerformanceSnapshot(client, converter, period);
// calculating the totals is tested with #testClientSnapshot
assertThat(performance.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 4131_99)));
assertThat(performance.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 4187_94)));
assertThat(performance.getAbsoluteDelta(), is(performance.getValue(CategoryType.FINAL_VALUE).subtract(performance.getValue(CategoryType.TRANSFERS)).subtract(performance.getValue(CategoryType.INITIAL_VALUE))));
assertThat(performance.getValue(CategoryType.CAPITAL_GAINS).add(performance.getValue(CategoryType.CURRENCY_GAINS)), is(performance.getValue(CategoryType.FINAL_VALUE).subtract(performance.getValue(CategoryType.INITIAL_VALUE))));
// compare with result calculated by Excel's XIRR function
assertThat(performance.getPerformanceIRR(), IsCloseTo.closeTo(0.505460984, 0.00000001));
}
use of name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot in project portfolio by buchen.
the class IssueCurrencyGainsRoundingError method testPurchaseValueOfSecurityPositionWithTransfers.
@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
Client client = ClientFactory.load(IssueCurrencyGainsRoundingError.class.getResourceAsStream(// $NON-NLS-1$
"IssueCurrencyGainsRoundingError.xml"));
ReportingPeriod period = new // $NON-NLS-1$
ReportingPeriod.FromXtoY(// $NON-NLS-1$
LocalDate.parse("2015-01-09"), // $NON-NLS-1$
LocalDate.parse("2016-01-09"));
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, period);
MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
currencyGains.add(snapshot.getValue(CategoryType.FEES));
currencyGains.add(snapshot.getValue(CategoryType.TAXES));
currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
use of name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot in project portfolio by buchen.
the class PerformanceView method reportingPeriodUpdated.
@Override
public void reportingPeriodUpdated() {
ReportingPeriod period = getReportingPeriod();
CurrencyConverter converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
Client filteredClient = clientFilter.getSelectedFilter().filter(getClient());
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(filteredClient, converter, period);
try {
calculation.getTree().setRedraw(false);
calculation.setInput(snapshot);
calculation.expandAll();
calculation.getTree().getParent().layout();
} finally {
calculation.getTree().setRedraw(true);
}
snapshotStart.setInput(snapshot.getStartClientSnapshot(), clientFilter.getSelectedFilter());
snapshotEnd.setInput(snapshot.getEndClientSnapshot(), clientFilter.getSelectedFilter());
earnings.setInput(snapshot.getEarnings());
earningsByAccount.setInput(new GroupEarningsByAccount(snapshot).getItems());
taxes.setInput(snapshot.getTaxes());
fees.setInput(snapshot.getFees());
}
use of name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot in project portfolio by buchen.
the class PerformanceCalculationWidget method update.
@Override
public void update() {
title.setText(getWidget().getLabel());
PerformanceIndex index = getDashboardData().calculate(get(DataSeriesConfig.class).getDataSeries(), get(ReportingPeriodConfig.class).getReportingPeriod());
ClientPerformanceSnapshot snapshot = index.getClientPerformanceSnapshot();
int ii = 0;
for (ClientPerformanceSnapshot.Category category : snapshot.getCategories()) {
signs[ii].setText(category.getSign());
labels[ii].setText(category.getLabel());
values[ii].setText(Values.Money.format(category.getValuation(), getClient().getBaseCurrency()));
if (++ii >= labels.length)
break;
}
container.layout();
}
Aggregations