Multivariate linear regression of factor models
Many Python packages such as SciPy
come with several variants of regression functions. In particular, the statsmodels
package is a complement to SciPy
with descriptive statistics and estimation of statistical models. The official page for statsmodels
is http://statsmodels.sourceforge.net/.
In this example, we will use the ols
function of the statsmodels
module to perform an ordinary least squares regression and view its summary.
Let's assume that you have implemented an APT model with seven factors that return the values of Y. Consider the following set of data collected over 9 time periods, to . X1 to X7 are independent variables observed at each period. The regression problem is therefore structured as:.
A simple ordinary least squares regression on values of X and Y can be performed with the following code:
""" Least squares regression with statsmodels """ import numpy as np import statsmodels.api as sm ...