Reputation: 15
I am running the linear regression function on a time series data of two stocks using statsmodels. While printing out the results using "summary", my code works fine. However I want to print only the beta(coef) of the two stocks. I tried using "params" instead of "summary" in the lines, but I keep getting the error message:
"TypeError: 'numpy.ndarray' object is not callable"
I understand this is a very basic mistake, but i'm very new to coding. Any advice would be appreciated.
Below is my code:
import pandas as pd
import statsmodels.api as sm
from scipy.stats.mstats import zscore
df = pd.read_excel('C:\\Users\Sai\Desktop\DF.xlsx')
x = df[['Stock A']]
y = df[['Stock B']]
model = sm.OLS(zscore(x), zscore(y))
results = model.fit()
print(results.params())
This is the error message I keep getting:
"C:\Program Files\Python35-32\python.exe" C:/Users/Sai/Desktop/Quantstart.py
Traceback (most recent call last):
File "C:/Users/Sai/Desktop/Quantstart.py", line 13, in <module>
print(results.params())
TypeError: 'numpy.ndarray' object is not callable
Upvotes: 0
Views: 5107
Reputation: 190
Use the below code
results.params
instead of
results.params()
and it will work properly.
Upvotes: 2