TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.49k stars 1.74k forks source link

Configuring CDL_PATTERNS before nmake #480

Closed 4trade closed 2 years ago

4trade commented 2 years ago

Hi,

so thanks for the wrapper its convenient.

Ta_libs original CDL_PATTERNS are not cool, so I thought fiddling with their source under (C:\ta-lib\c\src\ta_func) before using nmake, would do the trick and let me adjust the CDL_PATTERNS to my preference.

For PoC I changed the return value "100" of a CDL function to "80", used nmake, reinstalled ta_lib for python, reset the command prompt and run the script, with no luck, changes do not persist, or I'm looking in the wrong place. Someone knows what I'm talking about?

trufanov-nok commented 2 years ago

I changed the return value "100" of a CDL function to "80"

Where you changed it? Tell us a file and the line in it.
Also a link with compilation output could be provided via the pastebin.
And finally some task manager which is able to list dlls loaded by the running process would come in handy. You can launch python, import talib module and then list all dlls with their filepaths that are loaded by python process. There should be 2 related to talib: the original library and its wrapper. Last time I was launching Windows I used AnVir Task Manager for such tests. Perhaps modern Win versions could display such info without 3rd party tools. Once you know the exact dll location you may make sure this dll file is updated at the end of your nmake build process.

mrjbq7 commented 2 years ago

Are you installing this Python wrapper from a wheel? Or using the win64 build instructions?

On Dec 9, 2021, at 4:47 AM, 4trade @.***> wrote:

 Hi,

so thanks for the wrapper its convenient.

Ta_libs original CDL_PATTERNS are not cool, so I thought fiddling with their source under (C:\ta-lib\c\src\ta_func) before using nmake, would do the trick and let me adjust the CDL_PATTERNS to my preference.

For PoC I changed the return value "100" of a CDL function to "80", used nmake, reinstalled ta_lib for python, reset the command prompt and run the script, with no luck, changes do not persist, or I'm looking in the wrong place. Someone knows what I'm talking about?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

4trade commented 2 years ago

Are you installing this Python wrapper from a wheel? Or using the win64 build instructions? On Dec 9, 2021, at 4:47 AM, 4trade @.***> wrote:  Hi, so thanks for the wrapper its convenient. Ta_libs original CDL_PATTERNS are not cool, so I thought fiddling with their source under (C:\ta-lib\c\src\ta_func) before using nmake, would do the trick and let me adjust the CDL_PATTERNS to my preference. For PoC I changed the return value "100" of a CDL function to "80", used nmake, reinstalled ta_lib for python, reset the command prompt and run the script, with no luck, changes do not persist, or I'm looking in the wrong place. Someone knows what I'm talking about? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

I'm using x64 nmake instructions to install ta_lib and that works only under C:\ta-lib\c\make\cdr\win32\msvc Calls are coming from pandas_ta, which has python ta_lib as a dependency, and C ta_lib in turn. The good news is that candle_patterns are working after installing C ta_lib with instructions.


import pandas_ta as ta    

def patterns(self, df):
        # extend pDF with candle-pattern, price-action, indicator-action  columns 
        df.ta.rsi(close="close", length=25, append=True)
        df.ta.cdl_pattern(name="hammer", append=True)

I will try what @trufanov-nok mentioned, maybe something is not updated with nmake.

mrjbq7 commented 2 years ago

I guess what I'm saying is that you need to build your own version of this python module if you change the C library.

4trade commented 2 years ago

yea, i see maybe changing a few paths in setup.py? maybe that could help. This lib gave me quick results, and vectorbt seemed quite messy for indicator calculations. But maybe the best way is to code it all, or at least the candle patterns. How have you handled that one?

mrjbq7 commented 2 years ago

I don't think any paths would need to change if you build it in c:\ta-lib

4trade commented 2 years ago

I changed the return value "100" of a CDL function to "80"

Where you changed it? Tell us a file and the line in it. Also a link with compilation output could be provided via the pastebin. And finally some task manager which is able to list dlls loaded by the running process would come in handy. You can launch python, import talib module and then list all dlls with their filepaths that are loaded by python process. There should be 2 related to talib: the original library and its wrapper. Last time I was launching Windows I used AnVir Task Manager for such tests. Perhaps modern Win versions could display such info without 3rd party tools. Once you know the exact dll location you may make sure this dll file is updated at the end of your nmake build process.

The changes are in: C:\ta-lib\c\src\ta_func\ta_CDLHAMMER.c line 257 value 100 -> 80 line 388 value 100 -> 80

This is the output of nmake after making changes in one of the ta_func files: https://pastebin.com/cBHxBpXX (also tried nmake clean && nmake)

And these are the loaded DLLs, there is only one related to ta-lib though which is the .pyd generated from "pip install ta-lib==0.4.22": https://pastebin.com/p4a2U1Te

Thats the script used to print DLLs:

import psutil, os
import pandas_ta as ta
import talib
p = psutil.Process( os.getpid() )
for dll in p.memory_maps():
  print(dll.path)

C ta_lib forum is unavailable, however it seems there is not problem with building it. Py ta_lib links to the produced files correctly, because when C ta_lib is built I do not get error "need to install ta_lib library".

4trade commented 2 years ago

I guess what I'm saying is that you need to build your own version of this python module if you change the C library.

At the moment all I can understand is, that since this lib is a wrapper for the C version, changing the C version would do the trick. Maybe you can point me differently.

trufanov-nok commented 2 years ago

@4trade Well I see only .lib files building in nmake output. These are static libraries. And as only a wrapper library is visible as loaded by python process, I would expect it's statically linked with ta-lib library. Which means a binary code of ta-lib is integrated inside the wrapper and you can't change anything without wrapper code regeneration.
In Linux ta-lib libraries are dynamically loaded and I see both wrapper and the c library. But on Win static linking has sense as ta-lib dll isn't installed into system32/ folder and wrapper could have problems with finding its location... You may doublecheck if it's statically linked.

  1. Take a look inside ./lib/ subfolder and try to find dll files there.
  2. You may open wrapper file (C:\Users\30698\AppData\Local\Programs\Python\Python39\Lib\site-packages\talib\_ta_lib.cp39-win_amd64.pyd) in some app that is capable of listing dll dependencies. Like the old Dependency Walker. If there is no ta-lib dlls among dependencies then they are statically linked.
4trade commented 2 years ago

Just found it. As @mrjbq7 mentioned, when changing C ta-lib files, its required to re-build this wrapper from source. So eventually I had to uninstall anything related to talib installed with "pip install" under Python/site-packages/ And then just clone this wrapper from Git and run setup.py install.

Changes take place now. Thanks @trufanov-nok @mrjbq7