Class FxRateScenarioArray

  • All Implemented Interfaces:
    ScenarioArray<FxRate>, Serializable, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class FxRateScenarioArray
    extends Object
    implements ScenarioArray<FxRate>, org.joda.beans.ImmutableBean, Serializable
    A set of FX rates between two currencies containing rates for multiple scenarios.

    This represents rates of foreign exchange. The rate 'EUR/USD 1.25' consists of three elements - the base currency 'EUR', the counter currency 'USD' and the rate '1.25'. When performing a conversion a rate of '1.25' means that '1 EUR = 1.25 USD'.

    The FxRate class represents a single rate for a currency pair. This class is intended as an efficient way of storing multiple rates for the same currency pair for use in multiple scenarios.

    See Also:
    FxRate, Serialized Form
    • Method Detail

      • of

        public static FxRateScenarioArray of​(CurrencyPair currencyPair,
                                             DoubleArray rates)
        Returns an array of FX rates for a currency pair.

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

        Parameters:
        currencyPair - the currency pair
        rates - the FX rates for the currency pair
        Returns:
        an array of FX rates for a currency pair
      • of

        public static FxRateScenarioArray of​(Currency base,
                                             Currency counter,
                                             DoubleArray rates)
        Returns an array of FX rates for a currency pair.

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

        Parameters:
        base - the base currency of the pair
        counter - the counter currency of the pair
        rates - the FX rates for the currency pair
        Returns:
        an array of FX rates for a currency pair
      • get

        public FxRate get​(int scenarioIndex)
        Returns the FX rate for a scenario.
        Specified by:
        get in interface ScenarioArray<FxRate>
        Parameters:
        scenarioIndex - the index of the scenario
        Returns:
        the FX rate for the specified scenario
        Throws:
        IndexOutOfBoundsException - if the index is invalid
      • stream

        public Stream<FxRate> stream()
        Description copied from interface: ScenarioArray
        Returns a stream of the values.

        The stream will return the value for each scenario.

        Specified by:
        stream in interface ScenarioArray<FxRate>
        Returns:
        a stream of the values
      • fxRate

        public double fxRate​(Currency baseCurrency,
                             Currency counterCurrency,
                             int scenarioIndex)
        Returns the FX rate for the specified currency pair and scenario index.

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

        This will return the rate or inverse rate, or 1 if the two input currencies are the same.

        This method is more efficient than get(int) as it doesn't create an instance of FxRate for every invocation.

        Parameters:
        baseCurrency - the base currency, to convert from
        counterCurrency - the counter currency, to convert to
        scenarioIndex - the index of the scenario for which rates are required
        Returns:
        the FX rate for the currency pair
        Throws:
        IllegalArgumentException - if no FX rate could be found
      • convert

        public DoubleArray convert​(DoubleArray amounts,
                                   Currency fromCurrency,
                                   Currency toCurrency)
        Converts an amount in a currency to an amount in a different currency using this rate.

        The from and to currencies must be the same as this rate.

        Parameters:
        amounts - the amounts in fromCurrency to convert
        fromCurrency - the currency of the amounts
        toCurrency - the currency into which the amount should be converted
        Returns:
        the amount converted into toCurrency
        Throws:
        IllegalArgumentException - if one or both input currencies are not in part of this rate
      • crossRates

        public FxRateScenarioArray crossRates​(FxRateScenarioArray other)
        Derives a set of FX rates from these rates and another set of rates.

        For example, given rates for EUR/GBP and EUR/CHF it is possible to derive rates for GBP/CHF.

        There must be exactly one currency in common between the two currency pairs and each pair must contain two different currencies. The other rates must have the same scenario count as these rates.

        The returned object contains rates for converting between the two currencies which only appear in one set of rates.

        Parameters:
        other - the other rates
        Returns:
        a set of FX rates derived from these rates and the other rates
      • meta

        public static FxRateScenarioArray.Meta meta()
        The meta-bean for FxRateScenarioArray.
        Returns:
        the meta-bean, not null
      • getPair

        public CurrencyPair getPair()
        Gets the currency pair. The pair is formed of two parts, the base and the counter. In the pair 'AAA/BBB' the base is 'AAA' and the counter is 'BBB'.
        Returns:
        the value of the property, not null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object