pandas-ta: Pandas TA strategy method goes into infinite loop: Windows Freeze Support Error

@twopirllc I was trying to run the below code on a dataframe

df.ta.strategy("Momentum")
print(df)

It goes into infinite loop and consumes all CPU on my windows 10 laptop. Then I need to kill all VSCodium and python exes. Could you please help?

_Originally posted by @rahulmr in https://github.com/twopirllc/pandas-ta/issues/138#issuecomment-751864255_

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (6 by maintainers)

Most upvoted comments

You can close this issue if you do not want to investigate further, as I have got the solution which is as below: source code


import yfinance as yf
import pandas_ta as ta


def test():
    sbin = yf.Ticker("SBIN.NS")
    df = sbin.history(period="3d", interval="15m")
    df.ta.strategy("Momentum", verbose=True)
    print(df)

if __name__ == '__main__':
    test()

pwsh.exe console output

(venv) PS D:\trading\0sas_algo> cat .\crash.py
import yfinance as yf
import pandas_ta as ta


def test():
    sbin = yf.Ticker("SBIN.NS")
    df = sbin.history(period="3d", interval="15m")
    df.ta.strategy("Momentum", verbose=True)
    print(df)

if __name__ == '__main__':
    test()
(venv) PS D:\trading\0sas_algo> python .\crash.py
[+] Strategy: Momentum
[i] Indicator arguments: {'append': True}
[i] Excluded[10]: above, above_value, below, below_value, cross, cross_value, long_run, short_run, trend_return, vp
[i] Multiprocessing: 8 of 8 cores.
[i] Total indicators: 34
[i] Columns added: 55
                                 open        high         low       close   volume  Dividends  ...  STOCHd_14_3_3  STOCHRSIk_14_14_3_3  STOCHRSId_14_14_3_3  TRIX_30_9  TRIXs_30_9  TSI_13_25
datetime                                                                                       ...
2020-12-24 09:15:00+05:30  265.100006  266.549988  264.700012  266.299988  1653388          0  ...            NaN                  NaN                  NaN        NaN         NaN        NaN
2020-12-24 09:30:00+05:30  266.299988  266.649994  265.500000  266.299988  1346556          0  ...            NaN                  NaN                  NaN        NaN         NaN        NaN
2020-12-24 09:45:00+05:30  266.299988  266.450012  265.500000  266.100006   914542          0  ...            NaN                  NaN                  NaN        NaN         NaN        NaN
2020-12-24 10:00:00+05:30  266.100006  267.649994  266.100006  267.399994  1594715          0  ...            NaN                  NaN                  NaN        NaN         NaN        NaN
2020-12-24 10:15:00+05:30  267.299988  267.799988  266.649994  266.799988  1050138          0  ...            NaN                  NaN                  NaN        NaN         NaN        NaN
...                               ...         ...         ...         ...      ...        ...  ...            ...                  ...                  ...        ...         ...        ...
2020-12-29 14:15:00+05:30  278.000000  278.350006  277.049988  277.399994  1333187          0  ...      69.749927            62.894709            57.654916   1.585756    2.020604  27.573298
2020-12-29 14:30:00+05:30  277.500000  277.899994  276.500000  277.750000  1194604          0  ...      69.690995            54.537582            59.388621   1.498974    1.906078  26.838714
2020-12-29 14:45:00+05:30  277.649994  277.850006  276.850006  276.950012   841302          0  ...      65.919476            29.097088            48.843126   1.417326    1.798951  24.185578
2020-12-29 15:00:00+05:30  277.000000  278.399994  277.000000  277.950012  2298641          0  ...      63.675802            33.053394            38.896021   1.340583    1.698658  23.613085
2020-12-29 15:15:00+05:30  277.950012  278.450012  277.250000  277.750000  2537262          0  ...      62.222375            26.968237            29.706239   1.268367    1.604655  22.658487

[75 rows x 62 columns]
(venv) PS D:\trading\0sas_algo>

Again tried with python 3.9.1 and still getting same issue. Control + C is also not working. Anyways this is not high priority for me. I will concentrate more on the other stuff. Will continue there. Let me know if you are able to reproduce this issue at your end. I can try to uploaded a video if I get time.

Thank you for these posts, and especially thank you for your workaround @rahulmr !!

@rahulmr,

Excellent deductive work on figuring out the Issue. I have seen that wrapping it in __main__ before could solve the Issue. Glad that it works though!

Regards, KJ

Great it is working on my docker container Details here:

root@node54310-pandas-r:~/sas# cat sbin.py
import yfinance as yf
import pandas_ta as ta


sbin = yf.Ticker("SBIN.NS")
df = sbin.history(period="3d", interval="15m")
df.ta.strategy("Momentum", verbose=True)
print(df)

root@node54310-pandas-r:~/sas# python sbin.py
[+] Strategy: Momentum
[i] Indicator arguments: {'append': True}
[i] Excluded[10]: above, above_value, below, below_value, cross, cross_value, long_run, short_run, trend_return, vp
[i] Multiprocessing: 3 of 3 cores.
[i] Total indicators: 34
[i] Columns added: 55
                                 open        high         low       close   volume  Dividends  Stock Splits  ...  SQZ_ON  SQZ_OFF  SQZ_NO  STOCHk_14_3_3  STOCHd_14_3_3  STOCHRSIk_14_14_3_3  STOCHRSId_14_14_3_3
datetime                                                                                                     ...                                                                                              
2020-12-24 09:15:00+05:30  265.100006  266.549988  264.700012  266.299988  1653388          0             0  ...       0        0       1            NaN            NaN                  NaN                  NaN
2020-12-24 09:30:00+05:30  266.299988  266.649994  265.500000  266.299988  1346556          0             0  ...       0        0       1            NaN            NaN                  NaN                  NaN
2020-12-24 09:45:00+05:30  266.299988  266.450012  265.500000  266.100006   914542          0             0  ...       0        0       1            NaN            NaN                  NaN                  NaN
2020-12-24 10:00:00+05:30  266.100006  267.649994  266.100006  267.399994  1594715          0             0  ...       0        0       1            NaN            NaN                  NaN                  NaN
2020-12-24 10:15:00+05:30  267.299988  267.799988  266.649994  266.799988  1050138          0             0  ...       0        0       1            NaN            NaN                  NaN                  NaN
...                               ...         ...         ...         ...      ...        ...           ...  ...     ...      ...     ...            ...            ...                  ...                  ...
2020-12-29 14:15:00+05:30  278.000000  278.350006  277.049988  277.399994  1333187          0             0  ...       0        1       0      70.481224      69.749927            62.894709            57.654916
2020-12-29 14:30:00+05:30  277.500000  277.899994  276.500000  277.750000  1194604          0             0  ...       1        0       0      68.110486      69.690995            54.537582            59.388621
2020-12-29 14:45:00+05:30  277.649994  277.850006  276.850006  276.950012   841302          0             0  ...       1        0       0      59.166718      65.919476            29.097088            48.843126
2020-12-29 15:00:00+05:30  277.000000  278.399994  277.000000  277.950012  2298641          0             0  ...       1        0       0      63.750203      63.675802            33.053394            38.896021
2020-12-29 15:15:00+05:30  277.950012  278.450012  277.250000  277.750000  2537262          0             0  ...       1        0       0      63.750203      62.222375            26.968237            29.706239

[75 rows x 62 columns]
root@node54310-pandas-r:~/sas#

Let me try it on Linux container. And then I will add the updates.

This is great - some kind of tricky issue for me.

It is working from python prompt.

>>> sbin = yf.Ticker("SBIN.NS")
>>> df = sbin.history(period="3d", interval="15m")
>>> df.ta.strategy("Momentum")
>>> print(df)
                                 open        high         low       close   volume  Dividends  Stock Splits  ...  FISHERTs_9_1  INERTIA_20_14      K_9_3      D_9_3      J_9_3  KST_10_15_20_30_10_10_10_15       KSTs_9
datetime                                                                                                     ...
2020-12-24 09:15:00+05:30  265.100006  266.549988  264.700012  266.299988  1653388          0             0  ...           NaN            NaN        NaN        NaN        NaN                          NaN          NaN
2020-12-24 09:30:00+05:30  266.299988  266.649994  265.500000  266.299988  1346556          0             0  ...           NaN            NaN        NaN        NaN        NaN                          NaN          NaN
2020-12-24 09:45:00+05:30  266.299988  266.450012  265.500000  266.100006   914542          0             0  ...           NaN            NaN        NaN        NaN        NaN                          NaN          NaN
2020-12-24 10:00:00+05:30  266.100006  267.649994  266.100006  267.399994  1594715          0             0  ...           NaN            NaN        NaN        NaN        NaN                          NaN          NaN
2020-12-24 10:15:00+05:30  267.299988  267.799988  266.649994  266.799988  1050138          0             0  ...           NaN            NaN        NaN        NaN        NaN                          NaN          NaN
...                               ...         ...         ...         ...      ...        ...           ...  ...           ...            ...        ...        ...        ...                          ...          ...
2020-12-29 14:15:00+05:30  278.000000  278.350006  277.049988  277.399994  1333187          0             0  ...      0.900915      36.517981  66.863205  64.981378  70.626858                  1306.427229  1751.919538
2020-12-29 14:30:00+05:30  277.500000  277.899994  276.500000  277.750000  1194604          0             0  ...      0.996842      38.154401  67.492137  65.818298  70.839814                  1252.954426  1640.715420
2020-12-29 14:45:00+05:30  277.649994  277.850006  276.850006  276.950012   841302          0             0  ...      0.887071      37.971401  57.302575  62.979723  45.948279                  1186.942713  1539.359095
2020-12-29 15:00:00+05:30  277.000000  278.399994  277.000000  277.950012  2298641          0             0  ...      0.700636      39.792620  59.254517  61.737988  54.287576                  1154.360291  1451.367812
2020-12-29 15:15:00+05:30  277.950012  278.450012  277.250000  277.750000  2537262          0             0  ...      0.442987      41.414788  56.169678  59.881885  48.745265                  1095.710145  1367.014473

[75 rows x 62 columns]

>>> ", ".join(df.columns)
'open, high, low, close, volume, Dividends, Stock Splits, UO_7_14_28, WILLR_14, MACD_12_26_9, MACDh_12_26_9, MACDs_12_26_9, MOM_10, PGO_14, PPO_12_26_9, PPOh_12_26_9, PPOs_12_26_9, PSL_12, PVO_12_26_9, PVOh_12_26_9, PVOs_12_26_9, ROC_10, RSI_14, RVGI_14_4, RVGIs_14_4, SLOPE_1, SMI_5_20_5, SMIs_5_20_5, SMIo_5_20_5, SQZ_20_2.0_20_1.5, SQZ_ON, SQZ_OFF, SQZ_NO, STOCHk_14_3_3, STOCHd_14_3_3, STOCHRSIk_14_14_3_3, STOCHRSId_14_14_3_3, TRIX_30_9, TRIXs_30_9, TSI_13_25, AO_5_34, APO_12_26, BIAS_SMA_26, BOP, AR_26, BR_26, CCI_14_0.015, CFO_9, CG_10, CMO_14, COPC_11_14_10, ER_10, BULLP_13, BEARP_13, FISHERT_9_1, FISHERTs_9_1, INERTIA_20_14, K_9_3, D_9_3, J_9_3, KST_10_15_20_30_10_10_10_15, KSTs_9'
>>>

Also, what about the other code on the previous Issue? Or is that code not relevant?

No it is not relevant here. That issue is actually not an issue but help I need on how to work with pandas_ta. We will discuss it there.