public final class FxRate extends Object implements FxRateProvider, org.joda.beans.ImmutableBean, Serializable
This represents a rate 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'.
See CurrencyPair for the representation that does not contain a rate.
This class is immutable and thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
FxRate.Meta
The meta-bean for
FxRate. |
| Modifier and Type | Method and Description |
|---|---|
FxRate |
crossRate(FxRate other)
Derives an FX rate from two related FX rates.
|
boolean |
equals(Object obj) |
double |
fxRate(Currency baseCurrency,
Currency counterCurrency)
Gets the FX rate for the specified currency pair.
|
CurrencyPair |
getPair()
Gets the currency pair.
|
int |
hashCode() |
FxRate |
inverse()
Gets the inverse rate.
|
static FxRate.Meta |
meta()
The meta-bean for
FxRate. |
FxRate.Meta |
metaBean() |
static FxRate |
of(Currency base,
Currency counter,
double rate)
Obtains an instance from two currencies.
|
static FxRate |
of(CurrencyPair pair,
double rate)
Obtains an instance from a currency pair.
|
static FxRate |
parse(String rateStr)
Parses a rate from a string with format AAA/BBB RATE.
|
FxRate |
toConventional()
Returns an FX rate object representing the market convention rate between the two currencies.
|
String |
toString()
Returns the formatted string version of the currency pair.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitconvert, convert, fxRate, lazy, minimal, noConversionpublic static FxRate of(Currency base, Currency counter, double rate)
The first currency is the base and the second is the counter. The two currencies may be the same, but if they are then the rate must be one.
base - the base currencycounter - the counter currencyrate - the conversion rate, greater than zeroIllegalArgumentException - if the rate is invalidpublic static FxRate of(CurrencyPair pair, double rate)
The two currencies may be the same, but if they are then the rate must be one.
pair - the currency pairrate - the conversion rate, greater than zeroIllegalArgumentException - if the rate is invalidpublic static FxRate parse(String rateStr)
The parsed format is '${baseCurrency}/${counterCurrency} ${rate}'. Currency parsing is case insensitive.
rateStr - the rate as a string AAA/BBB RATEIllegalArgumentException - if the FX rate cannot be parsedpublic FxRate inverse()
The inverse rate has the same currencies but in reverse order. The rate is the reciprocal of the original.
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).
This will return the rate or inverse rate, or 1 if the two input currencies are the same.
fxRate in interface FxRateProviderbaseCurrency - the base currency, to convert fromcounterCurrency - the counter currency, to convert toIllegalArgumentException - if no FX rate could be foundpublic FxRate crossRate(FxRate other)
Given two FX rates it is possible to derive another rate if they have a currency in common. For example, given rates for EUR/GBP and EUR/CHF it is possible to derive rates for GBP/CHF. The result will always have a currency pair in the conventional order.
The cross is only returned if the two pairs contains three currencies in total. If the inputs are invalid, an exception is thrown.
other - the other ratesIllegalArgumentException - if the cross rate cannot be calculatedpublic FxRate toConventional()
If the currency pair is the market convention pair, this method returns this, otherwise
it returns an FxRate with the inverse currency pair and reciprocal rate.
public String toString()
The format is '${baseCurrency}/${counterCurrency} ${rate}'.
public static FxRate.Meta meta()
FxRate.public FxRate.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.