Class SyntheticCross
java.lang.Object
com.quantfinlib.fx.SyntheticCross
Direct-versus-synthetic cross execution arithmetic: an FX cross (EURJPY)
can be dealt directly or replicated through its liquid legs (buy EURUSD,
buy USDJPY), and the cheaper route changes with every quote — direct
cross books are thin outside London hours while the USD legs stay tight.
marketdata.CrossRateEngine (low-latency artifact) streams the synthetic rates; this class
answers the execution question: what does each route cost after
crossing every spread involved, and which should this clip take.
Spread composition is the whole point: a synthetic buy pays the ask on
both legs (CrossOp.MULTIPLY: askA × askB) or the ask of one and the
bid of the other (CrossOp.DIVIDE: askA ÷ bidB) — two half-spreads
against one on the direct route. The synthetic still wins whenever the
legs are tight enough, which is exactly what this comparison detects.
Static, primitives-only, zero allocation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublebuySavings(double directAsk, CrossOp op, double bidA, double askA, double bidB, double askB) Savings per unit of buying synthetically instead of directly (positive = the legs are cheaper).static booleanbuySyntheticWins(double directAsk, CrossOp op, double bidA, double askA, double bidB, double askB) True when buying through the legs beats the direct ask (NaN-safe: false).static doublesellSavings(double directBid, CrossOp op, double bidA, double askA, double bidB, double askB) Mirror: extra proceeds per unit of selling via the legs (positive = legs win).static booleansellSyntheticWins(double directBid, CrossOp op, double bidA, double askA, double bidB, double askB) True when selling through the legs beats the direct bid (NaN-safe: false).static doublesyntheticAsk(CrossOp op, double bidA, double askA, double bidB, double askB) All-in synthetic ASK (cost to BUY the cross via the legs).static doublesyntheticBid(CrossOp op, double bidA, double askA, double bidB, double askB) All-in synthetic BID (proceeds of selling the cross via the legs): the mirror ofsyntheticAsk(CrossOp, double, double, double, double).
-
Method Details
-
syntheticAsk
All-in synthetic ASK (cost to BUY the cross via the legs). Multiply (A/B × B/C = A/C): buy both legs → askA × askB. Divide (A/C ÷ B/C = A/B): buy leg A, sell leg B → askA ÷ bidB. -
syntheticBid
All-in synthetic BID (proceeds of selling the cross via the legs): the mirror ofsyntheticAsk(CrossOp, double, double, double, double). -
buySavings
public static double buySavings(double directAsk, CrossOp op, double bidA, double askA, double bidB, double askB) Savings per unit of buying synthetically instead of directly (positive = the legs are cheaper). NaN when either route is unpriced, where "unpriced" means NaN, zero (the Java default and what an emptyFxTierBooktier reads as) or negative. An unquoted book can therefore never masquerade as an attractive route, including via the divide-by-zero infinity a rawsyntheticBid(CrossOp, double, double, double, double)would produce. -
sellSavings
public static double sellSavings(double directBid, CrossOp op, double bidA, double askA, double bidB, double askB) Mirror: extra proceeds per unit of selling via the legs (positive = legs win). -
buySyntheticWins
public static boolean buySyntheticWins(double directAsk, CrossOp op, double bidA, double askA, double bidB, double askB) True when buying through the legs beats the direct ask (NaN-safe: false). -
sellSyntheticWins
public static boolean sellSyntheticWins(double directBid, CrossOp op, double bidA, double askA, double bidB, double askB) True when selling through the legs beats the direct bid (NaN-safe: false).
-