Class MarketDataFxRateProvider

  • All Implemented Interfaces:
    FxRateProvider, java.io.Serializable, Bean, ImmutableBean

    public final class MarketDataFxRateProvider
    extends java.lang.Object
    implements FxRateProvider, ImmutableBean, java.io.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
      • 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 java.util.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
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object