Introduction to statsmodels
statsmodels
is a powerful Python package for many types of statistical analysis. Again, if Python was installed via Anaconda, then the module was installed at the same time. In statistics, ordinary least square (OLS) regression is a method for estimating the unknown parameters in a linear regression model. It minimizes the sum of squared vertical distances between the observed values and the values predicted by the linear approximation. The OLS method is used extensively in finance. Assume that we have the following equation, where y is an n by 1 vector (array), and x is an n by (m+1) matrix, a return matrix (n by m), plus a vector that contains 1 only. n is the number of observations, and m is the number of independent variables:
In the following program, after generating the x
and y
vectors, we run an OLS regression (a linear regression). The x
and y
are artificial data. The last line prints the parameters only (the intercept is 1.28571420
and the slope is...