returns_strat

Defined in fynance.metrics

returns_strat(X, S=None, kind='pct', base=100., axis=0, dtype=None)[source]

Compute the returns 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.

kind{‘raw’, ‘pct’}
  • If ‘raw’, then considers returns as following \(R_t = X_t - X_{t-1}\).

  • If ‘pct’ (default), then considers returns as following \(R_t = \frac{X_t - X_{t-1}}{X_{t-1}}\).

basefloat, optional

Initial value for measure the returns, default is 100. Relevant only if kind='raw'.

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]

Returns 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.])
>>> returns_strat(X, S, base=10., kind='raw')
array([ 0.,  2.,  3., -0.,  2.,  2.,  2.])
>>> returns_strat(X, S)
array([ 0.        ,  0.2       ,  0.25      , -0.        ,  0.14285714,
        0.125     ,  0.11111111])