Why don't we add the constant along x while doing regression to calculate beta function

Course Name: Volatility Trading Strategies for Beginners, Section No: 22, Unit No: 1, Unit type: Notebook

I tried both methods in same course - Section 19, unit 13 :slight_smile:
Calculating Beta for the Tesla stock :

If I add constant to regression equation and then calculate the beta it comes out to be 1.973 and without constant it comes out to be 1.982 - It is not way off but it could be significantly different.

Original Function :

def calc_beta(y, x):
model = sm.OLS(y, x)
results = model.fit()
return results.params[0]

If we need to make that change in code for Section No. 22, unit no. 1 or ( section 21 codes ) for function that is calculating beta as follows : how do we use it along with apply function :

My modified function :

def calc_beta(y, x):
x = sm.add_constant(x)
model = sm.OLS(y, x)
results = model.fit()
return results.params[1]

Which one is more accurate ?

You will have to return both results.params[1] and results.params[0] for using both slope and intercept. Technically we say that when market returns are 0, the asset return will be 0, so there will be no intercept, but this is an assumption.
I hope this helps.