pandas-ta
pandas-ta copied to clipboard
Create Standard Deviation for Linear Regression
I needed to have standard deviation for linear regression and there was not function for it. so i coded it and if you like you can edit it and add to next version.
def stdevlinreg(close, length: int):
x_value = close
stdev = close
slope = ta.linreg(close=close, length=length, slope=True)
tsf = ta.linreg(close=close, length=length, tsf=True)
variance = 0
for i in range(1, length):
variance += (x_value.shift(i) - (tsf - i * slope)) ** 2
stdev = (variance / (length - 1)) ** 0.5
return stdev
so we can now use it as:
df['stdlinreg'] = stdevlinreg(df['close'], length=15)
and if add to 'linreg' it can be like:
df['stdlinreg'] = ta.linreg(df['close'], length=15, stdev=True)
@twopirllc please assign me this issue
Hello @mobley-trent,
Assignment unnecessary, contributions are always welcome. 😎 Checkout the development branch. Edit and submit a PR and I'll get to it as soon as I can.