ZMA — a new moving average

DrTrend
1 min readJul 3, 2023

--

Moving averages are designed to remove noise and enhance signal. Commonly used moving averages are simple moving average (SMA) and exponential moving averages(EMA). They are easy to calculate, and available in popular technical analysis packages, such as, pandas-ta.

In this note, I introduce you another moving average, ZMA, I developed when I worked on time series data a decade ago.

In SMA, the moving average is a sum of the last n data, y1+y2+y3+…yn, divided by n. In ZMA, we first calculate a cumsum() of the n data, z1=y1, z2=y1+y2, z3=y1+y2+y3,…zn=y1+y2+…yn. Then we do linear regression of the cumsum series z against x=1,2,…n, z~ ax +b.

ZMA(y)= a = correl(x,z)*sigma(z)/sigma(x)

where correl(x,z) is the correlation between the series of x and z in the time window n and sigma are the standard deviations.

ZMA is smoother than SMA due to the integration (cumsum) and then differentiation (slope), which is important for point of change detections. In other words, it generates fewer false signals in technical analysis for trading.

Here is a python function for ZMA. Let me know your feedback.

   def zma(y):
z= y.cumsum()
x = np.arange(len(y))
return np.corrcoef(x, z)[0,1]*np.std(z)/np.std(x)

Disclaimer: I am not a certified investment advisor, this is not a financial advice; it is purely for entertainment and educational purpose.

--

--

DrTrend

Quantitative analyst in commodities, derivatives pricing and trading strategies