pandas-ta icon indicating copy to clipboard operation
pandas-ta copied to clipboard

Create Standard Deviation for Linear Regression

Open enilno opened this issue 1 year ago • 2 comments

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)

enilno avatar Nov 29 '23 12:11 enilno

@twopirllc please assign me this issue

mobley-trent avatar Feb 23 '24 04:02 mobley-trent

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.

twopirllc avatar Feb 23 '24 18:02 twopirllc