com.opengamma.strata.basics.currency

## Class FxMatrixBuilder

• public class FxMatrixBuilder
extends Object
A mutable builder class for FxMatrix.
• ### Method Summary

All Methods
Modifier and Type Method and Description
FxMatrixBuilder addRate(Currency ccy1, Currency ccy2, double rate)
Add a new pair of currencies to the builder.
FxMatrixBuilder addRate(CurrencyPair currencyPair, double rate)
Adds a new rate for a currency pair to the builder.
FxMatrixBuilder addRates(Map<CurrencyPair,Double> rates)
Adds a collection of new rates for currency pairs to the builder.
FxMatrix build()
Build a new FxMatrix from the data in the builder.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Method Detail

• #### build

public FxMatrix build()
Build a new FxMatrix from the data in the builder.
Returns:
a new FxMatrix
Throws:
IllegalStateException - if an attempt was made to add currencies which have no currency in common with other rates

public FxMatrixBuilder addRate(CurrencyPair currencyPair,
double rate)
Adds a new rate for a currency pair to the builder. See addRate(Currency, Currency, double) for full explanation.
Parameters:
currencyPair - the currency pair to be added
rate - 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.
Returns:
the builder updated with the new rate

public FxMatrixBuilder addRate(Currency ccy1,
Currency ccy2,
double rate)
Add a new pair of currencies to the builder.

An invocation of the method with builder.addRate(GBP, USD, 1.6) indicates that 1 pound sterling is worth 1.6 US dollars. It is equivalent to: builder.addRate(USD, GBP, 1 / 1.6) (1 US dollar is worth 0.625 pounds sterling) for all cases except where the USD/GBP rates is already in the matrix and so will be updated.

There are a number of possible outcomes when this method is called:
• The builder is currently empty. In this case these currencies and rates will be added as the initial pair.
• The builder is non-empty and neither of the currencies are currently in the matrix. In this case the currencies cannot be immediately added as there is no common currency to allow the cross rates to be calculated. The currencies and rates are put into a pending set for later processing, for example after another pair containing one of the currencies and a currency already in the matrix is added. If no such event occurs, then an exception will be thrown when build() is called.
• The builder is non-empty and one of the currencies in the pair is already in the matrix, whilst the other is not. In this case the pair and rate is added to the matrix and all the cross rates to the other currencies are calculated.
• The builder is non-empty and contains both of the currencies in the pair. In this case the pair is treated as an update to the rate already in the matrix. The first currency (ccy1) is treated as the reference currency and the second currency (ccy2) is the updated currency. All rates involving the updated currency will be recalculated using the new rate.

Note that due to one of the rates being treated as a reference, this operation is not symmetric. That is, the result of matrix.addRate(USD, EUR, 1.23) will be different to the result of matrix.addRate(EUR, USD, 1 / 1.23) when there are other currencies present in the builder.

Parameters:
ccy1 - the first currency of the pair
ccy2 - the second currency of the pair
rate - 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.
Returns:
the builder updated with the new rate
public FxMatrixBuilder addRates(Map<CurrencyPair,Double> rates)
rates - the currency pairs and rates to be added