Skip to main content

How It Works

Calculator implements the portfolio margin formulas from Margin using risk surface data fetched live from the APIs. Risk surfaces: Fetches the full risk surface for every listed market via GET /riskSurfaces. Each response contains all 9 regime surfaces (the complete 2D lambda grid of notional x leverage knots with mmrO, mmrE, p triplets), plus pair correlations and the asset’s current live regime. You can query this endpoint directly to build your own margin tooling. Time decay: Each grid point contains three values. The effective lambda at time tt into the current regime is: λ(t)=λE+(λO−λE)⋅pt\lambda(t) = \lambda_E + (\lambda_O - \lambda_E) \cdot p^t Where λO\lambda_O is the start-of-regime value, λE\lambda_E is the equilibrium value, and pp is the transition probability. The calculator uses the live regimeDt from the WebSocket ticker stream for time decay. Live prices: Mark prices stream via WebSocket from the ticker and frontendContext subscriptions. Correlation matrix: Pair correlations are returned by the risk surfaces endpoint. The correlation between assets ii and jj is ρij\rho_{ij}, used in both the effective notional and portfolio margin calculations. Regime sensitivity: The risk surfaces have a 2% floor for small positions. Regime differentiation in lambda values becomes visible at higher notional values (roughly $750k+ for BTC) and portfolio leverage (4-5x+). At these sizes, bear and bull regimes can produce significantly different margin requirements. The margin calculation pipeline:
  1. Signed notional - sNi=sign(Qi)⋅∣Qi∣⋅PisN_i = \text{sign}(Q_i) \cdot |Q_i| \cdot P_i
  2. Effective notional - Neff=∑isNi2+2∑i<jsNi⋅sNj⋅ρijN_{\text{eff}} = \sqrt{\sum_i sN_i^2 + 2\sum_{i \lt j} sN_i \cdot sN_j \cdot \rho_{ij}}
  3. Portfolio leverage - L=Neff/CL = N_{\text{eff}} / C
  4. Lambda lookup - bilinear interpolation on the 2D surface (notional x leverage knots) with time decay
  5. Portfolio margin - Mp=∑iMi2+2∑i<jMi⋅Mj⋅ρijM_p = \sqrt{\sum_i M_i^2 + 2\sum_{i \lt j} M_i \cdot M_j \cdot \rho_{ij}}