FX Calc Introduction

The FX Calc package provides classes for handling Currencies and Rates within the Foreign Exchange business. The package requires JDK8.

The FX Calculator is created via a FxRateCalculatorBuilder so that the FxRateCalculator can be immutable for a given set of parameters and rates (unless you provide a BaseFxRateProvider).

Ways to import Base Rates

The FX Calculator requires Base Rates to return rates, inverse rates or cross rates. There are 3 ways to import rates via the FxRateCalculatorBuilder

  1. addRateSnapshot(FxRate rate): add the rate to an internal map per CurrencyPair, an immutable map will be given to the Calculator so the bases rates will NOT change.
  2. ratesSnapshot(Collection<FxRate> rates): add a collection of rates to an internal map per CurrencyPair, an immutable map will be given to the Calculator so the bases rates will NOT change.
  3. baseFxRateProvider(BaseFxRateProvider) You then control when the Base Rates change, the Calculator will call the required CurrencyPair you either every time or once (if cacheBaseRates is true).

FXRate

Once you have an FXRate , you can call:

  • getBid: bid (amount the quoter would buy Ccy1 for a given amount of Ccy2).
  • getAsk: ask (amount the quoter would sell Ccy1 for a given amount of Ccy2).
  • getMid: (bid+ask)/2
  • convertAmountUsingBidOrAsk: Given a monetary amount in the original currency, calculate the resulting amount in the other currency, using BID or ASK.
  • getPaymentAmountForBuying: to get the amount you would get by buying a currency amount.
  • getReceiptAmountForSelling: to get the amount you would get by selling a currency amount.

Example