1 year ago

#91425

test-img

roudan

Parabolic SAR (PTPS) doesn't work in cufflink quantfig

I am using cufflink Quantfig for stock TA. The Parabolic SAR (PTPS) never works with error of TypeError: '<=' not supported between instances of 'float' and 'NoneType'.

Someone told me I need to comment out the line 286 in ta.py file and it solved one error but I got another error which is shown on the bottom code.

enter image description here

    qf = cf.QuantFig(df, title=f'TA Dashboard - {stock} using Indicator of {indicator}', 
                     legend='right', name=f'{stock}',
                     yTitle='Price')

    if 'PTPS' in indicator:  # Parabolic SAR (PTPS) 
        qf.add_ptps(periods=other_period, yTitle='Parabolic SAR (PTPS)')  #af=0.2,initial='long'

The error is shown below with TypeError: '<=' not supported between instances of 'float' and 'NoneType'.

~\miniconda3\envs\dash_project\lib\site-packages\cufflinks\ta.py in <listcomp>(.0=<list_iterator object>)
    373         periods=make_list(periods)
    374         output=['LONG','SHORT']
--> 375         __df=pd.concat([_ptps(df,periods=y,high=high,low=low,include=False,str=str,detail=detail) for y in periods],axis=1)
        global __df = undefined
        global pd.concat = <function concat at 0x0000025A5EB03AF0>
        global _ptps = undefined
        global df = undefined
        global periods = undefined
        y = 14
        global high = undefined
        global low = undefined
        global include = undefined
        global str = undefined
        global detail = undefined
        global axis = undefined
    376         if include:
    377                 return pd.concat([df,__df],axis=1)

~\miniconda3\envs\dash_project\lib\site-packages\cufflinks\ta.py in _ptps(
    df=                    Open          High          ...2022-01-24  39467405312  

[208 rows x 5 columns],
    periods=14,
    high='High',
    low='Low',
    include=False,
    str='{study} {name}({period})',
    detail=False
)
    291                         # LorS - Long or Short
    292                         if _df['LorS'][_-1]=='long':
--> 293                                 if _df['T_SAR'][_-1]>=df[low][_]:
        _df =           Date  SAR  LorS            EP EP+-SAR   AF AF_Diff T_SAR Reversal  \
0   2021-07-01  NaN  long  35035.984375     NaN  0.2     NaN  None      NaN   
1   2021-07-02  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
2   2021-07-03  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
3   2021-07-04  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
4   2021-07-05  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
..         ...  ...   ...           ...     ...  ...     ...   ...      ...   
203 2022-01-20  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
204 2022-01-21  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
205 2022-01-22  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
206 2022-01-23  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   
207 2022-01-24  NaN   NaN           NaN     NaN  NaN     NaN   NaN      NaN   

    LONG SHORT  
0    NaN   NaN  
1    NaN   NaN  
2    NaN   NaN  
3    NaN   NaN  
4    NaN   NaN  
..   ...   ...  
203  NaN   NaN  
204  NaN   NaN  
205  NaN   NaN  
206  NaN   NaN  
207  NaN   NaN  

[208 rows x 11 columns]
        _ = 1
        df =                     Open          High           Low         Close  \
Date                                                                 
2021-07-01  35035.984375  35035.984375  32883.781250  33572.117188   
2021-07-02  33549.601562  33939.589844  32770.679688  33897.046875   
2021-07-03  33854.421875  34909.261719  33402.695312  34668.546875   
2021-07-04  34665.566406  35937.566406  34396.476562  35287.781250   
2021-07-05  35284.343750  35284.343750  33213.660156  33746.003906   
...                  ...           ...           ...           ...   
2022-01-20  41744.027344  43413.023438  40672.824219  40680.417969   
2022-01-21  40699.605469  41060.527344  35791.425781  36457.316406   
2022-01-22  36471.589844  36688.812500  34349.250000  35030.250000   
2022-01-23  35047.359375  36433.312500  34784.968750  36276.804688   
2022-01-24  36163.117188  36319.960938  33227.503906  36074.687500   

                 Volume  
Date                     
2021-07-01  37838957079  
2021-07-02  38728974942  
2021-07-03  24383958643  
2021-07-04  24924307911  
2021-07-05  26721554282  
...                 ...  
2022-01-20  20382033940  
2022-01-21  43011992031  
2022-01-22  39714385405  
2022-01-23  26017975951  
2022-01-24  39467405312  

[208 rows x 5 columns]
        low = 'Low'
    294                                         _df.loc[_,'LorS']='short'
    295                                 else:

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

~\miniconda3\envs\dash_project\lib\site-packages\cufflinks\ta.py in <listcomp>(.0=<list_iterator object>)
    373         periods=make_list(periods)
    374         output=['LONG','SHORT']
--> 375         __df=pd.concat([_ptps(df,periods=y,high=high,low=low,include=False,str=str,detail=detail) for y in periods],axis=1)
        global __df = undefined
        global pd.concat = <function concat at 0x000001B46A9E0AF0>
        global _ptps = undefined
        global df = undefined
        global periods = undefined
        y = 14
        global high = undefined
        global low = undefined
        global include = undefined
        global str = undefined
        global detail = undefined
        global axis = undefined
    376         if include:
    377                 return pd.concat([df,__df],axis=1)

~\miniconda3\envs\dash_project\lib\site-packages\cufflinks\ta.py in _ptps(
    df=                  Open        High         Low  ...97  161.619995  161045259

[143 rows x 5 columns],
    periods=14,
    high='High',
    low='Low',
    include=False,
    str='{study} {name}({period})',
    detail=False
)
    367                 _df['LONG']=_df.apply(lambda x:x['T_SAR'] if x['LorS']=='long' else np.nan,axis=1)
    368                 _df['SHORT']=_df.apply(lambda x:x['T_SAR'] if x['LorS']=='short' else np.nan,axis=1)
--> 369                 _df=_df.set_index('index')
        _df =           Date         SAR   LorS          EP   EP+-SAR   AF   AF_Diff  \
0   2021-07-01         NaN   long  136.924719       NaN  0.2       NaN   
1   2021-07-02  135.359345   long  139.586842  4.227497  0.2  0.845499   
2   2021-07-06  135.359345   long  142.727531  7.368185  0.2  1.473637   
3   2021-07-07  136.832982   long  144.462404  7.629422  0.2  1.525884   
4   2021-07-08  138.358867   long  144.462404  6.103537  0.2  1.220707   
..         ...         ...    ...         ...       ...  ...       ...   
138 2022-01-18  175.961993  short  169.410004   6.55199  0.2  1.310398   
139 2022-01-19  174.651595  short  165.940002  8.711593  0.2  1.742319   
140 2022-01-20  172.909277  short  164.179993  8.729284  0.2  1.745857   
141 2022-01-21   171.16342  short  162.300003  8.863417  0.2  1.772683   
142 2022-01-24  169.390737  short  154.699997  14.69074  0.2  2.938148   

          T_SAR Reversal        LONG       SHORT  
0           NaN      NaN         NaN         NaN  
1    135.359345      NaN  135.359345         NaN  
2    136.832982      NaN  136.832982         NaN  
3    138.358867      NaN  138.358867         NaN  
4    139.579574      NaN  139.579574         NaN  
..          ...      ...         ...         ...  
138  174.651595      NaN         NaN  174.651595  
139  172.909277      NaN         NaN  172.909277  
140   171.16342      NaN         NaN  171.163420  
141  169.390737      NaN         NaN  169.390737  
142  166.452589      NaN         NaN  166.452589  

[143 rows x 11 columns]
        _df.set_index = <bound method DataFrame.set_index of           Date         SAR   LorS          EP   EP+-SAR   AF   AF_Diff  \
0   2021-07-01         NaN   long  136.924719       NaN  0.2       NaN   
1   2021-07-02  135.359345   long  139.586842  4.227497  0.2  0.845499   
2   2021-07-06  135.359345   long  142.727531  7.368185  0.2  1.473637   
3   2021-07-07  136.832982   long  144.462404  7.629422  0.2  1.525884   
4   2021-07-08  138.358867   long  144.462404  6.103537  0.2  1.220707   
..         ...         ...    ...         ...       ...  ...       ...   
138 2022-01-18  175.961993  short  169.410004   6.55199  0.2  1.310398   
139 2022-01-19  174.651595  short  165.940002  8.711593  0.2  1.742319   
140 2022-01-20  172.909277  short  164.179993  8.729284  0.2  1.745857   
141 2022-01-21   171.16342  short  162.300003  8.863417  0.2  1.772683   
142 2022-01-24  169.390737  short  154.699997  14.69074  0.2  2.938148   

          T_SAR Reversal        LONG       SHORT  
0           NaN      NaN         NaN         NaN  
1    135.359345      NaN  135.359345         NaN  
2    136.832982      NaN  136.832982         NaN  
3    138.358867      NaN  138.358867         NaN  
4    139.579574      NaN  139.579574         NaN  
..          ...      ...         ...         ...  
138  174.651595      NaN         NaN  174.651595  
139  172.909277      NaN         NaN  172.909277  
140   171.16342      NaN         NaN  171.163420  
141  169.390737      NaN         NaN  169.390737  
142  166.452589      NaN         NaN  166.452589  

[143 rows x 11 columns]>
    370 
    371                 return rename(df,_df,study,periods,'',include,str,detail,output=output)

~\miniconda3\envs\dash_project\lib\site-packages\pandas\util\_decorators.py in wrapper(
    *args=(          Date         SAR   LorS          EP   ...       NaN  166.452589  

[143 rows x 11 columns], 'index'),
    **kwargs={}
)
    309                     stacklevel=stacklevel,
    310                 )
--> 311             return func(*args, **kwargs)
        global func = undefined
        args = (          Date         SAR   LorS          EP   EP+-SAR   AF   AF_Diff  \
0   2021-07-01         NaN   long  136.924719       NaN  0.2       NaN   
1   2021-07-02  135.359345   long  139.586842  4.227497  0.2  0.845499   
2   2021-07-06  135.359345   long  142.727531  7.368185  0.2  1.473637   
3   2021-07-07  136.832982   long  144.462404  7.629422  0.2  1.525884   
4   2021-07-08  138.358867   long  144.462404  6.103537  0.2  1.220707   
..         ...         ...    ...         ...       ...  ...       ...   
138 2022-01-18  175.961993  short  169.410004   6.55199  0.2  1.310398   
139 2022-01-19  174.651595  short  165.940002  8.711593  0.2  1.742319   
140 2022-01-20  172.909277  short  164.179993  8.729284  0.2  1.745857   
141 2022-01-21   171.16342  short  162.300003  8.863417  0.2  1.772683   
142 2022-01-24  169.390737  short  154.699997  14.69074  0.2  2.938148   

          T_SAR Reversal        LONG       SHORT  
0           NaN      NaN         NaN         NaN  
1    135.359345      NaN  135.359345         NaN  
2    136.832982      NaN  136.832982         NaN  
3    138.358867      NaN  138.358867         NaN  
4    139.579574      NaN  139.579574         NaN  
..          ...      ...         ...         ...  
138  174.651595      NaN         NaN  174.651595  
139  172.909277      NaN         NaN  172.909277  
140   171.16342      NaN         NaN  171.163420  
141  169.390737      NaN         NaN  169.390737  
142  166.452589      NaN         NaN  166.452589  

[143 rows x 11 columns], 'index')
        kwargs = {}
    312 
    313         return wrapper

~\miniconda3\envs\dash_project\lib\site-packages\pandas\core\frame.py in set_index(
    self=          Date         SAR   LorS          EP   ...       NaN  166.452589  

[143 rows x 11 columns],
    keys=['index'],
    drop=True,
    append=False,
    inplace=False,
    verify_integrity=False
)
   5449 
   5450         if missing:
-> 5451             raise KeyError(f"None of {missing} are in the columns")
        global KeyError = undefined
   5452 
   5453         if inplace:

KeyError: "None of ['index'] are in the columns"

python

cufflinks

0 Answers

Your Answer

Accepted video resources