exp_sample_weightsΒΆ

Defined in fynance.models.training

exp_sample_weights(n, halflife)[source]

Exponential-decay sample weights (recent observations weighted more).

The most recent observation gets weight 1; weights halve every halflife observations into the past. Useful to down-weight stale data when training on a long history.

Parameters:
nint

Number of observations.

halflifefloat

Decay half-life in observations (must be > 0).

Returns:
np.ndarray

Weights of shape (n,), in (0, 1], increasing with index (oldest first, most recent last).

Examples

>>> exp_sample_weights(4, halflife=1)
array([0.125, 0.25 , 0.5  , 1.   ])