RiskEngine.Portfolio.Server (risk_engine v0.1.0)

Copy Markdown View Source

GenServer callbacks for portfolio state management.

Not called directly — use RiskEngine.Portfolio's client API instead. Each server owns the state for a single portfolio: its trade history, running cash exposure, and the derived risk metrics (volatility and drawdown) recomputed by RiskEngine.RiskCalculator after every trade. Updates are published via RiskEngine.RiskBroadcaster.

Summary

Types

t()

A portfolio's state.

Functions

Returns a specification to start this module under a supervisor.

Types

t()

@type t() :: %{
  id: String.t(),
  trades: [RiskEngine.TradeIngestion.trade()],
  cash_exposure: float(),
  peak_exposure: float(),
  volatility: float(),
  drawdown_pct: float(),
  updated_at: DateTime.t() | nil
}

A portfolio's state.

  • :id — the portfolio id.
  • :trades — trades applied so far, most recent first.
  • :cash_exposure — signed net exposure (buys add, sells subtract).
  • :peak_exposure — the highest absolute exposure ever observed; only ever grows, and is the reference point for :drawdown_pct.
  • :volatility — standard deviation of recent signed trade notionals, see RiskEngine.RiskCalculator.volatility/1.
  • :drawdown_pct — percentage pullback from :peak_exposure, see RiskEngine.RiskCalculator.drawdown/2.
  • :updated_at — timestamp of the last processed trade, or nil if no trade has been submitted yet.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.