backtrader.mathsupport module

Math Support Module - Mathematical functions for indicator calculations.

This module provides mathematical utility functions for calculating statistics used in technical indicators, such as average, variance, and standard deviation.

Functions:

average: Calculate arithmetic mean with optional Bessel’s correction. variance: Calculate variance from a sequence. standarddev: Calculate standard deviation with Bessel’s correction option.

Note

These functions are primarily used for indicator calculations. For large datasets, numpy-based implementations would provide better performance.

backtrader.mathsupport.average(x, bessel=False)[source]

:param : param x: iterable with len :param : param bessel: default False, reduces the length of the array for the

division.

Returns:

A float with the average of the elements of x

backtrader.mathsupport.variance(x, avgx=None)[source]
Parameters:
  • x – iterable with len

  • avgx – average of x

Returns:

A list with the variance for each element of x

backtrader.mathsupport.standarddev(x, avgx=None, bessel=False)[source]
Parameters:
  • x – iterable with len

  • avgx – average of x

  • bessel – (default False) to be passed to the average to divide by

  • 1 (N -)

Returns:

A float with the standard deviation of the elements of x