Pure margin-bridge formulas for perp-funded option financing.
Computes margin usage ratios, runway, payback timelines, negative-funding stress, and funding kill-switch conditions using Decimal arithmetic throughout.
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
check_kill_switch | 3 | Evaluate whether negative funding plus high margin usage triggers the kill switch. | avg_funding_24h: value, margin_ratio: value, opts: value |
stress_test_prolonged_negative | 4 | Stress-test prolonged negative funding: rate × position × days. | negative_rate: value, position_size: value, duration_days: value, opts: value |
payback_timeline | 3 | Single-scenario payback: days to payoff and optional projected payoff date from daily funding. | remaining_debt: value, daily_funding: value, opts: value |
margin_runway_days | 2 | Estimate days until margin is exhausted at the current daily burn rate. | available_margin: value, daily_burn: value |
margin_ratio | 3 | Compute margin usage as (initial_margin + option_premium) / capital. | initial_margin: value, option_premium: value, capital: value |
Summary
Types
Kill-switch evaluation for margin bridge safety.
Payback projection from remaining debt and daily funding income.
Negative-funding stress scenario over a duration.
Functions
Return kill-switch status when avg_funding_24h is below threshold and margin exceeds 25%.
Return (initial_margin + option_premium) / capital, or zero when capital is non-positive.
Return available_margin / daily_burn, or nil when burn is non-positive.
Compute single-scenario payback days from remaining_debt and daily_funding.
Compute daily and total funding cost under prolonged negative rates.
Types
@type kill_switch_result() :: %{ avg_funding_24h: Decimal.t(), margin_ratio: Decimal.t(), funding_threshold: Decimal.t(), margin_threshold: Decimal.t(), kill_switch_triggered: boolean() }
Kill-switch evaluation for margin bridge safety.
@type payback_timeline() :: %{ remaining_debt: Decimal.t(), daily_funding: Decimal.t(), days_to_payoff: Decimal.t() | nil, projected_payoff_date: Date.t() | nil }
Payback projection from remaining debt and daily funding income.
@type stress_test_result() :: %{ negative_rate: Decimal.t(), position_size: Decimal.t(), duration_days: pos_integer(), daily_cost: Decimal.t(), total_cost: Decimal.t(), kill_switch_day: pos_integer() | nil }
Negative-funding stress scenario over a duration.
Functions
@spec check_kill_switch(Decimal.t(), Decimal.t(), keyword()) :: kill_switch_result()
Return kill-switch status when avg_funding_24h is below threshold and margin exceeds 25%.
Return (initial_margin + option_premium) / capital, or zero when capital is non-positive.
Return available_margin / daily_burn, or nil when burn is non-positive.
@spec payback_timeline(Decimal.t(), Decimal.t(), keyword()) :: payback_timeline()
Compute single-scenario payback days from remaining_debt and daily_funding.
Pass from_date: in opts to include projected_payoff_date.
For best/expected/worst cases under funding volatility, use
DeltaCalc.FundingProjection.project_payback_timeline/1.
@spec stress_test_prolonged_negative( Decimal.t(), Decimal.t(), pos_integer(), keyword() ) :: stress_test_result()
Compute daily and total funding cost under prolonged negative rates.
negative_rate is percent per funding period. Scale to daily cost with
periods_per_day (default 3 for 8h funding; use 24 for Deribit hourly).