DeltaCalc.DeltaNeutral (DeltaCalc v0.1.0)

Copy Markdown View Source

Net delta aggregation and rebalance sizing for delta-neutral portfolios.

Callers supply position maps with exchange-reported deltas (e.g. Deribit SPM delta_total for options). This module does not price options or compute Greeks.

API Functions

FunctionArityDescriptionParam Kinds
rebalance_to_neutral1Compute the hedge leg needed to flatten net delta within a tolerance.params: value
net_delta1Aggregate signed delta exposure across spot, perp, and option positions.positions: value

Summary

Functions

Sum signed delta exposure across positions.

Return the hedge adjustment to bring net delta to ~0 within tolerance.

Types

position()

@type position() :: %{
  :kind => position_kind(),
  optional(:size) => Decimal.t() | number() | String.t(),
  optional(:notional) => Decimal.t() | number() | String.t(),
  optional(:side) => position_side(),
  optional(:delta) => Decimal.t() | number() | String.t()
}

position_kind()

@type position_kind() :: :spot | :perp | :option

position_side()

@type position_side() :: :long | :short

rebalance_params()

@type rebalance_params() :: %{
  :positions => [position()],
  optional(:tolerance) => Decimal.t() | number() | String.t(),
  optional(:instrument) => :spot | :perp
}

rebalance_result()

@type rebalance_result() :: %{
  net_delta: Decimal.t(),
  within_tolerance: boolean(),
  side: :long | :short | :none,
  size: Decimal.t(),
  instrument: :spot | :perp,
  signed_hedge: Decimal.t()
}

Functions

net_delta(positions)

@spec net_delta([position()]) :: Decimal.t()

Sum signed delta exposure across positions.

Option positions must include exchange-supplied :delta (not computed here). Spot and perp positions use :delta when present; otherwise derive signed exposure from :size or :notional and :side (default :long).

rebalance_to_neutral(positions)

@spec rebalance_to_neutral(rebalance_params() | [position()]) :: rebalance_result()

Return the hedge adjustment to bring net delta to ~0 within tolerance.

When already within tolerance, :side is :none and :size is zero. :signed_hedge is sized for DeltaCalc.Hedging.suggest_hedge_distribution/1.