public interface FxRateProvider
This provides the ability to obtain an FX rate. The interface does not mandate when the rate applies, however it typically represents the current rate.
One possible implementation is FxMatrix.
Implementations do not have to be immutable, but calls to the methods must be thread-safe.
| Modifier and Type | Method and Description |
|---|---|
default Decimal |
convert(Decimal amount,
Currency fromCurrency,
Currency toCurrency)
Converts an amount in a currency to an amount in a different currency using this rate.
|
default double |
convert(double amount,
Currency fromCurrency,
Currency toCurrency)
Converts an amount in a currency to an amount in a different currency using this rate.
|
double |
fxRate(Currency baseCurrency,
Currency counterCurrency)
Gets the FX rate for the specified currency pair.
|
default double |
fxRate(CurrencyPair currencyPair)
Gets the FX rate for the specified currency pair.
|
static FxRateProvider |
lazy(Supplier<FxRateProvider> target)
Returns an
FxRateProvider that delays fetching its underlying provider
until actually necessary. |
static FxRateProvider |
minimal()
Returns a provider that provides minimal behavior.
|
static FxRateProvider |
noConversion()
Returns a provider that always throws an exception.
|
static FxRateProvider lazy(Supplier<FxRateProvider> target)
FxRateProvider that delays fetching its underlying provider
until actually necessary.
This is typically useful where you may need a MarketDataFxRateProvider
but want to delay loading market data to construct the provider until you are sure you actually do need it.
target - the supplier of the underlying providerstatic FxRateProvider noConversion()
The provider will always throw an exception, even if the two currencies are the same.
static FxRateProvider minimal()
This provider returns a rate or 1 when the two currencies are the same. When the two currencies differ an exception will be thrown.
default double convert(double amount,
Currency fromCurrency,
Currency toCurrency)
The currencies must both be included in the currency pair of this rate.
amount - an amount in fromCurrencyfromCurrency - the currency of the amounttoCurrency - the currency into which the amount should be convertedtoCurrencyIllegalArgumentException - if either of the currencies aren't included in the currency pair of this ratedefault Decimal convert(Decimal amount, Currency fromCurrency, Currency toCurrency)
The currencies must both be included in the currency pair of this rate.
amount - an amount in fromCurrencyfromCurrency - the currency of the amounttoCurrency - the currency into which the amount should be convertedtoCurrencyIllegalArgumentException - if either of the currencies aren't included in the currency pair of this ratedouble fxRate(Currency baseCurrency, Currency counterCurrency)
The rate returned is the rate from the base currency to the counter currency
as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).
baseCurrency - the base currency, to convert fromcounterCurrency - the counter currency, to convert toRuntimeException - if no FX rate could be founddefault double fxRate(CurrencyPair currencyPair)
The rate returned is the rate from the base currency to the counter currency
as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).
currencyPair - the ordered currency pair defining the rate requiredRuntimeException - if no FX rate could be foundCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.