gs_quant.timeseries.statistics.RollingLinearRegression¶
- class RollingLinearRegression(X, y, w, fit_intercept=True)[source]¶
Fit a rolling ordinary least squares (OLS) linear regression model.
- Parameters:
X (
Union
[Series
,List
[Series
]]) – observations of the explanatory variable(s)y (
Series
) – observations of the dependant variablew (
int
) – number of observations in each rolling window. Must be larger than the number of observations or explanatory variablesfit_intercept (
bool
) – whether to calculate intercept in the model
Usage
Fit OLS Model based on observations of the explanatory variables(s) X and the dependant variable y across a rolling window with fixed number of observations. The parameters of each rolling window are stored at the end of each window. If X and y are not aligned, only use the intersection of dates/times.
Examples
Run linear regressions on y vs. x1 and x2 in a rolling window of 22 observations and compute the R Squared:
>>> x1 = generate_series(100) >>> x2 = generate_series(100) >>> y = generate_series(100) >>> r = RollingLinearRegression([x1, x2], y, 22) >>> r.r_squared()
Methods
coefficient
(i)Estimated coefficients.
fitted_values
()Fitted values at the end of each rolling window.
r_squared
()Coefficients of determination (R Squared) of rolling regressions.
standard_deviation_of_errors
()Standard deviations of the error terms.