Perform calulations on moving window of data
6 views (last 30 days)
Show older comments
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 Comments
Scott MacKenzie
on 27 Jun 2021
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?
Answers (1)
Matt J
on 28 Jun 2021
Edited: Matt J
on 28 Jun 2021
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])
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!