use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ChainedExchangeRateTimeSeriesTest method testChainedLookupOfExchangeRate.
@Test
public void testChainedLookupOfExchangeRate() {
ExchangeRateTimeSeriesImpl first = new ExchangeRateTimeSeriesImpl(null, "EUR", "USD");
first.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
first.addRate(new ExchangeRate(LocalDate.parse("2014-12-02"), BigDecimal.valueOf(2)));
first.addRate(new ExchangeRate(LocalDate.parse("2014-12-03"), BigDecimal.valueOf(3)));
ExchangeRateTimeSeriesImpl second = new ExchangeRateTimeSeriesImpl(null, "USD", "CHF");
second.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
second.addRate(new ExchangeRate(LocalDate.parse("2014-12-02"), BigDecimal.valueOf(2)));
second.addRate(new ExchangeRate(LocalDate.parse("2014-12-03"), BigDecimal.valueOf(3)));
ChainedExchangeRateTimeSeries chained = new ChainedExchangeRateTimeSeries(first, second);
assertThat(chained.lookupRate(LocalDate.parse("2014-11-30")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(chained.lookupRate(LocalDate.parse("2014-12-01")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(chained.lookupRate(LocalDate.parse("2014-12-02")).get().getValue(), is(BigDecimal.valueOf(4)));
assertThat(chained.lookupRate(LocalDate.parse("2014-12-03")).get().getValue(), is(BigDecimal.valueOf(9)));
assertThat(chained.lookupRate(LocalDate.parse("2014-12-04")).get().getValue(), is(BigDecimal.valueOf(9)));
assertThat(chained.getBaseCurrency(), is("EUR"));
assertThat(chained.getTermCurrency(), is("CHF"));
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ExchangeRateTimeSeriesImplTest method testLookupOfExchangeRateWithOneRateOnly.
@Test
public void testLookupOfExchangeRateWithOneRateOnly() {
ExchangeRateTimeSeriesImpl series = new ExchangeRateTimeSeriesImpl();
series.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
assertThat(series.lookupRate(LocalDate.parse("2014-11-30")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(series.lookupRate(LocalDate.parse("2014-12-01")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(series.lookupRate(LocalDate.parse("2014-12-02")).get().getValue(), is(BigDecimal.valueOf(1)));
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ExchangeRateTimeSeriesImplTest method testLookupOfExchangeRateWithGaps.
@Test
public void testLookupOfExchangeRateWithGaps() {
ExchangeRateTimeSeriesImpl series = new ExchangeRateTimeSeriesImpl();
series.addRate(new ExchangeRate(LocalDate.parse("2014-12-01"), BigDecimal.valueOf(1)));
series.addRate(new ExchangeRate(LocalDate.parse("2014-12-03"), BigDecimal.valueOf(3)));
assertThat(series.lookupRate(LocalDate.parse("2014-11-30")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(series.lookupRate(LocalDate.parse("2014-12-01")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(series.lookupRate(LocalDate.parse("2014-12-02")).get().getValue(), is(BigDecimal.valueOf(1)));
assertThat(series.lookupRate(LocalDate.parse("2014-12-03")).get().getValue(), is(BigDecimal.valueOf(3)));
assertThat(series.lookupRate(LocalDate.parse("2014-12-04")).get().getValue(), is(BigDecimal.valueOf(3)));
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ExchangeRatesListView method refreshChart.
private void refreshChart(ExchangeRateTimeSeries series) {
try {
chart.suspendUpdate(true);
for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
if (series == null || series.getRates().isEmpty()) {
chart.getTitle().setText(Messages.LabelCurrencies);
return;
}
List<ExchangeRate> rates = series.getRates();
LocalDate[] dates = new LocalDate[rates.size()];
double[] values = new double[rates.size()];
int ii = 0;
for (ExchangeRate rate : rates) {
dates[ii] = rate.getTime();
values[ii] = rate.getValue().doubleValue();
ii++;
}
String title = // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
"{0}/{1} ({2})", series.getBaseCurrency(), series.getTermCurrency(), series.getProvider().getName());
chart.getTitle().setText(title);
chart.addDateSeries(dates, values, Colors.TOTALS, title);
chart.adjustRange();
} finally {
chart.suspendUpdate(false);
chart.redraw();
}
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class StatementOfAssetsViewer method addCurrencyColumns.
private // NOSONAR
void addCurrencyColumns() {
// $NON-NLS-1$
Column column = new Column("baseCurrency", Messages.ColumnCurrency, SWT.LEFT, 80);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (!element.isPosition())
return null;
return element.getPosition().getInvestmentVehicle().getCurrencyCode();
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isPosition() ? ((Element) e).getPosition().getInvestmentVehicle().getCurrencyCode() : null)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("exchangeRate", Messages.ColumnExchangeRate, SWT.RIGHT, 80);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new // NOSONAR
ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (!element.isPosition())
return null;
String baseCurrency = element.getPosition().getInvestmentVehicle().getCurrencyCode();
CurrencyConverter converter = getCurrencyConverter();
ExchangeRate rate = converter.getRate(getDate(), baseCurrency);
if (useIndirectQuotation)
rate = rate.inverse();
return Values.ExchangeRate.format(rate.getValue());
}
@Override
public String getToolTipText(Object e) {
String text = getText(e);
if (text == null)
return null;
String term = getCurrencyConverter().getTermCurrency();
String base = ((Element) e).getPosition().getInvestmentVehicle().getCurrencyCode();
return text + ' ' + (useIndirectQuotation ? base + '/' + term : term + '/' + base);
}
});
column.setVisible(false);
support.addColumn(column);
column = new // $NON-NLS-1$
Column(// $NON-NLS-1$
"marketValueBaseCurrency", Messages.ColumnMarketValue + Messages.BaseCurrencyCue, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnMarketValueBaseCurrency);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (!element.isPosition())
return null;
return Values.Money.format(element.getPosition().getPosition().calculateValue(), client.getBaseCurrency());
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isPosition() ? ((Element) e).getPosition().getPosition().calculateValue() : null)));
column.setVisible(false);
support.addColumn(column);
column = new // $NON-NLS-1$
Column(// $NON-NLS-1$
"purchaseValueBaseCurrency", Messages.ColumnPurchaseValue + Messages.BaseCurrencyCue, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPurchaseValueBaseCurrency);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (!element.isPosition())
return null;
return Values.Money.formatNonZero(element.getPosition().getPosition().getFIFOPurchaseValue(), client.getBaseCurrency());
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isPosition() ? ((Element) e).getPosition().getPosition().getFIFOPurchaseValue() : null)));
column.setVisible(false);
support.addColumn(column);
column = new // $NON-NLS-1$
Column(// $NON-NLS-1$
"profitLossBaseCurrency", Messages.ColumnProfitLoss + Messages.BaseCurrencyCue, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnProfitLossBaseCurrency);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Element element = (Element) e;
if (!element.isPosition())
return null;
return Values.Money.formatNonZero(element.getPosition().getPosition().getProfitLoss(), client.getBaseCurrency());
}
});
column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isPosition() ? ((Element) e).getPosition().getPosition().getProfitLoss() : null)));
column.setVisible(false);
support.addColumn(column);
}
Aggregations