Search in sources :

Example 1 with ExchangeRateProviderFactory

use of name.abuchen.portfolio.money.ExchangeRateProviderFactory 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 2 with ExchangeRateProviderFactory

use of name.abuchen.portfolio.money.ExchangeRateProviderFactory 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 3 with ExchangeRateProviderFactory

use of name.abuchen.portfolio.money.ExchangeRateProviderFactory 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

ExchangeRateProviderFactory (name.abuchen.portfolio.money.ExchangeRateProviderFactory)3 ExchangeRateTimeSeries (name.abuchen.portfolio.money.ExchangeRateTimeSeries)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2