DeltaCalc.MarginBridge (DeltaCalc v0.3.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 daily-normalized negative funding plus high margin usage.per_period_funding_rate: 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 after normalizing per-period funding to a daily fraction.

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() :: %{
  per_period_funding_rate: Decimal.t(),
  periods_per_day: Decimal.t(),
  daily_funding_rate: Decimal.t(),
  margin_ratio: Decimal.t(),
  daily_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(per_period_funding_rate, margin_ratio, opts \\ [])

Return kill-switch status after normalizing per-period funding to a daily fraction.

The comparison is per_period_funding_rate * periods_per_day < daily_funding_threshold. The default cadence of 3, daily threshold of -0.0006, and margin threshold of 0.25 are conventions; each is overridable through opts.

margin_ratio(initial_margin, option_premium, capital)

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

margin_runway_days(available_margin, daily_burn)

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

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

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

Compute single-scenario payback days from remaining_debt and daily_funding.

Pass from_date: in opts to include projected_payoff_date. days_to_payoff preserves Decimal precision; date projection alone rounds up because a Date is an intrinsic whole-day boundary. 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(
  DeltaCalc.Decimal.input(),
  DeltaCalc.Decimal.input(),
  pos_integer(),
  keyword()
) :: stress_test_result()

Compute daily and total funding cost under prolonged negative rates.

negative_rate is a decimal fraction per funding period (e.g. -0.00025 for -0.025%), matching Funding/Hedging — not a percent number. Scale to daily cost with periods_per_day. Its default of 3 is an overridable cadence convention. kill_switch_day, when requested, rounds up because it identifies the first whole calendar day on which the threshold is crossed.