public final class FxRateScenarioArray extends Object implements ScenarioArray<FxRate>, org.joda.beans.ImmutableBean, Serializable
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.
FxRate,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
FxRateScenarioArray.Meta
The meta-bean for
FxRateScenarioArray. |
| Modifier and Type | Method and 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 for
FxRateScenarioArray. |
FxRateScenarioArray.Meta |
metaBean() |
static FxRateScenarioArray |
of(Currency base,
Currency counter,
DoubleArray rates)
Returns an array of FX rates for a currency pair.
|
static FxRateScenarioArray |
of(CurrencyPair currencyPair,
DoubleArray rates)
Returns an array of FX rates for a currency pair.
|
Stream<FxRate> |
stream()
Returns a stream of the values.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitof, of, of, ofSingleValuepublic static FxRateScenarioArray of(CurrencyPair currencyPair, DoubleArray rates)
The rates are the rates from the base currency to the counter currency
as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).
currencyPair - the currency pairrates - the FX rates for the currency pairpublic static FxRateScenarioArray of(Currency base, Currency counter, DoubleArray rates)
The rates are the rates from the base currency to the counter currency
as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency).
base - the base currency of the paircounter - the counter currency of the pairrates - the FX rates for the currency pairpublic int getScenarioCount()
ScenarioArraygetScenarioCount in interface ScenarioArray<FxRate>public FxRate get(int scenarioIndex)
get in interface ScenarioArray<FxRate>scenarioIndex - the index of the scenarioIndexOutOfBoundsException - if the index is invalidpublic Stream<FxRate> stream()
ScenarioArrayThe stream will return the value for each scenario.
stream in interface ScenarioArray<FxRate>public double fxRate(Currency baseCurrency, Currency counterCurrency, int scenarioIndex)
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.
baseCurrency - the base currency, to convert fromcounterCurrency - the counter currency, to convert toscenarioIndex - the index of the scenario for which rates are requiredIllegalArgumentException - if no FX rate could be foundpublic DoubleArray convert(DoubleArray amounts, Currency fromCurrency, Currency toCurrency)
The from and to currencies must be the same as this rate.
amounts - the amounts in fromCurrency to convertfromCurrency - the currency of the amountstoCurrency - the currency into which the amount should be convertedtoCurrencyIllegalArgumentException - if one or both input currencies are not in part of this ratepublic FxRateScenarioArray crossRates(FxRateScenarioArray other)
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.
other - the other ratespublic static FxRateScenarioArray.Meta meta()
FxRateScenarioArray.public FxRateScenarioArray.Meta metaBean()
metaBean in interface org.joda.beans.Beanpublic CurrencyPair getPair()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.