FinQuant icon indicating copy to clipboard operation
FinQuant copied to clipboard

Momentum Indicators - RSI, MACD ... (#120)

Open fmilthaler opened this issue 2 years ago • 6 comments

Implementation of RSI momentum indicator, thank you @pythonhacker. This closes #119.

fmilthaler avatar Aug 05 '23 13:08 fmilthaler

Hi @fmilthaler - Any updates on if/when you may merge this ? Thank you.

pythonhacker avatar Sep 08 '23 04:09 pythonhacker

Hey, sorry for the delay, I was away and then busy otherwise. Anyway, I found several (different) implementations of the RSI, and they all differ from another. I still want to go through them and understand them better and see what can be used here. Funny thing is, they give different results. As for the macd, it might be good to use the example of https://github.com/matplotlib/mplfinance/blob/master/examples/indicators/macd_histogram_gradient.ipynb now rather in a later merge.

fmilthaler avatar Sep 09 '23 06:09 fmilthaler

Do you want me to modify the code ?

pythonhacker avatar Sep 20 '23 15:09 pythonhacker

Sorry for the delay @pythonhacker. I had to have a closer look at the RSI itself to understand it first.

~As for the implementation of the rsi relative_strength_index, can you please remove the for loops and use vectorized computations instead for the sake of performance and readability?~ Note: I just realized the dependecy within the for loop, thus a vectorized computation is not possible here. Too bad :(

For the macd, could you make use of the package mplfinance here instead? I don't like reinventing the wheel here. We can simply use one of the following:

  • https://github.com/matplotlib/mplfinance/blob/master/examples/indicators/macd.py
  • https://github.com/matplotlib/mplfinance/blob/master/examples/indicators/macd_histogram_gradient.ipynb

to plot the macd.

Again, sorry for the delay in this, I've been busy and pushed this back too many times.

fmilthaler avatar Sep 22 '23 13:09 fmilthaler

@pythonhacker I've updated the code to be compliant with the recent master and made changes to the macd function to be like the example in mplfinance. Have a look at everything and let me know if you are happy with that. If so, we can then get it checked by Pietropaolo and then merged.

Note: Mypy is not happy yet, thus more changes are required. If you want to have a look at that, please run scripts/run_code_analysis.sh and go through the mypy issues and try to fix them.

This is what the MACD plot looks like now: image

fmilthaler avatar Oct 01 '23 14:10 fmilthaler

@fmilthaler - I have been out of touch for a while, due to work and just looked back at this. Didn't see the review request my bad. Kindly let me know if I can still review this.

pythonhacker avatar Dec 23 '23 07:12 pythonhacker