use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecuritiesTable method addDeltaColumn.
private // NOSONAR
void addDeltaColumn() {
Column column;
// $NON-NLS-1$
column = new Column("5", Messages.ColumnChangeOnPrevious, SWT.RIGHT, 60);
column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabel);
column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, element -> {
SecurityPrice price = ((Security) element).getSecurityPrice(LocalDate.now());
if (!(price instanceof LatestSecurityPrice))
return null;
LatestSecurityPrice latest = (LatestSecurityPrice) price;
if (latest.getPreviousClose() == LatestSecurityPrice.NOT_AVAILABLE)
return null;
return (latest.getValue() - latest.getPreviousClose()) / (double) latest.getPreviousClose();
}));
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
// NOSONAR
SecurityPrice p1 = ((Security) o1).getSecurityPrice(LocalDate.now());
SecurityPrice p2 = ((Security) o2).getSecurityPrice(LocalDate.now());
if (!(p1 instanceof LatestSecurityPrice))
p1 = null;
if (!(p2 instanceof LatestSecurityPrice))
p2 = null;
if (p1 == null)
return p2 == null ? 0 : -1;
if (p2 == null)
return 1;
LatestSecurityPrice l1 = (LatestSecurityPrice) p1;
LatestSecurityPrice l2 = (LatestSecurityPrice) p2;
double v1 = ((double) (l1.getValue() - l1.getPreviousClose())) / l1.getPreviousClose() * 100;
double v2 = ((double) (l2.getValue() - l2.getPreviousClose())) / l2.getPreviousClose() * 100;
return Double.compare(v1, v2);
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecuritiesTable method addQuoteDeltaColumn.
private // NOSONAR
void addQuoteDeltaColumn() {
// create a modifiable copy as all menus share the same list of
// reporting periods
List<ReportingPeriod> options = new ArrayList<>(view.getPart().loadReportingPeriods());
BiFunction<Object, ReportingPeriod, Double> valueProvider = (element, option) -> {
Security security = (Security) element;
SecurityPrice latest = security.getSecurityPrice(option.getEndDate());
SecurityPrice previous = security.getSecurityPrice(option.getStartDate());
if (latest == null || previous == null)
return null;
if (previous.getValue() == 0)
return null;
if (previous.getDate().isAfter(option.getStartDate()))
return null;
return new Double((latest.getValue() - previous.getValue()) / (double) previous.getValue());
};
// $NON-NLS-1$
Column column = new Column("delta-w-period", Messages.ColumnQuoteChange, SWT.RIGHT, 80);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnQuoteChange_Option, options));
column.setDescription(Messages.ColumnQuoteChange_Description);
column.setLabelProvider(new QuoteReportingPeriodLabelProvider(valueProvider));
column.setVisible(false);
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
ReportingPeriod option = (ReportingPeriod) ColumnViewerSorter.SortingContext.getColumnOption();
Double v1 = valueProvider.apply(o1, option);
Double v2 = valueProvider.apply(o2, option);
if (v1 == null && v2 == null)
return 0;
else if (v1 == null)
return -1;
else if (v2 == null)
return 1;
return Double.compare(v1.doubleValue(), v2.doubleValue());
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecuritiesTable method addColumnDateOfLatestHistoricalPrice.
private // NOSONAR
void addColumnDateOfLatestHistoricalPrice() {
// $NON-NLS-1$
Column column = new Column("10", Messages.ColumnLatestHistoricalDate, SWT.LEFT, 80);
column.setMenuLabel(Messages.ColumnLatestHistoricalDate_MenuLabel);
column.setLabelProvider(new // NOSONAR
ColumnLabelProvider() {
@Override
public String getText(Object element) {
List<SecurityPrice> prices = ((Security) element).getPrices();
if (prices.isEmpty())
return null;
SecurityPrice latest = prices.get(prices.size() - 1);
return latest != null ? Values.Date.format(latest.getDate()) : null;
}
@Override
public Color getBackground(Object element) {
Security security = (Security) element;
List<SecurityPrice> prices = security.getPrices();
if (prices.isEmpty())
return null;
if (QuoteFeed.MANUAL.equals(security.getFeed()))
return null;
SecurityPrice latest = prices.get(prices.size() - 1);
if (!((Security) element).isRetired() && latest.getDate().isBefore(LocalDate.now().minusDays(7)))
return Colors.WARNING;
else
return null;
}
});
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
List<SecurityPrice> prices1 = ((Security) o1).getPrices();
SecurityPrice p1 = prices1.isEmpty() ? null : prices1.get(prices1.size() - 1);
List<SecurityPrice> prices2 = ((Security) o2).getPrices();
SecurityPrice p2 = prices2.isEmpty() ? null : prices2.get(prices2.size() - 1);
if (p1 == null)
return p2 == null ? 0 : -1;
if (p2 == null)
return 1;
return p1.getDate().compareTo(p2.getDate());
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityListView method createPricesTable.
// //////////////////////////////////////////////////////////////
// tab item: prices
// //////////////////////////////////////////////////////////////
protected Composite createPricesTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
prices = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
ColumnEditingSupport.prepare(prices);
ShowHideColumnHelper support = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
SecurityListView.class.getSimpleName() + "@prices", getPreferenceStore(), prices, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.Date.format(((SecurityPrice) element).getDate());
}
@Override
public Color getBackground(Object element) {
SecurityPrice current = (SecurityPrice) element;
List<?> all = (List<?>) prices.getInput();
int index = all.indexOf(current);
if (index == 0)
return null;
SecurityPrice previous = (SecurityPrice) all.get(index - 1);
int days = Dates.daysBetween(previous.getDate(), current.getDate());
return days > 3 ? Colors.WARNING : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(SecurityPrice.class, "date").attachTo(column, SWT.UP);
// $NON-NLS-1$
new DateEditingSupport(SecurityPrice.class, "date").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Security security = (Security) prices.getData(Security.class.toString());
SecurityPrice price = (SecurityPrice) element;
return Values.Quote.format(security.getCurrencyCode(), price.getValue(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(SecurityPrice.class, "value").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(SecurityPrice.class, "value", Values.Quote).addListener(this).attachTo(column);
support.addColumn(column);
support.createColumns();
prices.getTable().setHeaderVisible(true);
prices.getTable().setLinesVisible(true);
prices.setContentProvider(ArrayContentProvider.getInstance());
hookContextMenu(prices.getTable(), this::fillPricesContextMenu);
return container;
}
use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.
the class SecurityListView method onModified.
@Override
public void onModified(Object element, Object newValue, Object oldValue) {
// called from prices table
Security security = (Security) prices.getData(Security.class.toString());
// if the date changed, the prices must be reordered --> binary search
if (newValue instanceof LocalDate) {
SecurityPrice price = (SecurityPrice) element;
security.removePrice(price);
security.addPrice(price);
}
securities.refresh(security);
prices.refresh(element);
latest.setInput(security);
transactions.setInput(security.getTransactions(getClient()));
events.setInput(security.getEvents());
chart.updateChart(security);
markDirty();
}
Aggregations