Skip to main content

Contract DSL

The DerivFabric DSL models financial contracts as composable streams of conditional cash flows. The API exposes this through a serializable ContractSpec that maps 1:1 to DSL builder calls.

Operators

OperatorMeaningExample
a + bCombined (both execute)call + put = straddle
a - bLong a, short bcall(95) - call(105) = bull spread
-aNegate (swap perspective)-swap = receiver becomes payer
a * nScale by notionalcall * 100_000
a | bChoice (holder picks best)American exercise
a & cConditional on ccall & alive(barrier)

Contract types

Vanilla

{ "type": "vanilla_call", "underlying": "SPX", "strike": 4500, "expiry": "2026-12-31" }
{ "type": "vanilla_put", "underlying": "SPX", "strike": 4500, "expiry": "2026-12-31" }

Path-dependent

{ "type": "asian", "underlying": "SPX", "strike": 100, "expiry": "2026-12-31",
"optionType": "call", "averagingType": "arithmetic", "strikeType": "fixed" }
{ "type": "lookback", "underlying": "SPX", "expiry": "2026-12-31",
"optionType": "call", "lookbackType": "floating" }
{ "type": "barrier", "underlying": "SPX", "strike": 100, "expiry": "2026-12-31",
"barriers": [{"level": 90, "direction": "down", "style": "knock_out"}] }

Structured products

{ "type": "autocall", "underlying": "SPX",
"observationDates": ["2026-03-15", "2026-06-15", "2026-09-15", "2026-12-15"],
"callBarrier": 1.0, "couponBarrier": 0.8, "protectionBarrier": 0.6,
"couponRate": 0.01, "productType": "phoenix", "memoryCoupon": true }

Multi-asset

{ "type": "worst_of_autocall",
"underlyings": ["AAPL", "MSFT", "GOOGL"],
"observationDates": ["2026-06-15", "2026-12-15"],
"callBarrier": 1.0, "couponRate": 0.02, "productType": "phoenix" }

Strategies (expanded server-side)

{ "type": "strategy", "strategy": "iron_condor",
"underlying": "SPX", "putBuy": 90, "putSell": 95,
"callSell": 105, "callBuy": 110, "expiry": "2026-12-31" }

Supported strategies: straddle, strangle, bull_call_spread, bear_put_spread, iron_condor, butterfly, collar.

Algebra (composition)

{ "type": "combined", "contracts": [spec_a, spec_b, spec_c] }
{ "type": "scaled", "contract": spec, "factor": 1000.0 }
{ "type": "negated", "contract": spec }
{ "type": "conditional", "contract": spec, "condition": condition_spec }
{ "type": "choice", "left": spec_a, "right": spec_b }

Wire format

Client JSON  →  ContractSpec (serde)  →  contract_builder  →  Contract (DSL)
→ ContractEvaluator::mc_price()

No closures cross the wire. The ContractSpec is a declarative specification; the server interprets it into the runtime Contract using the existing builder API.

Multi-asset pricing

When a contract references multiple underlyings (e.g., worst-of autocall), the server:

  1. Builds a CorrelationMatrix from the request's correlation entries
  2. Creates MultiAssetPathGenerator with per-asset spot, vol, dividend
  3. Generates correlated GBM paths via Cholesky decomposition
  4. Computes the observable (worst-of, basket) at each time step
  5. Evaluates the contract payoff on the resulting performance path