Diffusal
Protocol

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 with deposited USDC and multiple option positions across different series.

This enables capital efficiency: a long call can offset some of the risk from a short put, reducing total margin requirements.


Portfolio Equity Calculation

The core health metric is Portfolio Equity:

Portfolio Equity=Deposited Collateral+Unrealized PnL\text{Portfolio Equity} = \text{Deposited Collateral} + \text{Unrealized PnL}

Unrealized PnL

For each position, unrealized PnL is calculated against current mark price:

Unrealized PnL=i(current_markientry_premiumi)×position_sizei\text{Unrealized PnL} = \sum_{i} (\text{current\_mark}_i - \text{entry\_premium}_i) \times \text{position\_size}_i

For long positions (size > 0):

  • Positive if option value increased (mark > entry)
  • Negative if option value decreased

For short positions (size < 0):

  • Positive if option value decreased (obligation worth less)
  • Negative if option value increased (obligation worth more)

Example

PositionEntry PremiumCurrent MarkSizePnL
Long ETH Call$150$180+10+$300
Short ETH Put$120$140-5-$100
Total+$200

If deposited collateral is $5,000:

Equity=$5,000+$200=$5,200\text{Equity} = \$5,000 + \$200 = \$5,200

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 calls (down + high vol)
2-30%-30%Long calls (down + vol crush)
3+30%+50%Short puts (up + high vol)
4+30%-30%Long puts (up + vol crush)

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)

Stress Loss Calculation

For each scenario:

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

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 loss across stress scenarios
  • Adverse PnL Buffer: max(0,Unrealized PnL)×1.05\max(0, -\text{Unrealized PnL}) \times 1.05 (covers current losses with 5% buffer)
  • Notional Buffer: Total Notional×0.15\text{Total Notional} \times 0.15 (15% of total position notional)

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 Example

Consider a portfolio with ETH at $3,000 spot and 50% IV:

Positions

PositionStrikeExpiryEntry PremiumSize
Long ETH Call$3,20030 days$150+10
Short ETH Put$2,80030 days$120-5

Deposited Collateral: $2,000

Step 1: Current Premiums (Black-Scholes)

Using Black-Scholes with spot=$3,000, IV=50%, r=5%, T=30/365:

OptionCurrent Mark
$3,200 Call$98.76
$2,800 Put$80.63

Step 2: Unrealized PnL

PositionEntryMarkSizePnL
Long Call$150$98.76+10-$512.40
Short Put$120$80.63-5+$196.85
Total-$315.55

Step 3: Stress Losses

Testing scenario 1 (Spot -30%, IV +50%):

  • Stressed spot: $2,100
  • Stressed IV: 75%
PositionCurrent MarkStressed MarkLoss
Long Call$98.76$45.20-$535.60
Short Put$80.63$142.30-$307.85
Total-$843.45

After testing all 4 scenarios, maximum stress loss: $843.45

Step 4: Required Collateral

IM=$843.45+($315.55×1.05)+$750=$1,924.78\text{IM} = \$843.45 + (\$315.55 \times 1.05) + \$750 = \$1,924.78 MM=$1,924.78×0.80=$1,539.82\text{MM} = \$1,924.78 \times 0.80 = \$1,539.82

Step 5: Health Check

Equity=$2,000$315.55=$1,684.45\text{Equity} = \$2,000 - \$315.55 = \$1,684.45

Since 1,684.45>1,684.45 > 1,539.82 (MM), the position is Healthy.


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_MULTIPLIER1.05Buffer on unrealized losses

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.

Entry Premium Recording

When a trade executes, the actual trade price is recorded as entry premium. For example, if a user buys 10 contracts via RFQ at 51.50each,theentrypremiumis51.50 each, the entry premium is 51.50. Later, if the current mark price (from Black-Scholes) is 50.20,theunrealizedPnLwouldbe(50.20, the unrealized PnL would be (50.20 - 51.50)×10=51.50) × 10 = -13.00.

The user paid above theoretical (the spread), so they start with a small unrealized 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})

Gas Optimization

The margin calculation is gas-intensive due to Black-Scholes evaluations. Optimizations include:

TechniqueBenefit
Batch oracle readsSingle oracle call for all positions on same pair
Cached GreeksReuse delta/gamma for nearby strikes
Off-chain pre-checkFrontend simulates margin before submission
Incremental updatesOnly recalculate affected positions on trade

Target gas cost: ~50,000 gas per margin check on high-throughput EVM chains.


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

On this page