DeltaCalc.MarginBridge (DeltaCalc v0.1.0)

Copy Markdown View Source

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

FunctionArityDescriptionParam Kinds
check_kill_switch3Evaluate whether negative funding plus high margin usage triggers the kill switch.avg_funding_24h: value, margin_ratio: value, opts: value
stress_test_prolonged_negative4Stress-test prolonged negative funding: rate × position × days.negative_rate: value, position_size: value, duration_days: value, opts: value
payback_timeline3Single-scenario payback: days to payoff and optional projected payoff date from daily funding.remaining_debt: value, daily_funding: value, opts: value
margin_runway_days2Estimate days until margin is exhausted at the current daily burn rate.available_margin: value, daily_burn: value
margin_ratio3Compute 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

kill_switch_result()

@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.

payback_timeline()

@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.

stress_test_result()

@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

check_kill_switch(avg_funding_24h, margin_ratio, opts \\ [])

@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%.

margin_ratio(initial_margin, option_premium, capital)

@spec margin_ratio(Decimal.t(), Decimal.t(), Decimal.t()) :: Decimal.t()

Return (initial_margin + option_premium) / capital, or zero when capital is non-positive.

margin_runway_days(available_margin, daily_burn)

@spec margin_runway_days(Decimal.t(), Decimal.t()) :: Decimal.t() | nil

Return available_margin / daily_burn, or nil when burn is non-positive.

payback_timeline(remaining_debt, daily_funding, opts \\ [])

@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.

stress_test_prolonged_negative(negative_rate, position_size, duration_days, opts \\ [])

@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).