How to do a moving regression

5 Ansichten (letzte 30 Tage)
Charles Anthony  Grech
Charles Anthony Grech am 29 Mai 2016
Beantwortet: Star Strider am 30 Mai 2016
I have a set of returns which I want to regress in a loop, rolling window loop that will regress the first 12 returns against a variable called inn_liq.
I want to be able to generate several betas, b(i), the first beta regresses the first twelve observations, the second beta regresses twelve observations from the first to the thirteenth observations and so forth. The third beta regresses from the second till the fourteenth observations.
For each beta, I would like to plot the 95% confidence intervals of each beta, together with the beta, in order to determine if each beta is statistically different from zero.
Kindly help me in solving my problem.

Antworten (2)

Image Analyst
Image Analyst am 30 Mai 2016
I don't know what you mean by you want to "generate several betas", but to filter a signal with a moving window by fitting/regressing the data in the window to a polynomial, you use a Savitzky-Golay filter, done by sgolayfilt() in the Signal Processing Toolbox. You can specify both the window width and the order of the polynomial that you want to use to do the regression. I attach a demo.

Star Strider
Star Strider am 30 Mai 2016
If I understand correctly what you want to do, and your ‘betas’ are the slopes of the individual segments, you will probably have to do this with a loop using polyfit and a 2-degree polynomial, then use the the File Exchange polyparci function to calculate the confidence intervals.

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by