1

I'm trying to resample by daily data to 5 Day periods instead where it will give me a tickers price each 5 days instead of each day (like it shows in my csv file).

I'm aware how to do this with the old 'from matplotlib.finance import candlestick_ohlc' however I'm not sure how to do this with the new mplfinance module?

Essentially I want to replicate this code;

df = pd.read_csv('tsla.csv', parse_dates=True, index_col=0)

df_ohlc = df['Adj Close'].resample('5D').ohlc() 

df_volume = df['Volume'].resample('5D').sum() 

df_ohlc.reset_index(inplace=True)

df_ohlc['Date'] = df_ohlc['Date'].map(mdates.date2num) 

ax1 = plt.subplot2grid((6,1), (0,0), rowspan=4, colspan=1) 

ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1) 

ax1.xaxis_date() 

candlestick_ohlc(ax1, df_ohlc.values, width=2, colorup='g') 

ax2.fill_between(df_volume.index.map(mdates.date2num), df_volume.values, 0)

plt.show()

This is what I have so far;

mpf.plot(df, type='candle', mav=100, volume=True, style='yahoo')

Thanks for your help!

Daniel Goldfarb
  • 6,937
  • 5
  • 29
  • 61

1 Answers1

0

Please take a look here: https://github.com/matplotlib/mplfinance/wiki/Resampling-Time-Series-Data-with-Pandas

Let me know if that helps you figure it out. If not, let me know and I can provide more detail relative to your specific case.

All the best.

Daniel Goldfarb
  • 6,937
  • 5
  • 29
  • 61