Class MarketDataFxRateProvider

  • All Implemented Interfaces:
    FxRateProvider, Serializable, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class MarketDataFxRateProvider
    extends Object
    implements FxRateProvider, org.joda.beans.ImmutableBean, Serializable
    Provides FX rates from market data.

    This decorates an instance of MarketData to provide FX rates.

    The FX rates provided are obtained via a triangulation process. To find the FX rate for the currency pair AAA/BBB:

    1. If the rate AAA/BBB is available, return it
    2. Find the triangulation currency of AAA (TTA), try to return rate from AAA/TTA and TTA/BBB
    3. Find the triangulation currency of BBB (TTB), try to return rate from AAA/TTB and TTB/BBB
    4. Find the triangulation currency of AAA (TTA) and BBB (TTB), try to return rate from AAA/TTA, TTA/TTB and TTB/BBB
    The triangulation currency can also be specified, which is useful if all FX rates are supplied relative to a currency other than USD.
    See Also:
    Serialized Form
    • Method Detail

      • of

        public static MarketDataFxRateProvider of​(MarketData marketData)
        Obtains an instance which takes FX rates from the market data.
        Parameters:
        marketData - market data used for looking up FX rates
        Returns:
        the provider
      • of

        public static MarketDataFxRateProvider of​(MarketData marketData,
                                                  ObservableSource fxRatesSource)
        Obtains an instance which takes FX rates from the market data, specifying the source of FX rates.

        The source of FX rates is rarely needed, as most applications only need one set of FX rates.

        Parameters:
        marketData - market data used for looking up FX rates
        fxRatesSource - the source of market data for FX rates
        Returns:
        the provider
      • of

        public static MarketDataFxRateProvider of​(MarketData marketData,
                                                  ObservableSource fxRatesSource,
                                                  Currency triangulationCurrency)
        Obtains an instance which takes FX rates from the market data, specifying the source of FX rates.

        The source of FX rates is rarely needed, as most applications only need one set of FX rates.

        Parameters:
        marketData - market data used for looking up FX rates
        fxRatesSource - the source of market data for FX rates
        triangulationCurrency - the triangulation currency to use
        Returns:
        the provider
      • fxRate

        public double fxRate​(Currency baseCurrency,
                             Currency counterCurrency)
        Description copied from interface: FxRateProvider
        Gets the FX rate for the specified currency pair.

        The rate returned is the rate from the base currency to the counter currency as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).

        Specified by:
        fxRate in interface FxRateProvider
        Parameters:
        baseCurrency - the base currency, to convert from
        counterCurrency - the counter currency, to convert to
        Returns:
        the FX rate for the currency pair
      • meta

        public static org.joda.beans.TypedMetaBean<MarketDataFxRateProvider> meta()
        The meta-bean for MarketDataFxRateProvider.
        Returns:
        the meta-bean, not null
      • metaBean

        public org.joda.beans.TypedMetaBean<MarketDataFxRateProvider> metaBean()
        Specified by:
        metaBean in interface org.joda.beans.Bean
      • getMarketData

        public MarketData getMarketData()
        Gets the market data that provides the FX rates.
        Returns:
        the value of the property, not null
      • getFxRatesSource

        public ObservableSource getFxRatesSource()
        Gets the source of market data for FX rates.
        Returns:
        the value of the property, not null
      • getTriangulationCurrency

        public Optional<Currency> getTriangulationCurrency()
        Gets the triangulation currency to use.

        If specified, this currency is used to triangulate FX rates in preference to the standard approach. This would be useful if all FX rates are supplied relative to a currency other than USD.

        Returns:
        the optional value of the property, not null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object