fmilthaler / FinQuant

A program for financial portfolio management, analysis and optimisation.
MIT License
1.34k stars 190 forks source link

Momentum Indicators - RSI, MACD #119

Open pythonhacker opened 11 months ago

pythonhacker commented 11 months ago

First of all thanks for the great work. This package is amazing!

I think apart from moving averages and related bollinger bands, indicators like RSI would add relative strength to the package (pun intended). Let me know what you think.

This issue is about adding a feature for plotting RSI indicators using a 14 day window as suggested using the approach here -> https://www.alpharithms.com/relative-strength-index-rsi-in-python-470209/

Update: Edited the issue and generalized it over a number of momentum indicators. I can go ahead and implement them all or we can discuss it if you have suggestions.

pythonhacker commented 11 months ago

I have completed an implementation of this in my fork of the project - https://github.com/pythonhacker/FinQuant/tree/feature/rsi-indicator. Screenshot_2023-07-31_17-50-07

fmilthaler commented 11 months ago

Hey @pythonhacker :) Awesome, appreciate both, the suggestion as well as your work on the implementation. I'll look over the PR in the next few days. :)

pythonhacker commented 11 months ago

I am right now using this project on a jupyter notebook to make decisions over stocks to invest in the highly bullish stock market of my country (India), so I am bullish on this project as well.

pythonhacker commented 11 months ago

Here is an implementation of MACD in the same PR. See attached figure. Screenshot_2023-08-02_00-00-57

fmilthaler commented 11 months ago

Man, really love this. :) And happy to hear that you are using FinQuant to invest and making the project even better.

And feel free to add more such indicators if you please.

Just a friendly reminder:

While FinQuant has tests in place that are run automatically by GitHub Actions, it cannot guarantee to be bug free, nor that the analysis or optimised portfolio yield to wealth. Please use at your own discretion and refer to the License.

Source: FinQuant's documentation ;)

pythonhacker commented 11 months ago

@fmilthaler - Added documentation and unit test. Let me know if this looks good.

fmilthaler commented 11 months ago

Hey, thank you for adding those. I've already merged your branch into FinQuant's branch feature/rsi-indicator so that I could play around with it myself. Could you open a new PR and set it up to be merged into said branch? Thanks for adding those. On a related note though, I stumbled upon this project: https://github.com/matplotlib/mplfinance It adds support for all kinds of financial indicators. All you need to feed it is data in form of a dataframe. I haven't tried yet, but I believe this would work nicely in combination with FinQuant, as in you have your data in a Portfolio instance from FinQuant, and then feed that (example: pf.data) into the functions provided by mplfinance.

pythonhacker commented 11 months ago

Hey, thank you for adding those. I've already merged your branch into FinQuant's branch feature/rsi-indicator so that I could play around with it myself. Could you open a new PR and set it up to be merged into said branch? Thanks for adding those. On a related note though, I stumbled upon this project: https://github.com/matplotlib/mplfinance It adds support for all kinds of financial indicators. All you need to feed it is data in form of a dataframe. I haven't tried yet, but I believe this would work nicely in combination with FinQuant, as in you have your data in a Portfolio instance from FinQuant, and then feed that (example: pf.data) into the functions provided by mplfinance.

Looks good, may I suggest we look into this as an enhancement over the current code ? Let us merge this first and in another set of feature issues, refactor the code to use mplfinance . Meanwhile I will create the 2nd PR.