Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving average for time series with not-equal intervls

I have a dataset for price of the ticker on the stock exchange: time - price. But intervals between data points are not equal - from 1 to 2 minutes.

What is the best practice to calculate moving average for such case? How to make it in Matlab?

I tend to think, that weights of the points should depend on the time interval that was last since previous point. Does we have function in Matlab to calculate moving average with custom weights of the points?

like image 938
Victor Mezrin Avatar asked Feb 13 '23 09:02

Victor Mezrin


1 Answers

Here is an example of the "naive" approach I mentioned in the comments above:

% some data (unequally spaced in time, but monotonically non-decreasing)
t = sort(rand(50,1));
x = cumsum(rand(size(t))-0.5);

% linear interpolatation on equally-spaced intervals
tt = linspace(min(t), max(t), numel(t));
xx = interp1(t, x, tt, 'linear');

% plot two data vectors
plot(t, x, 'b.-', tt, xx, 'r.:')
legend({'original', 'equally-spaced'})

interpolated_data_plot

like image 190
Amro Avatar answered Feb 15 '23 09:02

Amro