Diffusal

Margin System

Portfolio margin calculation using SPAN-like stress testing

Diffusal uses a portfolio margin system inspired by CME SPAN (Standard Portfolio Analysis of Risk). Unlike isolated margin where each position is collateralized independently, portfolio margin allows netting of positions and calculates collateral requirements based on worst-case portfolio loss under stress scenarios.


Cross-Margin Architecture

Users do not collateralize individual positions. Instead, all positions share a single collateral pool. Each series has four distinct instrument types created in pairs, enabling capital efficiency: a long call can offset some risk from a short put, and premium receivables offset premium obligations.


Portfolio Equity Calculation

The core health metric is Portfolio Equity:

Portfolio Equity=Deposited Collateral+Option Value+Premium Balance\text{Portfolio Equity} = \text{Deposited Collateral} + \text{Option Value} + \text{Premium Balance}

Option Value

For each position, option value is the current mark price times the option balance:

Option Value=icurrent_marki×optionBalancei\text{Option Value} = \sum_{i} \text{current\_mark}_i \times \text{optionBalance}_i
  • Long positions (optionBalance > 0): Positive value (asset)
  • Short positions (optionBalance < 0): Negative value (obligation)

Premium Balance

Premium balances represent deferred settlement obligations:

Premium Balance=ipremiumBalancei\text{Premium Balance} = \sum_{i} \text{premiumBalance}_i
  • premiumBalance > 0: User is OWED at settlement (receivable, increases equity)
  • premiumBalance < 0: User OWES at settlement (obligation, decreases equity)

Premium is an actual obligation that directly affects equity. It accumulates across trades:

  • Buyer: premiumBalance -= price × size
  • Seller: premiumBalance += price × size

Deferred Settlement

Important: Deposits do NOT change when opening positions:

  • At trade time: Option and premium balances updated; only fees transferred (premium is deferred)
  • During holding: Equity = Deposit + (mark × optionBalance) + premiumBalance
  • At settlement: Net settlement = (intrinsic × optionBalance) + premiumBalance

Example

See Worked Examples below for detailed equity calculations demonstrating how Option Value and Premium Balance combine to determine portfolio equity.


Portfolio Equity vs Deposited Cash

An important distinction: Portfolio Equity includes the mark-to-market value of positions (Option Value + Premium Balance), while Deposited Cash is only the actual USDC in the vault.

MetricDefinitionUsed For
Portfolio EquityDeposit + Option Value + Premium BalanceMargin health checks
Deposited CashRaw USDC deposit in vaultSettlement obligations

Why This Matters

A user can have:

  • High portfolio equity from profitable long positions (paper gains)
  • Low deposited cash (minimal USDC actually in the vault)
  • Expiring positions with settlement obligations requiring actual cash

The margin system sees a healthy portfolio (Equity ≥ MM), but at settlement the user may not have enough cash to pay obligations.

Example scenario:

ItemValue
Deposited cash$2,000
Long-dated calls (paper value)+$50,000
Short puts expiring tomorrow (worst-case obligation)-$8,000
Portfolio Equity$44,000 (healthy)
Cash needed at settlement$8,000 (insufficient!)

Settlement Readiness Liquidation

To handle this gap, the protocol has a separate liquidation mechanism that triggers when:

  1. Positions are within 1 day of expiry with net obligations
  2. Deposited cash is insufficient to cover worst-case settlement obligations
  3. User has liquidatable assets (non-expiring long positions or premium receivables)

This mechanism uses a waterfall approach:

  1. First: Liquidate non-expiring LONG positions at penalized mark price
  2. Then: If shortfall remains, liquidate premium receivables at a discount (default 5%, max 20%)

This is separate from margin-based liquidation that checks equity vs maintenance margin.

See Liquidation - Settlement Readiness for the full mechanism and worked examples.


Stress Testing (SPAN-like)

The margin system uses stress testing to determine required collateral. We test the corners of the risk space to find worst-case portfolio loss.

Stress Scenarios

We apply shocks to both spot price and implied volatility:

ParameterDown ShockUp Shock
Spot Price-30%+30%
Implied Volatility-30%+50%

This creates 4 corner scenarios:

ScenarioSpot ShockIV ShockPrimary Risk For
1-30%+50%Short puts (down + high vol)
2-30%-30%Long calls (down + vol crush)
3+30%+50%Short calls (up + high vol)
4+30%-30%Long puts (up + vol crush)

4-Corner Stress Testing Diagram

┌──────────────────────────────────────────────────────────────────────────┐
│                            CURRENT STATE                                  │
│  ┌────────────────────────────────────────────────────────────────────┐  │
│  │            Portfolio Value at Current Spot & IV                    │  │
│  └───────────────────────────────┬────────────────────────────────────┘  │
└──────────────────────────────────┴───────────────────────────────────────┘

         ┌─────────────────────────┼─────────────────────────┐
         │                         │                         │
         ▼                         ▼                         ▼
┌──────────────────────────────────────────────────────────────────────────┐
│                         4 STRESS SCENARIOS                                │
├─────────────────────────────────┬────────────────────────────────────────┤
│                                 │                                        │
│  ┌───────────────────────┐      │      ┌───────────────────────┐        │
│  │     Scenario 1        │      │      │     Scenario 2        │        │
│  │     Spot: -30%        │      │      │     Spot: -30%        │        │
│  │     IV: +50%          │      │      │     IV: -30%          │        │
│  │  Worst for: Short Puts│      │      │ Worst for: Long Calls │        │
│  └───────────┬───────────┘      │      └───────────┬───────────┘        │
│              │                  │                  │                    │
├──────────────┼──────────────────┼──────────────────┼────────────────────┤
│              │                  │                  │                    │
│  ┌───────────┴───────────┐      │      ┌───────────┴───────────┐        │
│  │     Scenario 3        │      │      │     Scenario 4        │        │
│  │     Spot: +30%        │      │      │     Spot: +30%        │        │
│  │     IV: +50%          │      │      │     IV: -30%          │        │
│  │Worst for: Short Calls │      │      │ Worst for: Long Puts  │        │
│  └───────────┬───────────┘      │      └───────────┬───────────┘        │
│              │                  │                  │                    │
└──────────────┴──────────────────┴──────────────────┴────────────────────┘
               │                                     │
               └───────────────────┬─────────────────┘


┌──────────────────────────────────────────────────────────────────────────┐
│                        MARGIN CALCULATION                                 │
│  ┌────────────────────────────────────────────────────────────────────┐  │
│  │  Stress Loss = max(loss across all 4 scenarios)                    │  │
│  │  IM = Stress Loss + Buffer (5%) + Notional Buffer (15%)            │  │
│  └────────────────────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────────────────────┘

Why These Values?

  • ±30% spot: Captures significant market moves (e.g., crypto flash crashes, major news events)
  • +50% IV: Volatility spikes are common during market stress (VIX can double in hours)
  • -30% IV: Vol crush after events resolve (post-earnings, post-FOMC)

Stressed Option Loss Calculation

For each scenario:

  1. Recalculate all option premiums with stressed spot and IV using Black-Scholes
  2. Compute option value change vs current mark
  3. Track the maximum loss across all scenarios
Stressed Option Loss=maxsscenarios(i(current_markistressed_marki,s)×optionBalancei)\text{Stressed Option Loss} = \max_{s \in \text{scenarios}} \left( \sum_{i} (\text{current\_mark}_i - \text{stressed\_mark}_{i,s}) \times \text{optionBalance}_i \right)

Note: The Adverse PnL Buffer is calculated as Stress Loss × 0.05 (5% buffer). Premium balances are NOT stressed—they are deterministic obligations added separately.


Required Margin Calculation

Initial Margin (IM)

Initial Margin=Stress Loss+Adverse PnL Buffer+Notional Buffer\text{Initial Margin} = \text{Stress Loss} + \text{Adverse PnL Buffer} + \text{Notional Buffer}

Where:

  • Stress Loss: Maximum option loss across all 4 stress scenarios
  • Adverse PnL Buffer: Stress Loss×0.05\text{Stress Loss} \times 0.05 — A 5% safety buffer on top of stress loss
  • Notional Buffer: Total Notional×0.15\text{Total Notional} \times 0.15 — 15% of total option position notional (mark × |optionBalance|)

Important: Notional is based on option position value (mark × optionBalance), NOT underlying asset exposure.

Why Premium is NOT in Margin

Premium balance is included in equity but NOT in margin requirements:

  • Premium is deterministic: Unlike option value (which fluctuates with market conditions), premium is a fixed, known amount
  • Already reflected in equity: Equity = Deposit + Option Value + Premium Balance — negative premium already reduces equity
  • No double-counting: Adding premium to margin would require users to hold extra capital beyond what's needed
  • Settlement readiness: A separate mechanism ensures users can pay their premium obligations at settlement

Maintenance Margin (MM)

Maintenance Margin=Initial Margin×0.80\text{Maintenance Margin} = \text{Initial Margin} \times 0.80

Health States

StateConditionAction
HealthyEquity ≥ MMNormal trading
LiquidatableEquity < MMPosition can be liquidated

Worked Examples

All examples use the following market conditions and option prices.

Reference Data

Market Parameters:

ParameterValue
ETH Spot Price$3,000
Implied Volatility50%
Risk-Free Rate5%
Time to Expiry30 days

Option Prices (Black-Scholes):

OptionStrikeMoneynessCurrent Mark
ETH Call$3,200OTM (strike > spot)$98.76
ETH Put$2,800OTM (strike < spot)$80.63

Stressed Prices (used for margin calculations):

Each scenario applies multiplicative shocks to spot and IV.

ScenarioSpotIVCall $3,200Put $2,800
Current$3,00050%$98.76$80.63
1 (Down/Up)$2,10075%$5.52$711.18
2 (Down/Down)$2,10035%$0.00$688.69
3 (Up/Up)$3,90075%$783.69$18.02
4 (Up/Down)$3,90035%$716.03$0.04

Standard Entry Prices: Call @ $150, Put @ $120 (used across examples)


Step-by-Step: Stress Testing All 4 Scenarios

For a mixed portfolio with Long 10 Call and Short 5 Put:

User's Portfolio

DirectionOptionStrikeSizeEntryCurrent MarkPosition Value
LongCall$3,200+10$150$98.76+$987.60
ShortPut$2,800-5$120$80.63-$403.15 (liability)

Note: For short positions, the "position value" represents the current liability — what it would cost to buy back the option to close the position.

Portfolio Value Under Stress

Position value formula: stressed mark×size\text{stressed mark} \times \text{size}

ScenarioLong Call (×10)Short Put (×-5)Portfolio Total
Current+$987.60-$403.15+$584.45
1+$55.20-$3,555.90-$3,500.70
2+$0.00-$3,443.45-$3,443.45
3+$7,836.90-$90.10+$7,746.80
4+$7,160.30-$0.20+$7,160.10

Note: Long positions are assets (positive). Short positions are liabilities (negative). The short put liability ranges from -$0.20 (best case, near zero) to -$3,555.90 (worst case).

Stress Loss Calculation

Stress loss = Current portfolio value - Stressed portfolio value

ScenarioPortfolio ChangeResult
1$584.45 - (-$3,500.70)+$4,085.15 loss
2$584.45 - (-$3,443.45)+$4,027.90 loss
3$584.45 - $7,746.80-$7,162.35 (gain)
4$584.45 - $7,160.10-$6,575.65 (gain)

Maximum Stress Loss: $4,085.15 (Scenario 1: Spot down, IV up)

Scenario 1 is worst because:

  • Long call loses most value (OTM becomes deeper OTM)
  • Short put liability increases (put becomes ITM with high IV)

Example A: Long Only (Bounded Margin)

Setup: A user has only long positions with $2,700 USDC deposited.

Option Position:

SeriesOption BalanceDescription
ETH Call $3,200+10Long 10 calls

Premium Position:

SeriesPremium BalanceDescription
ETH Call $3,200-$1,500Paid $150 each for 10 calls

Step 1: Calculate Option Value and Premium Balance

Option Value (mark × optionBalance):

Option Value=$98.76×10=+$987.60\text{Option Value} = \$98.76 \times 10 = +\$987.60

Premium Balance:

Premium Balance=$1,500\text{Premium Balance} = -\$1{,}500

Step 2: Calculate Portfolio Equity

Equity=Deposit+Option Value+Premium Balance\text{Equity} = \text{Deposit} + \text{Option Value} + \text{Premium Balance} =$2,700+$987.60+($1,500)=$2,187.60= \$2{,}700 + \$987.60 + (-\$1{,}500) = \$2{,}187.60

Step 3: Long Margin Calculation

Under worst-case stress (Scenario 2: spot -30% to $2,100, IV -30% to 35%):

Stressed Option Value=$0.00×10=$0.00\text{Stressed Option Value} = \$0.00 \times 10 = \$0.00

Stressed Option Loss:

Stressed Option Loss=$987.60$0.00=$987.60\text{Stressed Option Loss} = \$987.60 - \$0.00 = \$987.60

Stress Loss + Adverse PnL Buffer:

Stress Loss+Buffer=$987.60+($987.60×0.05)=$987.60+$49.38=$1,036.98\text{Stress Loss} + \text{Buffer} = \$987.60 + (\$987.60 \times 0.05) = \$987.60 + \$49.38 = \$1{,}036.98

Notional Buffer:

Notional Buffer=$987.60×15%=$148.14\text{Notional Buffer} = \$987.60 \times 15\% = \$148.14

Initial Margin:

IM=$1,036.98+$148.14=$1,185.12\text{IM} = \$1{,}036.98 + \$148.14 = \$1{,}185.12

Step 4: Calculate Maintenance Margin

MM=$1,185.12×0.80=$948.10\text{MM} = \$1{,}185.12 \times 0.80 = \$948.10

Step 5: Determine Health Status

$2,187.60$948.10\$2{,}187.60 \geq \$948.10 \quad \checkmark

Result: The position is Healthy.

Key insight: Users with long positions typically also hold Premium Payer positions (a separate instrument). Premium is NOT included in the margin requirement—it's already reflected in equity (reducing equity when negative). This prevents double-counting since the premium obligation is deterministic and known.

Settlement Scenarios:

Using the settlement formula: netSettlement=(intrinsic×optionBalance)+premiumBalance\text{netSettlement} = (\text{intrinsic} \times \text{optionBalance}) + \text{premiumBalance}

Intrinsic at ExpiryNet SettlementResult
$0 (deep OTM)$0 × 10 + (-$1,500) = -$1,500User pays $1,500
$100 (slight ITM)$1,000 + (-$1,500) = -$500User pays $500
$150 (breakeven)$1,500 + (-$1,500) = $0No payment
$300 (deep ITM)$3,000 + (-$1,500) = +$1,500User receives $1,500

Longs CAN be liquidated if their equity falls below maintenance margin.


Example B: Partial Liquidation (Succeeds)

Setup: A user holds a balanced portfolio with $3,200 USDC deposited.

Option Positions:

SeriesOption BalanceDescription
ETH Call $3,200+5Long 5 calls
ETH Put $2,800-5Short 5 puts

Premium Positions:

SeriesPremium BalanceDescription
ETH Call $3,200-$750Paid $150 each for 5 calls
ETH Put $2,800+$600Received $120 each for 5 puts
Total-$150Net premium payer

This portfolio is balanced (equal long and short contracts), but still has downside risk from the short puts.

Step 1: Calculate Option Value and Premium Balance

Option Value (mark × optionBalance):

Long call: $98.76×5=+$493.80\text{Long call: } \$98.76 \times 5 = +\$493.80 Short put: $80.63×(5)=$403.15\text{Short put: } \$80.63 \times (-5) = -\$403.15 Total Option Value=+$90.65\text{Total Option Value} = +\$90.65

Premium Balance:

Total Premium Balance=$750+$600=$150\text{Total Premium Balance} = -\$750 + \$600 = -\$150

Step 2: Calculate Portfolio Equity

Equity=Deposit+Option Value+Premium Balance\text{Equity} = \text{Deposit} + \text{Option Value} + \text{Premium Balance} =$3,200+$90.65+($150)=$3,140.65= \$3{,}200 + \$90.65 + (-\$150) = \$3{,}140.65

Step 3: Calculate Stress Loss + Adverse PnL Buffer

Under Scenario 1 (spot → $2,100, IV → 75%):

  • Call value drops: $98.76 → $5.52
  • Put value spikes: $80.63 → $711.18

Current Option Value = +$90.65

Stressed Option Value:

Long call: $5.52×5=+$27.60\text{Long call: } \$5.52 \times 5 = +\$27.60 Short put: $711.18×(5)=$3,555.90\text{Short put: } \$711.18 \times (-5) = -\$3{,}555.90 Total Stressed Option Value=$3,528.30\text{Total Stressed Option Value} = -\$3{,}528.30

Stressed Option Loss:

Stressed Loss=$90.65($3,528.30)=$3,618.95\text{Stressed Loss} = \$90.65 - (-\$3{,}528.30) = \$3{,}618.95 Stress Loss+Buffer=$3,618.95+($3,618.95×0.05)=$3,618.95+$180.95=$3,799.90\text{Stress Loss} + \text{Buffer} = \$3{,}618.95 + (\$3{,}618.95 \times 0.05) = \$3{,}618.95 + \$180.95 = \$3{,}799.90

Step 4: Calculate Notional Buffer

Total Notional=($98.76×5)+($80.63×5)=$493.80+$403.15=$896.95\text{Total Notional} = (\$98.76 \times 5) + (\$80.63 \times 5) = \$493.80 + \$403.15 = \$896.95 Notional Buffer=$896.95×15%=$134.54\text{Notional Buffer} = \$896.95 \times 15\% = \$134.54

Step 5: Calculate Initial Margin

IM=$3,799.90+$134.54=$3,934.44\text{IM} = \$3{,}799.90 + \$134.54 = \$3{,}934.44

Step 6: Calculate Maintenance Margin

MM=$3,934.44×0.80=$3,147.55\text{MM} = \$3{,}934.44 \times 0.80 = \$3{,}147.55

Step 7: Determine Health Status

$3,140.65<$3,147.55×\$3{,}140.65 < \$3{,}147.55 \quad \times

Result: The position is Liquidatable.

Partial Liquidation — detailed calculation:

Step 1: Calculate Debt

Debt=IMEquity=$3,934.44$3,140.65=$793.79\text{Debt} = \text{IM} - \text{Equity} = \$3{,}934.44 - \$3{,}140.65 = \$793.79

Step 2: Calculate Target Notional

The protocol uses notional-based partial liquidation:

Total Notional=$493.80+$403.15=$896.95\text{Total Notional} = \$493.80 + \$403.15 = \$896.95 DebtIM=$793.79$3,934.44=20.2%\frac{\text{Debt}}{\text{IM}} = \frac{\$793.79}{\$3{,}934.44} = 20.2\% Target Notional=$896.95×20.2%=$181.18\text{Target Notional} = \$896.95 \times 20.2\% = \$181.18

Step 3: Liquidate Positions (Longest-Dated First)

With equal expiry (30 days), the protocol liquidates the long call first (sorted by position direction, longs before shorts):

Long call position notional: $493.80

Since $493.80 > Target Notional $181.18, only a partial liquidation of the call position is needed:

Fraction to liquidate=$181.18$493.80=36.7%\text{Fraction to liquidate} = \frac{\$181.18}{\$493.80} = 36.7\% Contracts to liquidate=5×36.7%1.84 calls\text{Contracts to liquidate} = 5 \times 36.7\% \approx 1.84 \text{ calls}

Step 4: Calculate Position Transfer (1% penalty)

For long calls (1.84 contracts @ $98.76 mark):

Liquidator pays=1.84×$98.76×(11%)=1.84×$97.77=$179.90\text{Liquidator pays} = 1.84 \times \$98.76 \times (1 - 1\%) = 1.84 \times \$97.77 = \$179.90

User receives $179.90 for their long positions.

Step 5: Calculate Bounty

Bounty=$793.79×5%=$39.69\text{Bounty} = \$793.79 \times 5\% = \$39.69

Step 6: Re-check Health After Partial Liquidation

New deposit: $3,200 + $179.90 - $39.69 = $3,340.21

Remaining positions:

  • Long 3.16 calls: $98.76 × 3.16 = $312.08
  • Short 5 puts: $80.63 × (-5) = -$403.15
  • New Option Value: -$91.07
  • Premium Balance: -$150 (unchanged for remaining positions)

New Equity: $3,340.21 + (-$91.07) + (-$150) = $3,099.14

New margin requirements (recalculated with smaller positions):

  • Stressed call: $5.52 × 3.16 = $17.44
  • Stressed put: $711.18 × (-5) = -$3,555.90
  • New Stressed Option Value: -$3,538.46
  • New Stress Loss: -$91.07 - (-$3,538.46) = $3,447.39
  • New Stress Loss + Buffer: $3,447.39 × 1.05 = $3,619.76
  • New Notional: $312.08 + $403.15 = $715.23
  • New Notional Buffer: $715.23 × 15% = $107.28
  • New IM: $3,619.76 + $107.28 = $3,727.04
  • New MM: $3,727.04 × 80% = $2,981.63

Health Check: $3,099.14 ≥ $2,981.63? YES

Result: Partial liquidation succeeded. User retains 3.16 long calls and 5 short puts.

Key insight: The notional-based approach liquidates only the necessary value. Unlike position-count-based liquidation, the protocol supports partial position liquidation — only 1.84 of the 5 calls were liquidated to hit the target notional. The user retains their short put position and most of their long calls.


Example C: Full Liquidation (Partial Fails)

Setup: A user holds a short-heavy portfolio with only $2,500 USDC deposited.

Option Positions:

SeriesOption BalanceDescription
ETH Call $3,200+2Long 2 calls
ETH Put $2,800-10Short 10 puts

Premium Positions:

SeriesPremium BalanceDescription
ETH Call $3,200-$300Paid $150 each for 2 calls
ETH Put $2,800+$1,200Received $120 each for 10 puts
Total+$900Net premium receiver

This portfolio is heavily short-biased (5:1 short-to-long ratio), creating significant downside risk.

Step 1: Calculate Option Value and Premium Balance

Option Value (mark × optionBalance):

Long call: $98.76×2=+$197.52\text{Long call: } \$98.76 \times 2 = +\$197.52 Short put: $80.63×(10)=$806.30\text{Short put: } \$80.63 \times (-10) = -\$806.30 Total Option Value=$608.78\text{Total Option Value} = -\$608.78

Premium Balance:

Total Premium Balance=$300+$1,200=+$900\text{Total Premium Balance} = -\$300 + \$1{,}200 = +\$900

Step 2: Calculate Portfolio Equity

Equity=Deposit+Option Value+Premium Balance\text{Equity} = \text{Deposit} + \text{Option Value} + \text{Premium Balance} =$2,500+($608.78)+$900=$2,791.22= \$2{,}500 + (-\$608.78) + \$900 = \$2{,}791.22

Step 3: Calculate Stress Loss + Adverse PnL Buffer

Under Scenario 1 (spot → $2,100, IV → 75%):

  • Call value drops: $98.76 → $5.52
  • Put value spikes: $80.63 → $711.18

Current Option Value = -$608.78

Stressed Option Value:

Long call: $5.52×2=+$11.04\text{Long call: } \$5.52 \times 2 = +\$11.04 Short put: $711.18×(10)=$7,111.80\text{Short put: } \$711.18 \times (-10) = -\$7{,}111.80 Total Stressed Option Value=$7,100.76\text{Total Stressed Option Value} = -\$7{,}100.76

Stressed Option Loss:

Stressed Loss=($608.78)($7,100.76)=$6,491.98\text{Stressed Loss} = (-\$608.78) - (-\$7{,}100.76) = \$6{,}491.98 Stress Loss+Buffer=$6,491.98+($6,491.98×0.05)=$6,491.98+$324.60=$6,816.58\text{Stress Loss} + \text{Buffer} = \$6{,}491.98 + (\$6{,}491.98 \times 0.05) = \$6{,}491.98 + \$324.60 = \$6{,}816.58

Step 4: Calculate Notional Buffer

Total Notional=($98.76×2)+($80.63×10)=$197.52+$806.30=$1,003.82\text{Total Notional} = (\$98.76 \times 2) + (\$80.63 \times 10) = \$197.52 + \$806.30 = \$1{,}003.82 Notional Buffer=$1,003.82×15%=$150.57\text{Notional Buffer} = \$1{,}003.82 \times 15\% = \$150.57

Step 5: Calculate Initial Margin

IM=$6,816.58+$150.57=$6,967.15\text{IM} = \$6{,}816.58 + \$150.57 = \$6{,}967.15

Step 6: Calculate Maintenance Margin

MM=$6,967.15×0.80=$5,573.72\text{MM} = \$6{,}967.15 \times 0.80 = \$5{,}573.72

Step 7: Determine Health Status

$2,791.22<$5,573.72×\$2{,}791.22 < \$5{,}573.72 \quad \times

Result: The position is Liquidatable.

Partial Liquidation Attempt:

Step 1: Calculate Debt

Debt=IMEquity=$6,967.15$2,791.22=$4,175.93\text{Debt} = \text{IM} - \text{Equity} = \$6{,}967.15 - \$2{,}791.22 = \$4{,}175.93

Step 2: Calculate Target Notional

Total Notional=$197.52+$806.30=$1,003.82\text{Total Notional} = \$197.52 + \$806.30 = \$1{,}003.82 DebtIM=$4,175.93$6,967.15=59.9%\frac{\text{Debt}}{\text{IM}} = \frac{\$4{,}175.93}{\$6{,}967.15} = 59.9\% Target Notional=$1,003.82×59.9%=$601.29\text{Target Notional} = \$1{,}003.82 \times 59.9\% = \$601.29

Step 3: Liquidate Positions (Longest-Dated First)

With equal expiry (30 days), the long call is liquidated first:

Long call position notional: $197.52

Since $197.52 < Target Notional $601.29, the entire call position is liquidated:

Remaining Target=$601.29$197.52=$403.77\text{Remaining Target} = \$601.29 - \$197.52 = \$403.77

Next, the short put (notional $806.30) is partially liquidated:

Fraction to liquidate=$403.77$806.30=50.1%\text{Fraction to liquidate} = \frac{\$403.77}{\$806.30} = 50.1\% Puts to liquidate=10×50.1%5.0 puts\text{Puts to liquidate} = 10 \times 50.1\% \approx 5.0 \text{ puts}

Step 4: Calculate Position Transfers (1% penalty)

For long calls (2 contracts @ $98.76 mark):

Liquidator pays=2×$98.76×(11%)=2×$97.77=$195.54\text{Liquidator pays} = 2 \times \$98.76 \times (1 - 1\%) = 2 \times \$97.77 = \$195.54

For short puts (5.0 contracts @ $80.63 mark):

User pays=5.0×$80.63×(1+1%)=5.0×$81.44=$407.20\text{User pays} = 5.0 \times \$80.63 \times (1 + 1\%) = 5.0 \times \$81.44 = \$407.20

Net cash flow: $195.54 - $407.20 = -$211.66 (user pays)

Step 5: Calculate Bounty

Bounty=$4,175.93×5%=$208.80\text{Bounty} = \$4{,}175.93 \times 5\% = \$208.80

Step 6: Re-check Health After Partial Liquidation

New deposit: $2,500 - $211.66 - $208.80 = $2,079.54

Remaining positions:

  • Long 0 calls: $0
  • Short 5.0 puts: $80.63 × (-5) = -$403.15
  • New Option Value: -$403.15
  • Premium Balance: +$900 (unchanged)

New Equity: $2,079.54 + (-$403.15) + $900 = $2,576.39

New margin requirements (recalculated):

  • Stressed put value: $711.18 × (-5.0) = -$3,555.90
  • New Stress Loss: (-$403.15) - (-$3,555.90) = $3,152.75
  • Stress Loss + Buffer: $3,152.75 × 1.05 = $3,310.39
  • New Notional Buffer: $403.15 × 15% = $60.47
  • New IM: $3,310.39 + $60.47 = $3,370.86
  • New MM: $3,370.86 × 80% = $2,696.69

Health Check: $2,576.39 < $2,696.69? STILL UNHEALTHY

Step 7: Escalate to Full Liquidation

Since the user is still unhealthy after partial liquidation, the system escalates to full liquidation:

Liquidate remaining 5.0 short puts:

User pays=5.0×$81.44=$407.20\text{User pays} = 5.0 \times \$81.44 = \$407.20

Final User State:

ItemAmount
After partial$2,079.54
Remaining puts transfer-$407.20
Final deposit$1,672.34

User retains $1,672.34 but has no positions (fully liquidated).

Key insight: With a 59.9% debt/IM ratio, partial liquidation cannot restore health in this case. The short put positions contribute most of the margin requirement (stress loss), but their current mark value ($80.63) is much lower than their stressed value ($711.18). Even after liquidating 60% of notional, the remaining positions still generate enough stress loss to keep the user underwater. The system correctly escalates to full liquidation.


Example D: Unliquidatable Long Position (With Sufficient Cash)

Setup: A user holds only long positions with sufficient cash (deposit ≥ premium paid) to guarantee they can never be liquidated.

Option Position:

SeriesOption BalanceDescription
ETH Call $3,200+10Long 10 calls

Premium Position:

SeriesPremium BalanceDescription
ETH Call $3,200-$1,500Paid $150 each for 10 calls

Deposited collateral: $3,000 USDC

Step 1: Calculate Current State (mark = $98.76)

Option Value:

Option Value=$98.76×10=+$987.60\text{Option Value} = \$98.76 \times 10 = +\$987.60

Equity:

Equity=$3,000+$987.60+($1,500)=$2,487.60\text{Equity} = \$3{,}000 + \$987.60 + (-\$1{,}500) = \$2{,}487.60

Margin components:

Stress Loss+Buffer=$987.60+($987.60×0.05)=$1,036.98\text{Stress Loss} + \text{Buffer} = \$987.60 + (\$987.60 \times 0.05) = \$1{,}036.98 Notional Buffer=$987.60×15%=$148.14\text{Notional Buffer} = \$987.60 \times 15\% = \$148.14 IM=$1,036.98+$148.14=$1,185.12\text{IM} = \$1{,}036.98 + \$148.14 = \$1{,}185.12 MM=$1,185.12×80%=$948.10\text{MM} = \$1{,}185.12 \times 80\% = \$948.10

Current health: $2,487.60 > $948.10 ✓ Healthy

Step 2: Calculate Absolute Worst Case (Option Value → $0)

Even worse than the stress scenarios—the options become completely worthless:

Option Value=$0×10=$0\text{Option Value} = \$0 \times 10 = \$0

Equity at worst case:

Equity=$3,000+$0+($1,500)=$1,500\text{Equity} = \$3{,}000 + \$0 + (-\$1{,}500) = \$1{,}500

Margin at worst case (nothing left to lose):

Stress Loss+Buffer=$0+($0×0.05)=$0\text{Stress Loss} + \text{Buffer} = \$0 + (\$0 \times 0.05) = \$0 Notional Buffer=$0×15%=$0\text{Notional Buffer} = \$0 \times 15\% = \$0 IM=$0+$0=$0\text{IM} = \$0 + \$0 = \$0 MM=$0×80%=$0\text{MM} = \$0 \times 80\% = \$0

Worst case health: $1,500 > $0 ✓ Still Healthy!

Mathematical Proof: When Long-Only Positions Cannot Be Liquidated

For long-only positions, the absolute worst case is Option Value → $0 (worse than any stress scenario).

Let VV represent option value and PP represent premium paid (positive amount):

At any option value V0V \geq 0:

Equity=Deposit+VP\text{Equity} = \text{Deposit} + V - P IM=V×1.05+V×0.15=V×1.20\text{IM} = V \times 1.05 + V \times 0.15 = V \times 1.20 MM=V×1.20×0.80=V×0.96\text{MM} = V \times 1.20 \times 0.80 = V \times 0.96

For liquidation: Equity < MM

Deposit+VP<V×0.96\text{Deposit} + V - P < V \times 0.96 DepositP<V×0.96V=0.04V\text{Deposit} - P < V \times 0.96 - V = -0.04V

Key observation: For any V>0V > 0, the right side is negative. So liquidation only happens if DepositP<0\text{Deposit} - P < 0, i.e., Deposit<P\text{Deposit} < P.

At absolute worst (V=0V = 0):

Equity=DepositP\text{Equity} = \text{Deposit} - P MM=0\text{MM} = 0

Health check passes if DepositP0\text{Deposit} - P \geq 0.

DepositPremium PaidNever Liquidatable\boxed{\text{Deposit} \geq \text{Premium Paid} \Rightarrow \text{Never Liquidatable}}

In this example:

  • Deposit = $3,000
  • Premium = $1,500
  • $3,000 ≥ $1,500 ✓

Key insight: Since premium is NOT included in margin (only in equity), long-only positions can never be liquidated as long as deposit ≥ premium paid. The margin system only tracks option value risk, which naturally goes to zero as the options expire worthless—and at that point, both margin requirement and equity "floor" out together.

Important caveat: If a user's deposit is less than their premium paid, they can be liquidated even with only long positions. The protection only applies when cash covers premium obligations.


Risk Parameters

ParameterDefaultDescription
INITIAL_MARGIN_RATE15%% of notional for IM buffer
MAINTENANCE_MARGIN_RATE80%MM as % of IM
STRESS_SPOT_DOWN-30%Spot down shock
STRESS_SPOT_UP+30%Spot up shock
STRESS_IV_UP+50%IV up shock
STRESS_IV_DOWN-30%IV down shock
ADVERSE_PNL_BUFFER0.05Buffer rate on stress loss

Mark Price vs Trade Price

The margin system uses mark price (Black-Scholes theoretical) for all calculations, not the trade price:

ConceptSourceUsed For
Mark PriceBlack-Scholes (oracle inputs)Margin, PnL, liquidation triggers
Trade PriceMarket (order book / RFQ)Actual premium paid/received

This prevents manipulation: a user cannot avoid liquidation by submitting fake orders at favorable prices.

Premium Balance Recording

When a trade executes, the actual trade price determines the Premium Balance. For example, if a user buys 10 contracts via RFQ at $51.50 each:

  • optionBalance: +10 (long position)
  • premiumBalance: -$515.00 (paid $51.50 × 10)

If the current mark price is $50.20:

  • Option Value: $50.20 × 10 = $502.00
  • Total Position Effect: $502.00 + (-$515.00) = -$13.00

The user paid above theoretical (the spread), so their combined Option Value + Premium Balance shows a small loss.


Integration with Trading

Pre-Trade Check

Before any trade, the system verifies:

  1. New position margin: Would the post-trade portfolio be healthy?
  2. Sufficient collateral: Does user have enough deposited USDC?

The trade execution updates positions for both buyer and seller, then performs a post-trade margin check to ensure both parties remain healthy. If either fails the margin check, the transaction reverts.

Deposit and Withdrawal

  • Deposit: Always allowed (increases equity)
  • Withdrawal: Only if post-withdrawal Equity ≥ Initial Margin
Withdrawable=max(0,EquityInitial Margin)\text{Withdrawable} = \max(0, \text{Equity} - \text{Initial Margin})

Backend Enforcement: These margin checks are enforced both on-chain (contracts revert if post-trade health is violated) and off-chain (backend rejects matches before submission). See Backend Operations for off-chain validation details.


Contract Implementation

The margin system is implemented across several contracts:

ContractRole
MarginEngineCore SPAN-like stress testing library
DiffusalCollateralVaultDeposit/withdrawal with margin enforcement
DiffusalLiquidationEngineLiquidation when MM is breached

Protocol Documentation

Math Documentation

Contract Documentation

On this page