public final class FxMatrix extends Object implements FxRateProvider, ImmutableBean, Serializable
This provides a matrix of foreign exchange rates, such that the rate can be queried for any available pair. For example, if the matrix contains the currencies 'USD', 'EUR' and 'GBP', then six rates can be queried, 'EUR/USD', 'GBP/USD', 'EUR/GBP' and the three inverse rates.
This class is immutable and threadsafe.
Modifier and Type  Class and Description 

static class 
FxMatrix.Meta
The metabean for
FxMatrix . 
Modifier and Type  Method and Description 

static FxMatrixBuilder 
builder()
Creates a builder that can be used to build instances of
FxMatrix . 
CurrencyAmount 
convert(CurrencyAmount amount,
Currency targetCurrency)
Converts a
CurrencyAmount into an amount in the specified
currency using the rates in this matrix. 
CurrencyAmount 
convert(MultiCurrencyAmount amount,
Currency targetCurrency)
Converts a
MultipleCurrencyAmount into an amount in the
specified currency using the rates in this matrix. 
static FxMatrix 
empty()
Obtains an empty FX matrix.

static Collector<? super Map.Entry<CurrencyPair,Double>,FxMatrixBuilder,FxMatrix> 
entriesToFxMatrix()
Creates a
Collector that allows a Map.Entry of currency pair to rate
to be streamed and collected into a new FxMatrix . 
boolean 
equals(Object obj) 
double 
fxRate(Currency baseCurrency,
Currency counterCurrency)
Gets the FX rate for the specified currency pair.

ImmutableSet<Currency> 
getCurrencies()
Returns the set of currencies held within this matrix.

DoubleMatrix 
getRates()
Gets the matrix with all the exchange rates.

int 
hashCode() 
FxMatrix 
merge(FxMatrix other)
Merges the entries from the other matrix into this one.

static FxMatrix.Meta 
meta()
The metabean for
FxMatrix . 
FxMatrix.Meta 
metaBean() 
static FxMatrix 
of(Currency ccy1,
Currency ccy2,
double rate)
Obtains an instance containing a single FX rate.

static FxMatrix 
of(CurrencyPair currencyPair,
double rate)
Obtains an instance containing a single FX rate.

static Collector<? super Pair<CurrencyPair,Double>,FxMatrixBuilder,FxMatrix> 
pairsToFxMatrix()
Creates a
Collector that allows a collection of pairs each containing
a currency pair and a rate to be streamed and collected into a new FxMatrix . 
<R> Property<R> 
property(String propertyName) 
Set<String> 
propertyNames() 
FxMatrixBuilder 
toBuilder()
Creates a new builder using the data from this matrix to
create a set of initial entries.

String 
toString() 
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
convert, fxRate
public static FxMatrix empty()
The result contains no currencies or rates.
public static FxMatrix of(CurrencyPair currencyPair, double rate)
This is most likely to be used in testing.
An invocation of the method with FxMatrix.of(CurrencyPair.of(GBP, USD), 1.6)
indicates that 1 pound sterling is worth 1.6 US dollars.
The matrix can also be queried for the reverse rate, from USD to GBP.
currencyPair
 the currency pair to be addedrate
 the FX rate between the base currency of the pair and the
counter currency. The rate indicates the value of one unit of the base
currency in terms of the counter currency.public static FxMatrix of(Currency ccy1, Currency ccy2, double rate)
This is most likely to be used in testing.
An invocation of the method with FxMatrix.of(GBP, USD, 1.6)
indicates that 1 pound sterling is worth 1.6 US dollars.
The matrix can also be queried for the reverse rate, from USD to GBP.
ccy1
 the first currency of the pairccy2
 the second currency of the pairrate
 the FX rate between the first currency and the second currency.
The rate indicates the value of one unit of the first currency in terms
of the second currency.public static FxMatrixBuilder builder()
FxMatrix
.public static Collector<? super Map.Entry<CurrencyPair,Double>,FxMatrixBuilder,FxMatrix> entriesToFxMatrix()
Collector
that allows a Map.Entry
of currency pair to rate
to be streamed and collected into a new FxMatrix
.FxMatrix
from a streampublic static Collector<? super Pair<CurrencyPair,Double>,FxMatrixBuilder,FxMatrix> pairsToFxMatrix()
Collector
that allows a collection of pairs each containing
a currency pair and a rate to be streamed and collected into a new FxMatrix
.FxMatrix
from a streampublic ImmutableSet<Currency> getCurrencies()
public double fxRate(Currency baseCurrency, Currency counterCurrency)
The rate returned is the rate from the base currency to the counter currency
as defined by this formula: (1 * baseCurrency = fxRate * counterCurrency)
.
fxRate
in interface FxRateProvider
baseCurrency
 the base currency, to convert fromcounterCurrency
 the counter currency, to convert toIllegalArgumentException
 if no FX rate could be foundpublic CurrencyAmount convert(CurrencyAmount amount, Currency targetCurrency)
CurrencyAmount
into an amount in the specified
currency using the rates in this matrix.amount
 the CurrencyAmount
to be convertedtargetCurrency
 the currency to convert the CurrencyAmount
topublic CurrencyAmount convert(MultiCurrencyAmount amount, Currency targetCurrency)
MultipleCurrencyAmount
into an amount in the
specified currency using the rates in this matrix.amount
 the MultipleCurrencyAmount
to be convertedtargetCurrency
 the currency to convert all entries topublic FxMatrix merge(FxMatrix other)
The other matrix should have at least one currency in common with this one. The additional currencies from the other matrix are added one by one and the exchange rate data created is coherent with some data in this matrix.
Note that if the other matrix has more than one currency in common with this one, and the rates for pairs of those currencies are different to the equivalents in this matrix, then the rates between the additional currencies is this matrix will differ from those in the original.
other
 the matrix to be merged into this onepublic FxMatrixBuilder toBuilder()
public static FxMatrix.Meta meta()
FxMatrix
.public FxMatrix.Meta metaBean()
public Set<String> propertyNames()
propertyNames
in interface Bean
public DoubleMatrix getRates()
If currencies c1 and c2 are assigned indexes i and j respectively
in the currencies
map, then the entry [i][j] is such that
1 unit of currency c1 is worth rates[i][j]
units of
currency c2.
If currencies.get(EUR)
= 0 and currencies.get(USD)
= 1,
then the element rates[0][1]
is likely to be around
1.40 and rates[1][0]
around 0.7142. The rate rates[1][0]
will be computed from fxRate[0][1] when the object is constructed
by the builder. All the element of the matrix are meaningful and coherent.
Copyright 2009Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.