0

I'm new to pandas and matplotlib and I'm trying to code some algorithmic trading.

I bought this course, and now I understand more, BUT...

It does not includes sample code for OHLC chart in intraday (I mean, it is not complete)

And there are others problems that i have like that my native language is not English (there is no quality material in Spanish about those libraries)

All the material that I found online only plots "daily chart" and is based in matplotlib.finance, and now it is deprecated, currently python uses mplfinance.

Please I need a sample code to chart the csv file in seconds, minutes, hours and days.

I really had tried, I'm not a lazy person, but is taking a lot of time just to plot that chart, the course does not solve my requirement.

Here you have csv file for Alibaba (BABA) in 1 second, 5 second, 15 second, 30 second and 1 minute OHLC chart.

My data

William Miller
  • 9,839
  • 3
  • 25
  • 46

1 Answers1

0

MPLFINANCE

You can use mplfinance. I tried it and it worked, here is the sample code.

note: you need to rename the column in your source data so the columns Open, High, Low, Close have uppercase in their first character.

import mplfinance as mpf
import pandas as pd

data = pd.read_csv('NYSE_BABA, 5s.csv', index_col=0)
data.index = pd.to_datetime(data.index)
mpf.plot(data,type='candle')

Well yes the candlestick is difficult to see because we have the short range data, but you get the idea. Hope it helps!

enter image description here


PLOTLY

You might want to consider Plotly for a nicer visualization.

import plotly.graph_objects as go
import pandas as pd

data = pd.read_csv('NYSE_BABA, 5s.csv')
data['time'] = pd.to_datetime(data['time'], unit='s')

fig = go.Figure(data=[go.Candlestick(x=data['time'],
                open=data['Open'],
                high=data['High'],
                low=data['Low'],
                close=data['Close'])])

fig.show()

enter image description here

dzakyputra
  • 682
  • 4
  • 16