Perform calulations on moving window of data
6 次查看(过去 30 天)
显示 更早的评论
I have stock data (Open, High, Low, Close), i would like to perform a calculation on a moving window of data
for eg, the average price on 10 bars of data - Yes i know matlab has some function, i want to do my own function not available by matlab.
I've investigated the moving windows function in matlab below, but the problem is that it centres the moving average windows i don't want that.
I want it to take the last 10 data points.
so for eg. if i have a 20 bars of data, then bar 20 uses its last 10 data points, and bar 19 uses its last 10 data points and so on.
What is the function i want to apply?
I want to apply a linear regression model, but i need it to only use the last X (150) bars of data.
The current problem is when a new data point comes in, the complete linear regression model can change, because it uses all the data points, so this makes past historical data useles, because yesterday's model was based on a different data set, so thats why i want it to use the last X data bars, so the output is consistent, what we say yesterday will always be that value yesterday regardless of what new data comes out today.
https://au.mathworks.com/help/matlab/ref/matlab.tall.movingwindow.html
2 个评论
Scott MacKenzie
2021-6-27
I might help if you post an example data file. It seems you want a moving mean with a window size of 10 and you want to consider only the last 150 samples. Thus, you'd have 141 means (1-10, 2-11, 3-12, ... 141-150). Is this correct?
You've also tossed in something about a regression model. What are the (two) variables in the model?
回答(1 个)
Matt J
2021-6-28
编辑:Matt J
2021-6-28
but the problem is that it centres the moving average windows i don't want that.
The function you reference is not limited to centered windows. The same is true, for example of movmean, movmax, and other sliding window functions in that family, e.g.,
M = movmean(A,[-9 0])
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!