twopirllc / pandas-ta

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
https://twopirllc.github.io/pandas-ta/
MIT License
5.22k stars 1.02k forks source link

Create Standard Deviation for Linear Regression #741

Open enilno opened 9 months ago

enilno commented 9 months ago

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)

mobley-trent commented 6 months ago

@twopirllc please assign me this issue

twopirllc commented 6 months ago

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.