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.
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:
Can anyone offer any advice over which approach seems best, or whether there's an alternative (or hybrid) approach worth considering?
A time-weighted average is equal to the sum of the portion of each time period (as a decimal, such as 0.25 hour) multiplied by the levels of the substance or agent during the time period divided by the hours in the workday (usually 8 hours).
A Weighted moving average (WMA) attaches greater weight to the most recent data. The weighting is calculated from the sum of days. Weighted values are calculated by multiplying today's price by 5/15, yesterday by 4/15, and so on. The weighted moving average is the sum of the 5 weighted values.
A moving average is a technical indicator that investors and traders use to determine the trend direction of securities. It is calculated by adding up all the data points during a specific period and dividing the sum by the number of time periods.
To find a weighted average, multiply each number by its weight, then add the results. If the weights don't add up to one, find the sum of all the variables multiplied by their weight, then divide by the sum of the weights.
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}:
Have also a look at some of the reinforcement learning techniques (look at the different discounting methods) for example TD-learning and Q-Learning.
In expanding Tom's answer, the formula for taking into consideration the spacing between ticks can be formalized (close ticks have proportionately lower weighting):
eman = u * eman-1 + (v - u) * xn-1 + (1 - v) * xn
where:
a = ( tn - tn-1) / T
that is, a is a ratio of delta of arrival time over averaging interval
and
u = e-a
and
v = 1 (use previous point), or
v = (1 - u) / a (linear interpolation>, or
v = u (next point)
Further information is found on page 59 of the book An Introduction To High Frequency Finance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With