ZenQuant.MeanReversion (zen_quant v0.2.0)

Copy Markdown View Source

Mean reversion analytics for price series.

Provides Ornstein-Uhlenbeck half-life estimation, which approximates how many periods it takes for deviations from trend to decay by half.

API Functions

FunctionArityDescriptionParam Kinds
half_life1Estimate Ornstein-Uhlenbeck half-life from a price series.prices: value

Summary

Functions

Estimate Ornstein-Uhlenbeck half-life from a price series.

Functions

half_life(prices)

@spec half_life([number()]) :: {:ok, float()} | {:error, :no_mean_reversion} | nil

Estimate Ornstein-Uhlenbeck half-life from a price series.

Parameters

  • prices - List of prices in chronological order (oldest first) (value)

Returns

{:ok, half_life_in_periods}, {:error, :no_mean_reversion}, or nil for insufficient data (result_tuple)

Example

{:ok, 6.9}

Errors

  • :no_mean_reversion
# descripex:contract
%{
  params: %{
    prices: %{
      description: "List of prices in chronological order (oldest first)",
      kind: :value
    }
  },
  errors: [:no_mean_reversion],
  returns: %{
    type: :result_tuple,
    description: "{:ok, half_life_in_periods}, {:error, :no_mean_reversion}, or nil for insufficient data"
  },
  returns_example: {:ok, 6.9}
}