Class CurrencyPair
java.lang.Object
com.quantfinlib.fx.CurrencyPair
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 Summary
Modifier and TypeMethodDescriptionaddJointBusinessDays(LocalDate date, int n) Addsnjoint business days (n >= 0).base()The base currency's own holiday calendar (single-center conventions).static CurrencyPaircustom(String base, String quote, double pipSize, int pricePrecision, int spotLagDays, BusinessCalendar baseCalendar, BusinessCalendar quoteCalendar) Fully custom conventions (exotic pairs, onshore fixings, tests).booleanisJointBusinessDay(LocalDate date) Business day in both currencies' calendars.static CurrencyPairStandard conventions for a 6-letter pair code ("EURUSD", "USDJPY", ...), weekends-only calendars.static CurrencyPairStandard conventions for an explicit base/quote, weekends-only calendars.doublepips(double priceDifference) Converts a price difference to pips (e.g. 0.00013 → 1.3 pips on EURUSD).doublepipSize()One pip in price terms (0.0001, or 0.01 for JPY quotes).doublepriceFromPips(double pips) Converts pips to a price difference (the inverse ofpips(double)).intQuoted decimal places (5, or 3 for JPY quotes).quote()The quote currency's own holiday calendar — e.g. the restricted currency's local calendar that NDF fixing conventions count in.doubleround(double price) Rounds a raw price to the pair's quoted precision (half-up).Spot settlement date:spotLagDaysjoint business days after the trade date (see the class doc for the intermediate-day simplification).intSpot settlement lag in business days (T+2, or T+1 exceptions).symbol()"EURUSD" style symbol, the natural key for the tick bus.Forward settlement date for a market tenor, measured from the pair's spot date.toString()tradeDateForSpot(LocalDate spotDate) The inverse ofspotDate(java.time.LocalDate): the trade date whose spot isspotDate(which must be a joint business day) — the anchor inversion curve/instrument builders need to resolve tenors from a curve's own spot.withCalendars(BusinessCalendar baseCalendar, BusinessCalendar quoteCalendar) Same conventions with real holiday calendars for each currency's center.
-
Method Details
-
of
Standard conventions for a 6-letter pair code ("EURUSD", "USDJPY", ...), weekends-only calendars. UsewithCalendars(com.quantfinlib.rates.BusinessCalendar, com.quantfinlib.rates.BusinessCalendar)to attach real holiday calendars afterwards. -
of
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
Same conventions with real holiday calendars for each currency's center. -
base
-
quote
-
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 ofpips(double)). -
round
public double round(double price) Rounds a raw price to the pair's quoted precision (half-up). -
baseCalendar
The base currency's own holiday calendar (single-center conventions). -
quoteCalendar
The quote currency's own holiday calendar — e.g. the restricted currency's local calendar that NDF fixing conventions count in. -
isJointBusinessDay
Business day in both currencies' calendars. -
spotDate
-
tradeDateForSpot
The inverse ofspotDate(java.time.LocalDate): the trade date whose spot isspotDate(which must be a joint business day) — the anchor inversion curve/instrument builders need to resolve tenors from a curve's own spot. -
tenorDate
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
-
toString
-