Search code examples
pythonfinanceyahoo-financemplfinance

Issues with creating candlestick chart using mplfinance


Im relatively new to coding and especially financial coding and am having issues with mpl finance candlestick charts. My code goes something like

symbol = ['NIO']

start = datetime.datetime(2016,1,1)
end = datetime.date.today()

Stockdata = yf.download(symbol,start,end)

fplt.plot(Stockdata,
          type='candle',
          title='NIO, 2016 - 2020',
          ylabel='Price ($)'
        )

My output looks like this: Looks more like a line graph than a candlestick graph

I've found multiple comprehensive codes to plot candlestick charts but this relatively simple one seems to work for others, however if it doesn't seem to work for me, I'm probably missing something simple but like I said am new to coding, any help would be greatly appreciated.


Solution

  • It does look like a line chart, but it just looks collapsed because of the large number of data, but if you limit the number of data, it becomes a candlestick graph. The following is a graph with a narrowed-down count.

    import yfinance as yf
    import datetime
    import mplfinance as mpf
    
    symbol = ['NIO']
    
    start = datetime.datetime(2016,1,1)
    end = datetime.date.today()
    
    Stockdata = yf.download(symbol,start,end)
    
    mpf.plot(Stockdata[350:],
              type='candle',
              title='NIO, 2016 - 2020',
              ylabel='Price ($)',
             figratio=(12,4),
             volume=True
            )
    

    enter image description here