How to do a moving regression

조회 수: 6 (최근 30일)
Charles Anthony  Grech
Charles Anthony Grech 2016년 5월 29일
답변: Star Strider 2016년 5월 30일
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.

답변 (2개)

Image Analyst
Image Analyst 2016년 5월 30일
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 2016년 5월 30일
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.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by