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
FxRateclass 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 classFxRateScenarioArray.MetaThe meta-bean forFxRateScenarioArray.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DoubleArrayconvert(DoubleArray amounts, Currency fromCurrency, Currency toCurrency)Converts an amount in a currency to an amount in a different currency using this rate.FxRateScenarioArraycrossRates(FxRateScenarioArray other)Derives a set of FX rates from these rates and another set of rates.booleanequals(Object obj)doublefxRate(Currency baseCurrency, Currency counterCurrency, int scenarioIndex)Returns the FX rate for the specified currency pair and scenario index.FxRateget(int scenarioIndex)Returns the FX rate for a scenario.CurrencyPairgetPair()Gets the currency pair.intgetScenarioCount()Gets the number of scenarios.inthashCode()static FxRateScenarioArray.Metameta()The meta-bean forFxRateScenarioArray.FxRateScenarioArray.MetametaBean()static FxRateScenarioArrayof(CurrencyPair currencyPair, DoubleArray rates)Returns an array of FX rates for a currency pair.static FxRateScenarioArrayof(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.StringtoString()
-
-
-
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:ScenarioArrayGets the number of scenarios.- Specified by:
getScenarioCountin interfaceScenarioArray<FxRate>- Returns:
- the number of scenarios
-
get
public FxRate get(int scenarioIndex)
Returns the FX rate for a scenario.- Specified by:
getin 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:ScenarioArrayReturns a stream of the values.The stream will return the value for each scenario.
- Specified by:
streamin 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 ofFxRatefor 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 infromCurrencyto 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:
metaBeanin 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
-
-