Split a seasonal series into trend, seasonal and residual parts with classical decomposition, in its additive and multiplicative forms.
Implement classical_decompose(y, period, model="additive").
Inputs. y: 1-D array of length period. period: season length . model: "additive" () or "multiplicative" (, all ).
Trend. A centered moving average with half-width :
is defined for and is None elsewhere.
Seasonal. Detrend where exists: (additive) or (multiplicative). For each position , average over the with . Normalize these indices so they sum to 0 (additive: subtract their mean) or average to 1 (multiplicative: divide by their mean). Then is the index of position , defined for every .
Residual. or , None where is None.
Output. A dict {"trend": [...], "seasonal": [...], "resid": [...]} of length- lists, numbers rounded to 4 decimals. Any other model raises ValueError.