Class CurrencyPair

java.lang.Object
com.quantfinlib.fx.CurrencyPair

public final class CurrencyPair extends Object
Market conventions for an FX currency pair: quotation precision, pip size, spot lag, and settlement-date arithmetic against both currencies' holiday calendars.

Everything a strategy needs at runtime (pip size, precision, spot lag) is resolved to primitives at construction, so hot-path code can hold a CurrencyPair per dense symbol id and never re-parse conventions per tick. The date arithmetic (spotDate(java.time.LocalDate), tenorDate(java.time.LocalDate, java.lang.String)) is calendar work for the pricing/booking layer, not the tick path.

Conventions encoded

  • Pip size / precision — JPY-quoted pairs quote to 3 decimals (pip = 0.01), everything else to 5 (pip = 0.0001). Half-pip "points" shown by ECNs are the extra decimal.
  • Spot lag — T+2 for most pairs; T+1 for USDCAD, USDTRY, USDRUB and USDPHP (the market's short-dated exceptions).
  • Joint calendar — a settlement date must be a business day in both currencies' main centers. This class treats intermediate days the same way, a slight simplification of the full market rule (where a USD holiday only blocks the settlement day itself, not the intermediate days).
  • Forward tenors — months/years roll modified-following with the end-end rule: if spot is the last business day of its month, the forward date is the last business day of the target month.
  • Method Details

    • of

      public static CurrencyPair of(String pair)
      Standard conventions for a 6-letter pair code ("EURUSD", "USDJPY", ...), weekends-only calendars. Use withCalendars(com.quantfinlib.rates.BusinessCalendar, com.quantfinlib.rates.BusinessCalendar) to attach real holiday calendars afterwards.
    • of

      public static CurrencyPair of(String base, String quote)
      Standard conventions for an explicit base/quote, weekends-only calendars.
    • custom

      public static CurrencyPair custom(String base, String quote, double pipSize, int pricePrecision, int spotLagDays, BusinessCalendar baseCalendar, BusinessCalendar quoteCalendar)
      Fully custom conventions (exotic pairs, onshore fixings, tests).
    • withCalendars

      public CurrencyPair withCalendars(BusinessCalendar baseCalendar, BusinessCalendar quoteCalendar)
      Same conventions with real holiday calendars for each currency's center.
    • base

      public String base()
    • quote

      public String quote()
    • symbol

      public String symbol()
      "EURUSD" style symbol, the natural key for the tick bus.
    • pipSize

      public double pipSize()
      One pip in price terms (0.0001, or 0.01 for JPY quotes).
    • pricePrecision

      public int pricePrecision()
      Quoted decimal places (5, or 3 for JPY quotes).
    • spotLagDays

      public int spotLagDays()
      Spot settlement lag in business days (T+2, or T+1 exceptions).
    • pips

      public double pips(double priceDifference)
      Converts a price difference to pips (e.g. 0.00013 → 1.3 pips on EURUSD).
    • priceFromPips

      public double priceFromPips(double pips)
      Converts pips to a price difference (the inverse of pips(double)).
    • round

      public double round(double price)
      Rounds a raw price to the pair's quoted precision (half-up).
    • baseCalendar

      public BusinessCalendar baseCalendar()
      The base currency's own holiday calendar (single-center conventions).
    • quoteCalendar

      public BusinessCalendar quoteCalendar()
      The quote currency's own holiday calendar — e.g. the restricted currency's local calendar that NDF fixing conventions count in.
    • isJointBusinessDay

      public boolean isJointBusinessDay(LocalDate date)
      Business day in both currencies' calendars.
    • spotDate

      public LocalDate spotDate(LocalDate tradeDate)
      Spot settlement date: spotLagDays joint business days after the trade date (see the class doc for the intermediate-day simplification).
    • tradeDateForSpot

      public LocalDate tradeDateForSpot(LocalDate spotDate)
      The inverse of spotDate(java.time.LocalDate): the trade date whose spot is spotDate (which must be a joint business day) — the anchor inversion curve/instrument builders need to resolve tenors from a curve's own spot.
    • tenorDate

      public LocalDate tenorDate(LocalDate tradeDate, String tenor)
      Forward settlement date for a market tenor, measured from the pair's spot date. Supported tenors:
      • ON — trade date + 1 joint business day (pre-spot leg);
      • TN — ON date + 1 joint business day (= spot for T+2 pairs);
      • SN — spot + 1 joint business day;
      • <n>D / <n>W — spot + days/weeks, rolled following;
      • <n>M / <n>Y — spot + months/years, modified-following with the end-end rule.
    • addJointBusinessDays

      public LocalDate addJointBusinessDays(LocalDate date, int n)
      Adds n joint business days (n >= 0).
    • toString

      public String toString()
      Overrides:
      toString in class Object