perf_strat

Defined in fynance.features.metrics

perf_strat(X, S=None, base=100., axis=0, dtype=None, reinvest=False)[source]

Compute the performance of strategies for each X’ series.

With respect to this underlying and signal series along time axis.

Parameters:
Xnp.ndarray[dtype, ndim=1 or 2]

Time-series of prices or index values.

Snp.ndarray[dtype, ndim=1 or 2]

Time-series of signals, if None considering a long only position. S array must have the same shape than X. Default is None.

basefloat, optional

Initial value for measure the performance, default is 100.

reinvestbool, optional
  • If True, then reinvest profit to compute the performance.

  • Otherwise (default), compute the performance without reinvesting.

axis{0, 1}, optional

Axis along wich the computation is done. Default is 0.

dtypenp.dtype, optional

The type of the output array. If dtype is not given, infer the data type from X input.

Returns:
np.ndarray[dtype, ndim=1 or 2]

Performances along time axis.

See also

perf_returns, perf_index

Examples

>>> X = np.array([10., 12., 15., 14., 16., 18., 16.])
>>> S = np.array([1., 1., 1., 0., 1., 1., -1.])
>>> perf_strat(X, S, base=100.)
array([100., 120., 150., 150., 170., 190., 210.])
>>> perf_strat(X, S, base=100., reinvest=True)
array([100.        , 120.        , 150.        , 150.        ,
       171.42857143, 192.85714286, 214.28571429])