Computing time-weighted moving average

Adamski picture Adamski · Apr 14, 2012 · Viewed 9.2k times · Source

I have a time series of stock prices and wish to compute the moving average over a ten minute window (see diagram below). As price ticks occur sporadically (i.e. they are not periodic) it seems fairest to calculate a time-weighted moving average.

Time Series

In the diagram there are four price changes: A, B, C and D, with the latter three occurring inside the window. Note that because B only occurs some time into the window (say 3 minutes), the value of A still contributes to the computation.

In fact, as far as I can tell the computation should be solely based on the values of A, B and C (not D) and the durations between them and the next point (or in the case of A: the duration between the start of the time window and B). Initially D will not have any effect as its time weighting will be zero. Is this correct?

Assuming this is correct, my concern is that the moving average will "lag" more than the non-weighted computation (which would account for the value of D immediately), However, the non-weighted computation has its own disadvantages:

  • "A" would have as much effect on the result as the other prices despite being outside the time window.
  • A sudden flurry of fast price ticks would heavily bias the moving average (although perhaps this is desirable?)

Can anyone offer any advice over which approach seems best, or whether there's an alternative (or hybrid) approach worth considering?

Answer

Anonymous picture Anonymous · Apr 14, 2012

The two suggestions come from the discrete world, but you might find an inspiration for your particular case.

Have a look at exponential smoothing. In this approach you introduce the smoothing factor (α ∈ [0;1]) that allows you to alter the influence of the recent elements on the “forecast” value (older elements are assigned exponentially decreasing weights):

st=αxt-1+(1+α)st-1; s1=x0

I have created a simple animation of how the exponential smoothing would track the a uniform time series x=[1 1 1 1 3 3 2 2 2 1] with three different α={0.3, 0.6, 0.9}:

enter image description here

Have also a look at some of the reinforcement learning techniques (look at the different discounting methods) for example TD-learning and Q-Learning.