# `TAlib.Indicators.Stats`
[🔗](https://github.com/benyblack/talib/blob/main/lib/indicators/stats.ex#L1)

Statistic functions (TA-Lib group).

Linear regression fits `y = intercept + slope * x` over each lookback
window with `x = 0..period - 1`. `linear_reg/2` is the fitted value at
the window's last point, `tsf/2` projects one bar ahead, `angle/2` is
the slope in degrees. `beta/3` and `correl/3` relate two series over
the window. See `TAlib` for the conventions: chronological input,
series aligned with the input, `nil` for insufficient data.

# `angle`

```elixir
@spec angle([number()], pos_integer()) :: float() | nil
```

The regression slope in degrees
(TA-Lib LINEARREG_ANGLE).

    iex> TAlib.Indicators.Stats.angle([1, 2, 3, 4, 5], 3)
    45.0

# `beta`

```elixir
@spec beta([number()], [number()], pos_integer()) :: float() | nil
```

Beta of `prices` against `market` over the `period` newest points:
`covariance / market variance`.

    iex> TAlib.Indicators.Stats.beta([1, 2, 3, 4], [2, 4, 6, 8], 3)
    2.0

# `correl`

```elixir
@spec correl([number()], [number()], pos_integer()) :: float() | nil
```

Pearson correlation of the two series over the `period` newest points.

    iex> TAlib.Indicators.Stats.correl([1, 2, 3, 4], [2, 4, 6, 8], 3)
    1.0

# `intercept`

```elixir
@spec intercept([number()], pos_integer()) :: float() | nil
```

The intercept of the linear regression over the `period` newest prices
(TA-Lib LINEARREG_INTERCEPT).

    iex> TAlib.Indicators.Stats.intercept([1, 2, 3, 4, 5], 3)
    3.0

# `linear_reg`

```elixir
@spec linear_reg([number()], pos_integer()) :: float() | nil
```

The fitted value of the linear regression at the window's last point
(TA-Lib LINEARREG).

    iex> TAlib.Indicators.Stats.linear_reg([1, 2, 3, 4, 5], 3)
    5.0

# `slope`

```elixir
@spec slope([number()], pos_integer()) :: float() | nil
```

The slope of the linear regression over the `period` newest prices
(TA-Lib LINEARREG_SLOPE).

    iex> TAlib.Indicators.Stats.slope([1, 2, 3, 4, 5], 3)
    1.0

# `tsf`

```elixir
@spec tsf([number()], pos_integer()) :: float() | nil
```

The Time Series Forecast: the regression projected one bar past the
window's last point (TA-Lib TSF).

    iex> TAlib.Indicators.Stats.tsf([1, 2, 3, 4, 5], 3)
    6.0

# `variance`

```elixir
@spec variance([number()], pos_integer()) :: float() | nil
```

The population Variance of the `period` newest prices.

    iex> TAlib.Indicators.Stats.variance([1, 2, 3, 4], 2)
    0.25

---

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