Class FxRateScenarioArray
- java.lang.Object
-
- com.opengamma.strata.data.scenario.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FxRateScenarioArray.Meta
The meta-bean forFxRateScenarioArray
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DoubleArray
convert(DoubleArray amounts, Currency fromCurrency, Currency toCurrency)
Converts an amount in a currency to an amount in a different currency using this rate.FxRateScenarioArray
crossRates(FxRateScenarioArray other)
Derives a set of FX rates from these rates and another set of rates.boolean
equals(Object obj)
double
fxRate(Currency baseCurrency, Currency counterCurrency, int scenarioIndex)
Returns the FX rate for the specified currency pair and scenario index.FxRate
get(int scenarioIndex)
Returns the FX rate for a scenario.CurrencyPair
getPair()
Gets the currency pair.int
getScenarioCount()
Gets the number of scenarios.int
hashCode()
static FxRateScenarioArray.Meta
meta()
The meta-bean forFxRateScenarioArray
.FxRateScenarioArray.Meta
metaBean()
static FxRateScenarioArray
of(CurrencyPair currencyPair, DoubleArray rates)
Returns an array of FX rates for a currency pair.static FxRateScenarioArray
of(Currency base, Currency counter, DoubleArray rates)
Returns an array of FX rates for a currency pair.Stream<FxRate>
stream()
Returns a stream of the values.String
toString()
-
-
-
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 pairrates
- 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 paircounter
- the counter currency of the pairrates
- the FX rates for the currency pair- Returns:
- an array of FX rates for a currency pair
-
getScenarioCount
public int getScenarioCount()
Description copied from interface:ScenarioArray
Gets the number of scenarios.- Specified by:
getScenarioCount
in interfaceScenarioArray<FxRate>
- Returns:
- the number of scenarios
-
get
public FxRate get(int scenarioIndex)
Returns the FX rate for a scenario.- Specified by:
get
in interfaceScenarioArray<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 interfaceScenarioArray<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 ofFxRate
for every invocation.- Parameters:
baseCurrency
- the base currency, to convert fromcounterCurrency
- the counter currency, to convert toscenarioIndex
- 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 infromCurrency
to convertfromCurrency
- the currency of the amountstoCurrency
- 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 forFxRateScenarioArray
.- Returns:
- the meta-bean, not null
-
metaBean
public FxRateScenarioArray.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
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
-
-