use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.
the class AbstractSecurityTransactionModel method updateExchangeRate.
protected void updateExchangeRate() {
// do not auto-suggest exchange rate when editing an existing transaction
if (hasSource())
return;
if (getTransactionCurrencyCode().equals(getSecurityCurrencyCode())) {
setExchangeRate(BigDecimal.ONE);
} else if (!getTransactionCurrencyCode().isEmpty() && !getSecurityCurrencyCode().isEmpty()) {
ExchangeRateTimeSeries series = //
getExchangeRateProviderFactory().getTimeSeries(getSecurityCurrencyCode(), getTransactionCurrencyCode());
if (series != null)
setExchangeRate(series.lookupRate(date).orElse(new ExchangeRate(date, BigDecimal.ONE)).getValue());
else
setExchangeRate(BigDecimal.ONE);
}
}
use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.
the class ECBExchangeRateProviderTest method testLookup.
@Test
public void testLookup() {
ExchangeRateProviderFactory factory = new ExchangeRateProviderFactory();
assertThat(factory.getTimeSeries("EUR", "CHF"), instanceOf(ExchangeRateTimeSeriesImpl.class));
assertThat(factory.getTimeSeries("CHF", "EUR"), instanceOf(InverseExchangeRateTimeSeries.class));
assertThat(factory.getTimeSeries("EUR", "XXX"), is(nullValue()));
assertThat(factory.getTimeSeries("XXX", "EUR"), is(nullValue()));
assertThat(factory.getTimeSeries("GBP", "XXX"), is(nullValue()));
assertThat(factory.getTimeSeries("XXX", "GBP"), is(nullValue()));
assertThat(factory.getTimeSeries("XZY", "XXX"), is(nullValue()));
ExchangeRateTimeSeries timeSeries = factory.getTimeSeries("CHF", "USD");
assertThat(timeSeries, instanceOf(ChainedExchangeRateTimeSeries.class));
assertThat(timeSeries.getBaseCurrency(), is("CHF"));
assertThat(timeSeries.getTermCurrency(), is("USD"));
}
use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.
the class GBXExchangeRateProviderTest method testIt.
@Test
public void testIt() {
ExchangeRateProviderFactory factory = new ExchangeRateProviderFactory();
// default value EUR -> GBP is 0.72666
ExchangeRateTimeSeries eur_gbx = factory.getTimeSeries("EUR", "GBX");
assertThat(eur_gbx.lookupRate(LocalDate.now()).get().getValue(), comparesEqualTo(new BigDecimal("72.666")));
// inverse of default EUR -> GBP
ExchangeRateTimeSeries gbx_eur = factory.getTimeSeries("GBX", "EUR");
assertThat(gbx_eur.lookupRate(LocalDate.now()).get().getValue(), comparesEqualTo(BigDecimal.ONE.divide(new BigDecimal("72.666"), 12, BigDecimal.ROUND_HALF_DOWN)));
// GBX -> GBP
ExchangeRateTimeSeries gbx_gbp = factory.getTimeSeries("GBX", "GBP");
assertThat(gbx_gbp.lookupRate(LocalDate.now()).get().getValue(), comparesEqualTo(new BigDecimal("0.01")));
// GBP -> GBX
ExchangeRateTimeSeries gbp_gbx = factory.getTimeSeries("GBP", "GBX");
assertThat(gbp_gbx.lookupRate(LocalDate.now()).get().getValue(), comparesEqualTo(new BigDecimal(100.0)));
// GBX -> USD
// default value EUR -> GBP is 0.72666
// default value EUR -> USD is 1.0836
double calculatedRate = 0.01d * (1 / 0.72666d) * 1.0836d;
ExchangeRateTimeSeries gbx_usd = factory.getTimeSeries("GBX", "USD");
assertThat(gbx_usd.lookupRate(LocalDate.now()).get().getValue().doubleValue(), closeTo(calculatedRate, 0.00000001));
// USD -> GBX
calculatedRate = (1 / 1.0836d) * 0.72666d * 100;
ExchangeRateTimeSeries usd_gbx = factory.getTimeSeries("USD", "GBX");
assertThat(usd_gbx.lookupRate(LocalDate.now()).get().getValue().doubleValue(), closeTo(calculatedRate, 0.00000001));
}
use of name.abuchen.portfolio.money.ExchangeRateTimeSeries 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()) : '-'));
}
use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.
the class AEDExchangeRateProviderTest method testIt.
@Test
public void testIt() {
ExchangeRateProviderFactory factory = new ExchangeRateProviderFactory();
ExchangeRateTimeSeries usd_aed = factory.getTimeSeries("USD", "AED");
assertThat(usd_aed.lookupRate(LocalDate.now()).get().getValue(), comparesEqualTo(new BigDecimal("3.6725")));
ExchangeRateTimeSeries aed_usd = factory.getTimeSeries("AED", "USD");
assertThat(aed_usd.lookupRate(LocalDate.now()).get().getValue(), comparesEqualTo(BigDecimal.ONE.divide(new BigDecimal("3.6725"), 10, BigDecimal.ROUND_HALF_DOWN)));
// EUR -> USD -> AED
// default value EUR -> USD is 1.0836
double calculatedRate = 1.0836d * 3.6725d;
ExchangeRateTimeSeries eur_aed = factory.getTimeSeries("EUR", "AED");
assertThat(eur_aed.lookupRate(LocalDate.now()).get().getValue().doubleValue(), closeTo(calculatedRate, 0.00000001));
}
Aggregations