# `DeltaCalc.OptionsRisk`
[🔗](https://github.com/ZenHive/delta_calc/blob/v0.3.0/lib/delta_calc/options_risk.ex#L1)

Long-option risk framing and margin-bridge funding stress for option buyers.

Long options have defined max loss equal to premium paid. Combined with perp-funded
margin bridges, cash-flow risk from negative funding dominates — price risk is hedged.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `monitor_margin_bridge_health` | 2 | Monitor margin-bridge health using margin ratio, runway, and status bands. | `params: value`, `opts: value` |
| `stress_test_extended_negative` | 2 | Stress-test multiple negative funding rates over an extended horizon. | `params: value`, `opts: value` |
| `calculate_negative_funding_impact` | 1 | Estimate daily funding drain and cash-flow risk under negative rates. | `params: value` |
| `calculate_total_exposure` | 1 | Sum gross exposure across spot, perp, options, and margin debt legs. | `legs: value` |
| `max_loss` | 1 | Return defined max loss for long options (premium paid only). | `option_premiums: value` |

# `decimal_input`

```elixir
@type decimal_input() :: DeltaCalc.Decimal.input()
```

# `exposure_inputs`

```elixir
@type exposure_inputs() :: %{
  spot_notional: decimal_input(),
  perp_notional: decimal_input(),
  options_notional: decimal_input(),
  margin_debt: decimal_input()
}
```

# `exposure_result`

```elixir
@type exposure_result() :: %{
  spot_notional: Decimal.t(),
  perp_notional: Decimal.t(),
  options_notional: Decimal.t(),
  margin_debt: Decimal.t(),
  total_exposure: Decimal.t()
}
```

# `extended_stress_inputs`

```elixir
@type extended_stress_inputs() :: %{
  :funding_rates =&gt; [decimal_input()],
  :position_size =&gt; decimal_input(),
  optional(:scenario) =&gt; atom()
}
```

# `extended_stress_result`

```elixir
@type extended_stress_result() :: %{
  scenario: atom(),
  scenarios: [stress_scenario()],
  kill_switch_day_min: pos_integer() | nil,
  kill_switch_day_max: pos_integer() | nil
}
```

# `health_status`

```elixir
@type health_status() :: :healthy | :warning | :critical
```

# `margin_health`

```elixir
@type margin_health() :: %{
  margin_ratio: Decimal.t(),
  runway_days: Decimal.t() | nil,
  health_status: health_status()
}
```

# `margin_health_inputs`

```elixir
@type margin_health_inputs() :: %{
  initial_margin: decimal_input(),
  option_premium: decimal_input(),
  capital: decimal_input(),
  available_margin: decimal_input(),
  daily_burn: decimal_input()
}
```

# `max_loss_result`

```elixir
@type max_loss_result() :: %{
  max_loss: Decimal.t(),
  risk_model: :premium_only,
  limited_downside: true
}
```

# `negative_funding_impact`

```elixir
@type negative_funding_impact() :: %{
  daily_cost: Decimal.t(),
  capital_at_risk: boolean(),
  cash_flow_risk: boolean(),
  market_setup: :bullish | :neutral | :bearish,
  opportunity: :high | :moderate | :low
}
```

# `negative_funding_inputs`

```elixir
@type negative_funding_inputs() :: %{
  :negative_rate =&gt; decimal_input(),
  :position_size =&gt; decimal_input(),
  optional(:market_context) =&gt; atom(),
  optional(:capital_protected) =&gt; boolean(),
  optional(:periods_per_day) =&gt; pos_integer()
}
```

# `stress_scenario`

```elixir
@type stress_scenario() :: %{
  rate: Decimal.t(),
  daily: Decimal.t(),
  margin_impact: Decimal.t()
}
```

# `calculate_negative_funding_impact`

```elixir
@spec calculate_negative_funding_impact(negative_funding_inputs()) ::
  negative_funding_impact()
```

Compute negative-funding cash-flow impact for a delta-neutral margin bridge.

`:negative_rate` is a decimal fraction per funding period (e.g. `-0.0003` for
`-0.03%`), matching `Funding`/`Hedging`/`MarginBridge` — not a percent number.
`:capital_protected` defaults to true (price risk hedged). `:market_context` adjusts
qualitative setup/opportunity fields (`:post_crash`, `:bear_market`, etc.).

# `calculate_total_exposure`

```elixir
@spec calculate_total_exposure(exposure_inputs()) :: exposure_result()
```

Return per-leg notionals and `total_exposure` as the sum of absolute leg values.

# `max_loss`

```elixir
@spec max_loss(decimal_input() | [decimal_input()]) :: max_loss_result()
```

Frame long-option risk as premium-only max loss.

Accepts one premium or a list; returns the summed premium as `max_loss`.

# `monitor_margin_bridge_health`

```elixir
@spec monitor_margin_bridge_health(
  margin_health_inputs(),
  keyword()
) :: margin_health()
```

Evaluate margin-bridge health during the payback period.

Delegates ratio and runway math to `DeltaCalc.MarginBridge`. Three status bands default to
phase7 thresholds: healthy at or below 25%, warning above 25% through 35%, critical above
the `:reduce` threshold (default 35%).

# `stress_test_extended_negative`

```elixir
@spec stress_test_extended_negative(
  extended_stress_inputs(),
  keyword()
) :: extended_stress_result()
```

Run extended negative-funding scenarios (default 90 days) across multiple rates.

Each rate in `:funding_rates` is a decimal fraction per period (e.g. `-0.0002` for
`-0.02%`), matching `Funding`/`Hedging`/`MarginBridge`. `margin_impact` is the funding
drain as a ratio of free capital headroom below the kill-switch threshold
(e.g. `0.07` for 7% of headroom).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
