santosjorge / cufflinks

Productivity Tools for Plotly + Pandas
MIT License
3.02k stars 675 forks source link

error on QuantFig.add_ptps #244

Open TsaiJinhang opened 4 years ago

TsaiJinhang commented 4 years ago

this is the code:

import cufflinks as cf
cf.set_config_file(offline=True, world_readable=True)
df=cf.datagen.ohlcv()
qf=cf.QuantFig(df,legend='top',name='QF')
qf.add_ptps()
qf.iplot()

the error:

D:\Anaconda\lib\site-packages\cufflinks\ta.py in _ptps(df, periods, high, low, include, str, detail)
    291                         # LorS - Long or Short
    292                         if _df['LorS'][_-1]=='long':
--> 293                                 if _df['T_SAR'][_-1]>=df[low][_]:
    294                                         _df.loc[_,'LorS']='short'
    295                                 else:

TypeError: '<=' not supported between instances of 'float' and 'NoneType'

My solution: delete _df.loc[0,'T_SAR']=None (in line 286 of ta.py)

vijay-r commented 3 years ago

Hi Team, getting same error

Traceback (most recent call last):
  File "/Users/vkumaraguruparan/Projects/algo/SwingTrade/p_ta/offline.py", line 46, in <module>
    qf.iplot(asFigure=True), 
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/quant_figure.py", line 1235, in iplot
    study_fig=self._get_study_figure(k,**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/quant_figure.py", line 1073, in _get_study_figure
    fig=df.ta_figure(study=kind,**params)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/plotlytools.py", line 1485, in _ta_figure
    return self.ta_plot(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/plotlytools.py", line 1631, in _ta_plot
    figure=get_study(self,ta_func,iplot_kwargs,iplot_study_kwargs,include=include,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/plotlytools.py", line 1606, in get_study
    df_ta=func(df,column=column,include=False,str=str,**study_kwargs)   
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/ta.py", line 375, in ptps
    __df=pd.concat([_ptps(df,periods=y,high=high,low=low,include=False,str=str,detail=detail) for y in periods],axis=1)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/ta.py", line 375, in <listcomp>
    __df=pd.concat([_ptps(df,periods=y,high=high,low=low,include=False,str=str,detail=detail) for y in periods],axis=1)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cufflinks/ta.py", line 293, in _ptps
    if _df['T_SAR'][_-1]>=df[low][_]:
TypeError: '<=' not supported between instances of 'float' and 'NoneType'
geraldbl commented 3 years ago

Getting the same error, but commenting the line 293 does not solve the underlying problem. just postpone it. After, it triggers the following: File "C:\Users\geral\repos\TradingPatterns\venv\lib\site-packages\cufflinks\ta.py", line 376, in ptps __df=pd.concat([_ptps(df,periods=y,high=high,low=low,include=False,str=str,detail=detail) for y in periods],axis=1) File "C:\Users\geral\repos\TradingPatterns\venv\lib\site-packages\cufflinks\ta.py", line 376, in __df=pd.concat([_ptps(df,periods=y,high=high,low=low,include=False,str=str,detail=detail) for y in periods],axis=1) File "C:\Users\geral\repos\TradingPatterns\venv\lib\site-packages\cufflinks\ta.py", line 370, in _ptps _df=_df.set_index('index') File "C:\Users\geral\repos\TradingPatterns\venv\lib\site-packages\pandas\core\frame.py", line 4727, in set_index raise KeyError(f"None of {missing} are in the columns") KeyError: "None of ['index'] are in the columns"

dschrempf commented 2 years ago

I can confirm this error.