Bourse.OptionProposal.Hedge (bourse v0.1.0)

Copy Markdown View Source

Pure spot/perp hedge quantity calculation for a caller-chosen target delta.

Rounds to venue amount precision and reports the residual delta after rounding. Candidate selection follows only the caller's venue policy and candidate list — this module never invents instruments or strategy.

Summary

Functions

Selects a hedge candidate under venue_policy and sizes it to target_delta.

Returns the venue quantity step and delta carried by one signed candidate unit.

Types

candidate()

@type candidate() :: %{
  :id => term(),
  :venue => String.t(),
  :account => term(),
  :symbol => String.t(),
  :market => Bourse.Market.t(),
  optional(:kind) => term(),
  optional(:price) => number(),
  optional(:quote) => number() | map()
}

venue_policy()

@type venue_policy() :: :same_only | :prefer_same_venue | :cross_allowed

Functions

calculate(current_delta, target_delta, candidates, venue_policy, option_venues)

@spec calculate(number(), number(), [candidate()], venue_policy(), [String.t()]) ::
  {:ok, map()} | {:error, atom() | {atom(), term()}}

Selects a hedge candidate under venue_policy and sizes it to target_delta.

current_delta is post-option, pre-hedge exposure in underlying units. A zero needed hedge returns quantity 0 with residual current - target. Inverse candidates use a positive caller :price, then a price-bearing caller :quote, before falling back to price fields in market.info.

candidate_terms(candidate)

@spec candidate_terms(map()) ::
  {:ok,
   %{
     market: Bourse.Market.t(),
     kind: term(),
     amount_step: float(),
     delta_per_unit: float()
   }}
  | {:error, atom()}

Returns the venue quantity step and delta carried by one signed candidate unit.