Search in sources :

Example 11 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class StatementOfAssetsViewer method addDividendColumns.

private void addDividendColumns(List<ReportingPeriod> options) {
    ReportingPeriodLabelProvider labelProvider;
    // $NON-NLS-1$
    Column column = new Column("sumdiv", Messages.ColumnDividendSum, SWT.RIGHT, 80);
    Function<Stream<Object>, Object> collector = elements -> elements.map(e -> (Money) e).collect(MoneyCollectors.sum(client.getBaseCurrency()));
    labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getSumOfDividends, collector, false);
    // $NON-NLS-1$
    column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendSum + " {0}", options));
    column.setGroupLabel(Messages.GroupLabelDividends);
    column.setMenuLabel(Messages.ColumnDividendSum_MenuLabel);
    column.setLabelProvider(labelProvider);
    column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("d%", Messages.ColumnDividendTotalRateOfReturn, SWT.RIGHT, 80);
    labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTotalRateOfReturnDiv, null, false);
    // $NON-NLS-1$
    column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendTotalRateOfReturn + " {0}", options));
    column.setGroupLabel(Messages.GroupLabelDividends);
    column.setDescription(Messages.ColumnDividendTotalRateOfReturn_Description);
    column.setLabelProvider(labelProvider);
    column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("d%mvavg", Messages.ColumnDividendMovingAverageTotalRateOfReturn, SWT.RIGHT, 80);
    labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTotalRateOfReturnDivMovingAverage, null, false);
    // $NON-NLS-1$
    column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendMovingAverageTotalRateOfReturn + " {0}", options));
    column.setGroupLabel(Messages.GroupLabelDividends);
    column.setDescription(Messages.ColumnDividendMovingAverageTotalRateOfReturn_Description);
    column.setLabelProvider(labelProvider);
    column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
    column.setVisible(false);
    support.addColumn(column);
}
Also used : ReportingPeriodColumnOptions(name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions) Adaptable(name.abuchen.portfolio.model.Adaptable) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) DND(org.eclipse.swt.dnd.DND) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) Classification(name.abuchen.portfolio.model.Classification) AttributeComparator(name.abuchen.portfolio.ui.util.AttributeComparator) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) MoneyCollectors(name.abuchen.portfolio.money.MoneyCollectors) AbstractFinanceView(name.abuchen.portfolio.ui.AbstractFinanceView) Map(java.util.Map) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) UIConstants(name.abuchen.portfolio.ui.UIConstants) GroupByTaxonomy(name.abuchen.portfolio.snapshot.GroupByTaxonomy) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Collectors(java.util.stream.Collectors) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) Objects(java.util.Objects) OptionLabelProvider(name.abuchen.portfolio.ui.util.viewers.OptionLabelProvider) List(java.util.List) Stream(java.util.stream.Stream) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) PostConstruct(javax.annotation.PostConstruct) Attributable(name.abuchen.portfolio.model.Attributable) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) Annotated(name.abuchen.portfolio.model.Annotated) Messages(name.abuchen.portfolio.ui.Messages) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Font(org.eclipse.swt.graphics.Font) MarkDirtyListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.MarkDirtyListener) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) Shell(org.eclipse.swt.widgets.Shell) Viewer(org.eclipse.jface.viewers.Viewer) AssetCategory(name.abuchen.portfolio.snapshot.AssetCategory) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Preference(org.eclipse.e4.core.di.extensions.Preference) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Named(name.abuchen.portfolio.model.Named) ToolTip(org.eclipse.jface.window.ToolTip) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Menu(org.eclipse.swt.widgets.Menu) Comparator(java.util.Comparator) Control(org.eclipse.swt.widgets.Control) Money(name.abuchen.portfolio.money.Money) ReportingPeriodColumnOptions(name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) Stream(java.util.stream.Stream)

Example 12 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class ExchangeRateWidget method update.

@Override
void update() {
    this.title.setText(getWidget().getLabel());
    ReportingPeriod period = get(ReportingPeriodConfig.class).getReportingPeriod();
    ExchangeRateTimeSeries series = get(ExchangeRateSeriesConfig.class).getSeries();
    Optional<ExchangeRate> rate = series.lookupRate(period.getEndDate());
    this.indicator.setText(series.getLabel() + ' ' + (rate.isPresent() ? Values.ExchangeRate.format(rate.get().getValue()) : '-'));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries)

Example 13 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class ClientSecurityFilterTest method testThatAllSecuritiesHaveIdendicalPerformanceToClient.

@Test
public void testThatAllSecuritiesHaveIdendicalPerformanceToClient() {
    Client filtered = new ClientSecurityFilter(securityEUR, securityUSD).filter(client);
    assertThat(filtered.getAccounts(), hasSize(2));
    assertThat(filtered.getPortfolios(), hasSize(1));
    List<Exception> warnings = new ArrayList<>();
    TestCurrencyConverter converter = new TestCurrencyConverter();
    ReportingPeriod interval = new ReportingPeriod.FromXtoY(LocalDate.parse("2015-12-31"), LocalDate.parse("2017-01-31"));
    PerformanceIndex all = PerformanceIndex.forClient(client, converter, interval, warnings);
    assertThat(warnings, empty());
    PerformanceIndex filteredAll = PerformanceIndex.forClient(filtered, converter, interval, warnings);
    assertThat(warnings, empty());
    assertThat(all.getFinalAccumulatedPercentage(), is(filteredAll.getFinalAccumulatedPercentage()));
    assertThat(all.getDeltaPercentage(), is(filteredAll.getDeltaPercentage()));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 14 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod 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 15 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class VolatilityTestCase method testVolatilityOfSharesHeldIsIdenticalToExcel.

@Test
public void testVolatilityOfSharesHeldIsIdenticalToExcel() throws IOException {
    ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2014-07-31"));
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, report, warnings);
    assertThat(warnings, empty());
    // excel
    assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.141568791460, 0.1e-10));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Aggregations

ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)27 Test (org.junit.Test)14 Client (name.abuchen.portfolio.model.Client)13 ArrayList (java.util.ArrayList)11 Security (name.abuchen.portfolio.model.Security)11 IOException (java.io.IOException)8 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)8 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)8 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)8 SecurityPerformanceRecord (name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord)8 SecurityPerformanceSnapshot (name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot)8 Portfolio (name.abuchen.portfolio.model.Portfolio)5 Composite (org.eclipse.swt.widgets.Composite)5 LocalDate (java.time.LocalDate)4 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)4 ExchangeRate (name.abuchen.portfolio.money.ExchangeRate)4 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)4 List (java.util.List)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3