Portfolio Finder Statistics API Reference

Portfolio Finder Statistics

Collection of classes and methods used to generate and analyze statistics for backtested portfolios.

portfoliofinder.stats.Callable

Callable type; Callable[[int], str] is a function of (int) -> str.

The subscription syntax must always be used with exactly two values: the argument list and the return type. The argument list must be a list of types or ellipsis; the return type must be a single type.

There is no syntax to indicate optional or keyword arguments, such function types are rarely used as callback types.

alias of Callable

portfoliofinder.stats.gmean(a, axis=0, dtype=None)[source]

Compute the geometric mean along the specified axis.

Return the geometric average of the array elements. That is: n-th root of (x1 * x2 * … * xn)

aarray_like

Input array or object that can be converted to an array.

axisint or None, optional

Axis along which the geometric mean is computed. Default is 0. If None, compute over the whole array a.

dtypedtype, optional

Type of the returned array and of the accumulator in which the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.

gmeanndarray

See dtype parameter above.

numpy.mean : Arithmetic average numpy.average : Weighted average hmean : Harmonic mean

The geometric average is computed over a single dimension of the input array, axis=0 by default, or all values in the array if axis=None. float64 intermediate and return values are used for integer inputs.

Use masked arrays to ignore any non-finite values in the input or that arise in the calculations such as Not a Number and infinity because masked arrays automatically mask any non-finite values.

>>> from scipy.stats import gmean
>>> gmean([1, 4])
2.0
>>> gmean([1, 2, 3, 4, 5, 6, 7])
3.3800151591412964
portfoliofinder.stats.percentile_for(percentile: int) → Callable[[pandas.core.series.Series], float][source]

Creates a function to calculate the specified percentile.

Parameters

percentile – Percentile as an integer from 0 to 100

Returns

function to calculate the specified percentile

portfoliofinder.stats.sharpe_ratio(series: pandas.core.series.Series)float[source]

Calculates the Sharpe ratio for a series of returns.

This function assumes that returns are already relative to a risk-free rate, and thus simply calculates mean / std.

Parameters

series – series of calculate ratio for

Returns

sharpe ratio