matplotlib / mpl-finance

This package is DEPRECATED, replaced by https://github.com/matplotlib/mplfinance

Home Page:https://pypi.org/project/mplfinance/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ckhung opened this issue · comments

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. (Hope it's ok to post it as an issue.) 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}
] )

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 week or two 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. Please feel free to re-post this idea here: https://github.com/matplotlib/mplfinance/issues as I plan to be doing all new development in that new repository. Thanks again.