pandas-ta
pandas-ta copied to clipboard
Linreg does not return Slope, Forecast, Angle, or R coefficient
Which version are you running? 0.3.14b0 Do you have TA Lib also installed in your environment? No
The LINREG indicator returns the linreg indicator value but does not return other useful indicator values mentioned in the documentation - e.g. Slope, Forecast, Angle, or R coefficient which are calculated in the indicator code.
Sample code to reproduce:
import pandas as pd
import pandas_ta as ta
import yfinance as yf
print(f"PANDAS TA version = {ta.version}")
# Get symbol OHLC data
data = yf.download("CL=F")
# pandas_ta linreg doesn't appear to be returning all the values yet...
# this works
data['LINREG'] = data.ta.linreg(length=20, slope=True, degrees=True, r=True, tsf = True )
# this (below) doesn't work as dictionary key values are missing
# linreg = data.ta.linreg(length=20, slope=True, degrees=True, r=True, tsf = True )
# data['LINREG'] = linreg['LR_20']
# data['LINREG_SLOPE'] = linreg['LRm_20']
# data['LINREG_FORECAST'] = linreg['LR_20']
# data['LINREG_ANGLE'] = linreg['LRa_20']
# data['LINREG_R'] = linreg['LRr_20']
Expected: indicator values described in the documentation (and calculated in the indicator code) should be available
Hello @sdk451,
This library intends to provide similar functionality as TA Lib. As such, individual calls are currently required to return each Series. For more detail, here is PTAs development source.
import pandas as pd
import pandas_ta as ta
import yfinance as yf
print(f"PANDAS TA version = {ta.version}")
# Get symbol OHLC data
data = yf.download("CL=F")
# this works
n = 20
data.ta.linreg(length=n, append=True)
data.ta.linreg(length=n, slope=True, append=True)
# Angle in radians
data.ta.linreg(length=n, angle=True, append=True)
# Angle in degrees
data.ta.linreg(length=n, angle=True, degrees=True, append=True)
data.ta.linreg(length=n, r=True, append=True)
data.ta.linreg(length=n, intercept=True, append=True)
# Only works if TA Lib is installed as it calls TA Lib's TSF()
data.ta.linreg(length=n, tsf=True, append=True)
The Linear Regression indicator, like many others, is due for an update as well as be rewritten using numpy to speed it up. So an all like parameter to return each in one call will take a bit more time. Unfortunately there are too many things outstanding for one person to do. So hopefully someone can help by checking out the development branch and submit a PR to get this resolved sooner. 😎
Kind Regards, KJ
Thanks KJ!
I'll grab the values separately through repeat calls as suggested above. If I get bandwidth I'll look into making a PR/contribution to fix.