Search in sources :

Example 1 with ExchangeRateTimeSeries

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);
    }
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries)

Example 2 with ExchangeRateTimeSeries

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"));
}
Also used : ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) Test(org.junit.Test)

Example 3 with ExchangeRateTimeSeries

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));
}
Also used : ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with ExchangeRateTimeSeries

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()) : '-'));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries)

Example 5 with ExchangeRateTimeSeries

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));
}
Also used : ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

ExchangeRateTimeSeries (name.abuchen.portfolio.money.ExchangeRateTimeSeries)8 ExchangeRate (name.abuchen.portfolio.money.ExchangeRate)5 ExchangeRateProviderFactory (name.abuchen.portfolio.money.ExchangeRateProviderFactory)4 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)2 Composite (org.eclipse.swt.widgets.Composite)2 DecimalFormat (java.text.DecimalFormat)1 MessageFormat (java.text.MessageFormat)1 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Inject (javax.inject.Inject)1 Values (name.abuchen.portfolio.money.Values)1 Messages (name.abuchen.portfolio.ui.Messages)1 Colors (name.abuchen.portfolio.ui.util.Colors)1 TimelineChart (name.abuchen.portfolio.ui.util.chart.TimelineChart)1 Column (name.abuchen.portfolio.ui.util.viewers.Column)1 ColumnViewerSorter (name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter)1 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1