-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Hilbert Transform Trendline, closes issue #411 #759
Implement Hilbert Transform Trendline, closes issue #411 #759
Conversation
…tor. Also the initialization of ht_trendline is done inside ht_trendline.py file.
Hello @aligheshlaghi97, On first glance it looks good. I'll take a look this week. Also all the other Hilbert Transform indicators need to be converted as well, so this is a great starting point. Thanks for helping with this. 😎 KJ |
Hi @twopirllc Thank you for taking the time to review the PR. I'm glad to hear that the initial feedback is positive. Could you please elaborate more on what you mean by converting all HT indicators? And also how much should I consider the failed workflows as they may not belong to HT indicator? Bests, |
Sure. There are a handful left to complete that begin with HT_. I want to get those completed as well as rewrite
I can write the tests for it. No worries. 😎 |
Thank you for the additional information, @twopirllc . I'm eager to assist with completing the remaining HT indicators and rewriting td_seq for the upcoming Pandas TA release. Could you please let me know if there are any specific notes, resources, or guidelines available for implementing the HT indicators and completing the td_seq rewrite? Additionally, I wanted to mention that during the implementation of ht_trendline, I found myself delving into calculations related to ht_dcperiod (dominant cycle calculations). As such, I believe I can contribute to other aspects such as phase or sine calculations if needed. Please let me know how I can best support the completion of these indicators. |
I appreciate all the help. In no rush.
The best source is TA Lib since that is default values that Pandas TA is expected to return. Otherwise it should return TV values. I'll dig up any other info I can and make a later comment.
I figured as much. I wonder if they can all be done in one indicator? I would need to dive into the code to be sure though. |
Hi @twopirllc, Thank you for your explanations and clarifications. Based on the indicators in TALib prefixed with 'HT_', I believe it's entirely feasible to consolidate all the HT indicators into one. They share many common elements, particularly in the calculation of dcperiod. For instance, the variable I wanted to inquire about the level of expectation regarding the similarity between our results and TALib's. Is it anticipated that our results match TALib's precisely, or is there room for minor discrepancies? |
Yes. It has been acheiveable with most Pandas TA indicators to match those of TA Lib. Just get a close as you can and I will try and fix the differences. 😎 |
Thank you for the update, @twopirllc I appreciate your efforts in updating the development environment and addressing the Deprecation and Future Warnings messages. In regards to the versions, I'd like to confirm that both Python 3.9 and 3.11, along with their respective packages, yield identical results for ht_trendline. I've been working with Python version 3.10.12 and the following package versions:
Regarding the differences observed between my code and TALib's, it's possible that the variance stems from the initial point for calculating ht_trendline, resulting in non-identical outputs at the beginning of the array. However, as you rightly mentioned, they converge and maintain good coverage thereafter. Best regards, |
No worries. I just wanted to make sure that we were both getting similar results for bars between bars 63 and 167 followed by convergence starting from bar 168 on.
No rush. I'll be diving into it as well while also tackling some other issues. Appreciate the help. 😎 |
Thanks @twopirllc for your update. This indicates that the convergence point of my data is at the 116th candle for BTCUSDT-1D data, spanning from 2020 to the present. I am now even more confident that the issue lies with the initial data point, and I will work on resolving it. |
I've also found something else worth sharing. If you decrease the index at which the calculations start from 50 to 5, the convergence point will occur earlier. Please make this change in my implementation, on line 30: While this adjustment seems logical, we can't set it to zero, as Elher indicates in his article, and we can also find some clues to this in TALib's implementation. However, by making this minor change, the convergence point decreases from the 116th candle to the 95th for BTCUSDT-1D data, spanning from 2020 to the present. Moreover, MSE of the result decreases a lot. |
Hey @aligheshlaghi97 It's up and ready to go on the development version. Let me know how it works for you. Thanks again for the submission. 😎 |
Hi @twopirllc, Thank you for merging the pull request and implementing the changes. It's great to see progress in resolving the differences between our implementation and TALib's. Upon reviewing the new code, I noticed a longer time taken to converge between our implementation and TALib's, as depicted in the provided screenshots: However, I also noticed that the mean difference between our implementation and TALib's is very low: This suggests that while our implementation is more accurate in terms of mean error, it may take longer to converge compared to TALib's. I was also curious about your thoughts on the idea of mixing all ht_ indicators together. Do you think it's feasible now, or do you have any concerns about this approach? Bests |
Yes, that is true it does take a little longer to converge and has generally a smaller mean error. The truth is neither of us were able to exactly replicate TA Libs calculation and that is ok. Sometimes there will be differences in calculation no matter what. A 99% correlation is not bad considering the differences in execution and the original intent from Ehler's EasyLanguage code from which I ultimately chose to default to. However I believe it may be possible to get them exact with more time. The core groundwork has been laid and anyone is welcome to improve it. If you would like your version included as well, let me know, we can do that. No biggie.
In nearly all pandas-ta/pandas_ta/trend/ht_trendline.py Line 67 in 947cbde
So yeah, one or two can be combined easily. The others may need some juggling to do so. Cheers |
Hi @twopirllc Thank you for your insights. I appreciate the clarification. I'm glad to hear that some ht_ indicators can be combined easily. Could you please suggest which indicator would be most aligned with your opinion to work on next? Bests |
DC Period and that one is trivial as returning with trendline in the numba function. I'll dig in again after I finish this other task. Apologies for the delayed response |
Hi @twopirllc Hope you're doing well. I'm still excited about the potential to integrate other APIs for the Best regards, |
Hey @aligheshlaghi97,
There are no specific requirements and was unintentional. I apologize for it somehow not going through, I must have done something incorrectly through the merge process such that it did not include you in the contributors. 🤦🏼♂️ I will try to rectify it if you make a trivial PR so Github recognizes you as a contributor. Irregardless, I remember all the main contributors, like you, to the project. 😎
No. I had to deal with some other umm... "pressing" issue and it's post-effects. But it is still on my mind cause I want to get it done.
As we discussed earlier, I think we should try to roll as much as possible into I also have to do this with KJ |
Hi @twopirllc Sorry for my delayed response; I was working on improving the performance of the
In my trials, it seems it's not possible to further optimize our current
I believe this issue arises because we haven't had any releases for a while (or any merges with main branch), so the contribution list isn't updated. However I'll definitely make new PRs.
This is an honor for me🎉 |
Hey @aligheshlaghi97,
No worries. Even I have long response delays as well, especially since this repo is nowhere close for me to support it full time. 😑
Thanks for the optimization confirmation.
I agree. Which abstraction technique did you have in mind? I do not want to use
Your contributions and collaboration has been most gracious. You don't happen to have a Stripe (or similar) account by chance? KJ |
Hi @twopirllc
I understand, and I am very curious to know whether you're working on your public projects e.g. AlphaVantageAPI (which sounds interesting to me) or mainly on private ones.
I think abstract class could be useful for us. We can also use python protocols to remain decoupled and only use type checks.
This sounds cool, but there is debates about the performance impact, and we might need to conduct our own survey. Please look at this link about class overhead vs function Btw, if you don't want to use class's methods, there will be absolutely no difference and we can define one function to calculate the shared parts. And then use that function inside our new APIs. Shared Parts of
|
Hey @aligheshlaghi97
Mainly private ones. I haven't touched AlphaVantageAPI in a long time, too busy with Pandas TA. 😑
Yeah an ABC could be useful. Haven't heard of protocols, they seem like they can help. 🤷🏼♂️ If you want to try that approach, that would be cool.
Yeah I remember reading something like that. That the performance difference is negligible.
We will find a path, time willingly.
I will try and expand nb_ht_trendline to include the remaining ht_ indicators. Yeah,
Damn! I checked stripe and they don't support crypto there either. 😑 And I almost never use crypto. I'll look more into it when I can. |
Hi @twopirllc
Totally understandable and hopefully I'd be able to help you with some Pandas-TA's loads.
Sure, but I think our coding signature in Pandas-TA is to keep everything in function level as you said before, and using protocol requires class anyways. So I'm wondering function is better than class in our case.
Thank you so much for this, as I'm really eager to learn how you'll do it. My SuggestionI think you should make another Inside of This way we can simply use And if you want to implement sth like my suggestion, please let me do that, so you might have more free time for your other tasks.
Don't worry about it, your attention and your trial is so much valuable for me. Best Regards, |
I implemented the Hilbert Transform Instantaneous Trendline in pandas-ta by studying the mathematical principles of the Z-transform and reverse-engineering TALIB's C implementation. Through rigorous testing, I ensured that the results produced by ht_trendline match those generated by TALIB's implementation, thus enhancing the technical analysis capabilities of the pandas-ta library and closing issue #411 .
In addition, I further enhanced its performance by leveraging the Numba library, thereby significantly boosting the execution speed. This experience allowed me to deepen my understanding of Numba's capabilities and its integration within the project structure. Furthermore, I refined my Git proficiency by creating a new branch locally and generating the pull request towards the development branch. By following best practices and maintaining clean commit histories, I ensured seamless integration with minimal conflicts, streamlining the merge process for @twopirllc .
The code for test is inspired by @rafalsza provided in #411 :
Here you can see the results of the the two which are very much the same:
I also found this piece of code very useful for testing pandas-ta functions under development without the necessity of local installation or modification of the current library version.