Search in sources :

Example 1 with ClientPerformanceSnapshot

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);
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) CTabItem(org.eclipse.swt.custom.CTabItem) Font(org.eclipse.swt.graphics.Font) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider)

Example 2 with ClientPerformanceSnapshot

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));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) Test(org.junit.Test)

Example 3 with ClientPerformanceSnapshot

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()));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) Test(org.junit.Test)

Example 4 with ClientPerformanceSnapshot

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());
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) GroupEarningsByAccount(name.abuchen.portfolio.snapshot.GroupEarningsByAccount) Client(name.abuchen.portfolio.model.Client) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot)

Example 5 with ClientPerformanceSnapshot

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();
}
Also used : PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot)

Aggregations

ClientPerformanceSnapshot (name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot)5 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)3 Client (name.abuchen.portfolio.model.Client)2 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)2 Test (org.junit.Test)2 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)1 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)1 MutableMoney (name.abuchen.portfolio.money.MutableMoney)1 GroupEarningsByAccount (name.abuchen.portfolio.snapshot.GroupEarningsByAccount)1 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)1 SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Font (org.eclipse.swt.graphics.Font)1 Image (org.eclipse.swt.graphics.Image)1