How to perform different RUNNING calculations on a financial Timetable.

1 view (last 30 days)
I have Stock data that I put in a Timetable. Several built in functions exists to perform calculations row by row for a SPECIFIC subset of data ex: tsmovavg (output = tsmovavg(tsobj,'e',timeperiod)) where timeperiod ex: 3 perform the calculation on the last 3 records. But, since those builtin functions are limited, I want to use other functions that could behave identically. For example, create a new variable that, for each row, would calculate the slope for the last 3 rows: coefficients = polyfit(A, B, 1); slope = coefficients(1)
Also, the trend based on the same 3 periods: mdl = fitlm(A,B,'linear'); Xnew = A; ypred = predict(mdl,Xnew);
Note that do not want to emphasize on the functions themselves but the ability to run through each row and perform a calculation base on n rows before and put the result in a new variable in my timetable, so at the end I'd have, for example, the slope at each rows BASED on the last 3 rows.
I'd like to use Matlab's power to not using loop and therefore reduce the numbers of code lines.
I reviewed a lot of possibilities, but none seems obvious but I'm shure there's a simpler way. Thanks all.

Answers (0)

Categories

Find more on Timetables 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!