import statsmodels.api as sm
xdat = rets['EUROSTOXX']
xdat = sm.add_constant(xdat)
ydat = rets['VSTOXX']
model = sm.OLS(y=ydat,x=xdat).fit()
I don't understand why there is an error popping up as stated on the topic. The following is the tail of the Dataframe of rets
Out[105]:
EUROSTOXX VSTOXX
2014-12-23 0.011835 -0.039307
2014-12-24 -0.002449 0.000000
2014-12-29 0.000160 0.121598
2014-12-30 -0.015574 0.048998
2014-12-31 0.003336 0.000000
The Python "TypeError: __init__() missing 1 required positional argument" occurs when we forget to provide a required argument when instantiating a class. To solve the error, specify the argument when instantiating the class or set a default value for the argument.
Python classes need to be instantiated, or called, before you can access their methods. If you forget to instantiate an object of a class and try to access a class method, you encounter an error saying “missing 1 required positional argument: ‘self’”. In this guide, we talk about what this error means and why it is raised.
The “missing 1 required positional argument: ‘self’” error can occur when you incorrectly instantiate a class. Consider the following code: While this code is similar to our solution from the last example, it is incorrect. This is because we have not added any parenthesis after the word Hero.
missing 1 required positional argument: ‘self’ Positional arguments refer to data that is passed into a function. In a class, every function must be given the value “ self ”. The value of “self” is similar to “this” in JavaScript. “self” represents the data stored in an object of a class.
According to the documentation of OLS, the function's parameters aren't called y
and x
, but endog
and exog
. You can simply change your function call to:
model = sm.OLS(ydat, xdat).fit()
or:
model = sm.OLS(endog=ydat, exog=xdat).fit()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With