# `ZenQuant.MeanReversion`
[🔗](https://github.com/ZenHive/zen_quant/blob/v0.8.1/lib/zen_quant/mean_reversion.ex#L1)

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
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `half_life` | 1 | Estimate Ornstein-Uhlenbeck half-life from a price series. | `prices: value` |

# `half_life`

```elixir
@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

```elixir
{:ok, 6.9}
```

## Errors

  * `:no_mean_reversion`

```elixir
# 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}
}
```

---

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