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
| Operator | Meaning | Example |
|---|---|---|
a + b | Combined (both execute) | call + put = straddle |
a - b | Long a, short b | call(95) - call(105) = bull spread |
-a | Negate (swap perspective) | -swap = receiver becomes payer |
a * n | Scale by notional | call * 100_000 |
a | b | Choice (holder picks best) | American exercise |
a & c | Conditional on c | call & 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:
- Builds a
CorrelationMatrixfrom the request's correlation entries - Creates
MultiAssetPathGeneratorwith per-asset spot, vol, dividend - Generates correlated GBM paths via Cholesky decomposition
- Computes the observable (worst-of, basket) at each time step
- Evaluates the contract payoff on the resulting performance path