Skip to content
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

use tulipy and accept an array of technical indicators as an argument (feature request) #3

Closed
ckhung opened this issue Dec 20, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@ckhung
Copy link

ckhung commented Dec 20, 2019

Hi Daniel, thank you for taking over the maintainance of mpl-finance. I agree with you about the new mission statement. Here is a feature request for you to consider. The tulipy project already implemented lots of technical indicators. It would be nice to be able to use them in mpl_finance. Here is a short piece showing how I would like to be able to pass my chosen technical indicators as arguments to candlestick_ohlc():

#!/usr/bin/python3

import numpy as np
import tulipy as ti
from datetime import datetime

def candlestick_ohlc(quotes, ti_array):
    close_prices = quotes['Close'].copy(order='C')
    for ti in ti_array:
        f = ti['f']
        del ti['f']
        print(f.full_name, f(close_prices, **ti))
        # of course in real code it should be plotting here.

dt = [float] * 6
dt[0] = 'datetime64[D]'
convertfunc = lambda x: datetime.strptime(x.decode('utf8'), '%m/%d/%Y')
daily = np.genfromtxt('SP500_NOV2019_Hist.csv',
    delimiter=',', autostrip=True, names=True, dtype=dt,
    converters = {'Date': convertfunc}
)
candlestick_ohlc(daily, [
    {'f':ti.sma, 'period':5},
    {'f':ti.sma, 'period':10},
    {'f':ti.macd, 'short_period':2, 'long_period':5, 'signal_period':9}
] )

Maybe we also need room for options telling candlestick_ohlc what colors and line width, etc. to use for each indicator line. And/or whether some of them should be displayed as solid bar and/or on a separate pane (so that volume can be processed using exactly this same interface without requiring a distinctive/separate interface). I don't have a very good suggestion yet as to how best to design that part of the interface.

@DanielGoldfarb
Copy link
Collaborator

Chao-Kuei, Thank you so much for the idea. I had never heard of tulipy, and I like this idea very much. I will try in the next few weeks to make some time to experiment with the code you have provided, and with tulipy in general, and see if I can prototype something for you to play with.

Regarding your other ideas, Volume is already available via the same interface and on a separate pane, and the ability to customize more of the plot is also on my list of things to do. Again, thanks so much for the idea regardy tulipy. I will definitely be looking into it.

@DanielGoldfarb DanielGoldfarb added the enhancement New feature or request label Jan 15, 2020
@DanielGoldfarb
Copy link
Collaborator

The are now a number of ways to add technical indicators to mplfinance plots, most of which are outlined here: https://github.com/matplotlib/mplfinance/blob/master/examples/addplot.ipynb

These techniques allow many different source of technical indicators to be plotted in mplfinance, including tulipy, pandas-ta, and others.

I would prefer not to integrate directly into mplfinance and thereby create unnecessary dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants