use of name.abuchen.portfolio.money.CurrencyConverter 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.money.CurrencyConverter in project portfolio by buchen.
the class SecuritiesChart method addMovingAveragePurchasePrice.
private void addMovingAveragePurchasePrice() {
// no purchase price
if (security.getCurrencyCode() == null)
return;
// create a list of dates that are relevant for floating avg purchase price
// changes (i.e. all purchase and sell events)
Client filteredClient = new ClientSecurityFilter(security).filter(client);
CurrencyConverter securityCurrency = converter.with(security.getCurrencyCode());
LocalDate today = LocalDate.now();
List<LocalDate> candidates = //
client.getPortfolios().stream().flatMap(//
p -> p.getTransactions().stream()).filter(t -> t.getSecurity().equals(security)).filter(t -> !(t.getType() == PortfolioTransaction.Type.TRANSFER_IN || t.getType() == PortfolioTransaction.Type.TRANSFER_OUT)).filter(t -> t.getDateTime().toLocalDate().isBefore(today)).map(t -> (chartPeriod == null || t.getDateTime().toLocalDate().isAfter(chartPeriod)) ? t.getDateTime().toLocalDate() : chartPeriod).distinct().sorted().collect(Collectors.toList());
// calculate floating avg purchase price for each event - separate lineSeries
// per holding period
List<Double> values = new ArrayList<>();
List<LocalDate> dates = new ArrayList<>();
int seriesCounter = 0;
for (LocalDate eventDate : candidates) {
Optional<Double> purchasePrice = getMovingAveragePurchasePrice(filteredClient, securityCurrency, eventDate);
if (purchasePrice.isPresent()) {
dates.add(eventDate);
values.add(purchasePrice.get());
} else {
if (!dates.isEmpty()) {
// add previous value if the data series ends here (no more
// future events)
dates.add(eventDate);
values.add(values.get(values.size() - 1));
createMovingAveragePurchaseLineSeries(values, dates, seriesCounter++);
values.clear();
dates.clear();
} else if (dates.isEmpty()) {
// if no holding period exists, then do not add the event at
// all
}
}
}
// add today if needed
getMovingAveragePurchasePrice(filteredClient, securityCurrency, today).ifPresent(price -> {
dates.add(today);
values.add(price);
});
if (!dates.isEmpty())
createMovingAveragePurchaseLineSeries(values, dates, seriesCounter);
}
use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.
the class SecuritiesChart method addFIFOPurchasePrice.
private void addFIFOPurchasePrice() {
// no purchase price
if (security.getCurrencyCode() == null)
return;
// create a list of dates that are relevant for FIFO purchase price
// changes (i.e. all purchase and sell events)
Client filteredClient = new ClientSecurityFilter(security).filter(client);
CurrencyConverter securityCurrency = converter.with(security.getCurrencyCode());
LocalDate today = LocalDate.now();
List<LocalDate> candidates = //
client.getPortfolios().stream().flatMap(//
p -> p.getTransactions().stream()).filter(t -> t.getSecurity().equals(security)).filter(t -> !(t.getType() == PortfolioTransaction.Type.TRANSFER_IN || t.getType() == PortfolioTransaction.Type.TRANSFER_OUT)).filter(t -> t.getDateTime().toLocalDate().isBefore(today)).map(t -> (chartPeriod == null || t.getDateTime().toLocalDate().isAfter(chartPeriod)) ? t.getDateTime().toLocalDate() : chartPeriod).distinct().sorted().collect(Collectors.toList());
// calculate FIFO purchase price for each event - separate lineSeries
// per holding period
List<Double> values = new ArrayList<>();
List<LocalDate> dates = new ArrayList<>();
int seriesCounter = 0;
for (LocalDate eventDate : candidates) {
Optional<Double> purchasePrice = getPurchasePrice(filteredClient, securityCurrency, eventDate);
if (purchasePrice.isPresent()) {
dates.add(eventDate);
values.add(purchasePrice.get());
} else {
if (!dates.isEmpty()) {
// add previous value if the data series ends here (no more
// future events)
dates.add(eventDate);
values.add(values.get(values.size() - 1));
createFIFOPurchaseLineSeries(values, dates, seriesCounter++);
values.clear();
dates.clear();
} else if (dates.isEmpty()) {
// if no holding period exists, then do not add the event at
// all
}
}
}
// add today if needed
getPurchasePrice(filteredClient, securityCurrency, today).ifPresent(price -> {
dates.add(today);
values.add(price);
});
if (!dates.isEmpty())
createFIFOPurchaseLineSeries(values, dates, seriesCounter);
}
use of name.abuchen.portfolio.money.CurrencyConverter 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.money.CurrencyConverter in project portfolio by buchen.
the class PortfolioListView method createTopTable.
// //////////////////////////////////////////////////////////////
// top table: accounts
// //////////////////////////////////////////////////////////////
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
portfolios = new TableViewer(container, SWT.FULL_SELECTION);
ColumnEditingSupport.prepare(portfolios);
portfolioColumns = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
PortfolioListView.class.getSimpleName() + "@top2", getPreferenceStore(), portfolios, layout);
// $NON-NLS-1$
Column column = new NameColumn("0", Messages.ColumnPortfolio, SWT.None, 100);
column.setLabelProvider(new NameColumnLabelProvider() {
@Override
public Color getForeground(Object e) {
boolean isRetired = ((Portfolio) e).isRetired();
return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
}
});
column.getEditingSupport().addListener(this);
portfolioColumns.addColumn(column);
column = new Column(Messages.ColumnReferenceAccount, SWT.None, 160);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Portfolio p = (Portfolio) e;
return p.getReferenceAccount() != null ? p.getReferenceAccount().getName() : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(Portfolio.class, "referenceAccount").attachTo(column);
// $NON-NLS-1$
new ListEditingSupport(Portfolio.class, "referenceAccount", getClient().getAccounts()).addListener(this).attachTo(column);
portfolioColumns.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(this);
portfolioColumns.addColumn(column);
portfolioColumns.createColumns();
portfolios.getTable().setHeaderVisible(true);
portfolios.getTable().setLinesVisible(true);
portfolios.setContentProvider(ArrayContentProvider.getInstance());
setInput();
portfolios.addSelectionChangedListener(event -> {
Portfolio portfolio = (Portfolio) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (portfolio != null) {
transactions.setInput(portfolio, portfolio.getTransactions());
transactions.refresh();
CurrencyConverter converter = new CurrencyConverterImpl(factory, portfolio.getReferenceAccount().getCurrencyCode());
statementOfAssets.setInput(PortfolioSnapshot.create(portfolio, converter, LocalDate.now()));
} else {
transactions.setInput(null, null);
transactions.refresh();
statementOfAssets.setInput((PortfolioSnapshot) null);
}
});
hookContextMenu(portfolios.getTable(), this::fillPortfolioContextMenu);
}
Aggregations