BennyThadikaran / stock-pattern

A python scanner to detect and plot common chart patterns
GNU General Public License v3.0
128 stars 26 forks source link

Dataframe series truth value error #28

Closed Prady04 closed 3 months ago

Prady04 commented 4 months ago

steps: clone repository install pre-requisites configure datapath symlist:nse500.csv (attached)

select all patterns and run Scanning ALL patterns. Press Ctrl - C to exit 68%|█████████████████████████████████▌ | 342/500 [00:06<00:02, 54.75it/s] Uncaught Exception concurrent.futures.process._RemoteTraceback: """ Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\process.py", line 263, in _process_worker r = call_item.fn(*call_item.args, *call_item.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Pattern_Clone\stock-pattern\src\init.py", line 87, in scan_pattern
result = fn(sym, df, pivots) ^^^^^^^^^^^^^^^^^^^ File "D:\python\Pattern_Clone\stock-pattern\src\utils.py", line 906, in find_double_top if is_double_top(a, b, c, d, aVol, cVol, avgBarLength, atr): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python\Pattern_Clone\stock-pattern\src\utils.py", line 354, in is_double_top
c - b < atr
4 File "D:\python\Pattern_Clone\stock-pattern\venv\Lib\site-packages\pandas\core\generic.py", line 1577, in nonzero raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). """

File "D:\python\Pattern_Clone\stock-pattern\src\init.py", line 436, in patterns = process(data, fns) ^^^^^^^^^^^^^^^^^^ File "D:\python\Pattern_Clone\stock-pattern\src\init.py", line 143, in process result = future.result() ^^^^^^^^^^^^^^^ n500.csv

BennyThadikaran commented 4 months ago

Your setup is fine.

The error was caused by series being passed to the is_double_top function. Could be duplicate index in the DataFrame. I suspect this is the ATR value passed. Since everything else has been checked to make sure its a valid number and not a series.

Screenshot from 2024-05-17 21-35-36

I have a copy of Nifty 500 stocks but couldnt reproduce the error with todays updated data. I will try with your list and let you know.

I am just releasing a major update to Stock-Patterns. The documentation is pending. So i will add a check for the ATR and club it with the update. Most likely tomorrow.

BennyThadikaran commented 4 months ago

I have added a possible fix for this issue. Below is a code illustrating the problem.

import pandas as pd

d = {"col1": [1, 2, 2, 4], "col2": [3, 4, 4, 6]}

# Duplicate index 2 added on purpose
df = pd.DataFrame(d, index=pd.Series([1, 2, 2, 3]))

a = df["col1"].at[2] # results in a pandas Series
print("Before", a)

# Fix
if isinstance(a, pd.Series):
    a = a.iloc[0] # get the first value in the Series
    print("After", a)

Once i post the update, you can give it a run and check if the issue is resolved.

BennyThadikaran commented 4 months ago

Try updating the repo and give it a run. Let me know if you still face the same issue.

Prady04 commented 4 months ago

Did that. Same result.

regards, Pradeep

On Sat, May 18, 2024, 22:12 Benny Thadikaran @.***> wrote:

Try updating the repo and give it a run. Let me know if you still face the same issue.

— Reply to this email directly, view it on GitHub https://github.com/BennyThadikaran/stock-pattern/issues/28#issuecomment-2118876369, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ7FKRR4QC74ARBYJFEDHMDZC6AGLAVCNFSM6AAAAABH4EIAWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJYHA3TMMZWHE . You are receiving this because you authored the thread.Message ID: @.***>

BennyThadikaran commented 3 months ago

I have attached utils.txt. Rename it to utils.py and replace it in src/utils.py

It has a temporary fix to skip the scan for stocks which throw the error and log some debug info like below.

XTZUSDT - a: <class 'float'>, b: <class 'numpy.float64'>, c: <class 'float'>, d: <class 'numpy.float64'>, avol: <class 'float'>, cVol: <class 'float'>, avg: <class 'numpy.float64'>, atr: <class 'numpy.float64'> 

Run the script and paste the log here. XTZUSDT is the symbol name. If possible, attach the offending stock CSV file. That way i can run tests of the file and fix it faster.

utils.txt

Prady04 commented 3 months ago

hi you have removed the csv_loader method. so i assume i need an updated init,py as well? following stocks are causing the errors. once i remove these from csv it works fine

VARROC VBL VEDL WELCORP WELSPUNLIV WIPRO ZENSARTECH ZYDUSWELL VMART VIPIND TRITURBINE TIINDIA THERMAX TORNTPHARM TRENT TV18BRDCST TANLA TVSMOTOR TCS SBIN POLICYBZR PHOENIXLTD

On Sun, 19 May 2024 at 20:47, Benny Thadikaran @.***> wrote:

I have attached utils.txt. Rename this attached file to utils.py and replace it in src/utils.py

I have added a temporary fix to skip the scan for such stocks. But it will also log some debug info like below.

XTZUSDT - a: <class 'float'>, b: <class 'numpy.float64'>, c: <class 'float'>, d: <class 'numpy.float64'>, avol: <class 'float'>, cVol: <class 'float'>, avg: <class 'numpy.float64'>, atr: <class 'numpy.float64'>

Can you run the script and paste the log here. XTZUSDT here is the symbol name. If its possible can you provide me the offending symbols CSV file. That way i can run tests of the file and fix it faster.

utils.txt https://github.com/BennyThadikaran/stock-pattern/files/15369860/utils.txt

— Reply to this email directly, view it on GitHub https://github.com/BennyThadikaran/stock-pattern/issues/28#issuecomment-2119272363, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ7FKRX6LYSMGRVMFP4E36TZDC7ABAVCNFSM6AAAAABH4EIAWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGI3TEMZWGM . You are receiving this because you authored the thread.Message ID: @.***>

BennyThadikaran commented 3 months ago

No need to update the init.py. Assuming you have updated to the latest 3.0 version, just download utils.txt. Rename to .py and replace your utils.py and run init.py.

It seems like some of your CSV files have duplicate dates. Normally my code should handle this issue, but clearly i missed something.

If you're using EOD2 you could try running diagnostic.py in EOD2 /src/defs/diagnostic.py. That will help detect common issues in files. For now if you can run the scan with utils.py i will have the necessary info to get started on a fix.

BennyThadikaran commented 3 months ago

Can you send me a sample of one the CSV files causing the problem. That will also help.

Prady04 commented 3 months ago

a few data files

On Sun, 19 May 2024 at 22:23, Pradeep Iyer @.***> wrote:

hi you have removed the csv_loader method. so i assume i need an updated init,py as well? following stocks are causing the errors. once i remove these from csv it works fine

VARROC VBL VEDL WELCORP WELSPUNLIV WIPRO ZENSARTECH ZYDUSWELL VMART VIPIND TRITURBINE TIINDIA THERMAX TORNTPHARM TRENT TV18BRDCST TANLA TVSMOTOR TCS SBIN POLICYBZR PHOENIXLTD

On Sun, 19 May 2024 at 20:47, Benny Thadikaran @.***> wrote:

I have attached utils.txt. Rename this attached file to utils.py and replace it in src/utils.py

I have added a temporary fix to skip the scan for such stocks. But it will also log some debug info like below.

XTZUSDT - a: <class 'float'>, b: <class 'numpy.float64'>, c: <class 'float'>, d: <class 'numpy.float64'>, avol: <class 'float'>, cVol: <class 'float'>, avg: <class 'numpy.float64'>, atr: <class 'numpy.float64'>

Can you run the script and paste the log here. XTZUSDT here is the symbol name. If its possible can you provide me the offending symbols CSV file. That way i can run tests of the file and fix it faster.

utils.txt https://github.com/BennyThadikaran/stock-pattern/files/15369860/utils.txt

— Reply to this email directly, view it on GitHub https://github.com/BennyThadikaran/stock-pattern/issues/28#issuecomment-2119272363, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ7FKRX6LYSMGRVMFP4E36TZDC7ABAVCNFSM6AAAAABH4EIAWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGI3TEMZWGM . You are receiving this because you authored the thread.Message ID: @.***>

BennyThadikaran commented 3 months ago

I managed to reproduce the error by adding a duplicate entry to the csv file. The issue was the Close value. It has been fixed for good now in all the find_* functions.

Prady04 commented 3 months ago

Awesome, thanks for the update!

regards, Pradeep

On Mon, May 20, 2024, 15:34 Benny Thadikaran @.***> wrote:

I managed to reproduce the error by adding a duplicate entry to the csv file. The issue was the Close value. It has been fixed for good now in all the find_* functions.

— Reply to this email directly, view it on GitHub https://github.com/BennyThadikaran/stock-pattern/issues/28#issuecomment-2120115612, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ7FKRVPINVQXXI3LOAR2S3ZDHDBNAVCNFSM6AAAAABH4EIAWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRQGEYTKNRRGI . You are receiving this because you authored the thread.Message ID: @.***>