ema_smooth

Defined in fynance.signal

ema_smooth(pred, alpha=0.2)[source]

Causally smooth a position with an exponential moving average.

out[t] = alpha * pred[t] + (1 - alpha) * out[t-1] — a low alpha reacts slowly, cutting turnover by damping minute-to-minute flips. Anti-churn.

Parameters:
predarray-like, shape (T,)

Raw position / prediction series.

alphafloat

Smoothing factor in (0, 1] (1 = no smoothing).

Examples

>>> import numpy as np
>>> ema_smooth(np.array([0.0, 1.0, 1.0, -1.0]), alpha=0.5)
array([ 0.   ,  0.5  ,  0.75 , -0.125])