Python for Finance: Analyze Big Financial Data

(Elle) #1
plt.grid(True)
ax.xaxis_date()
plt.title(‘DAX Index’)
plt.ylabel(‘index level’)
plt.setp(plt.gca().get_xticklabels(), rotation= 30 )

Figure 5-21. Daily summary chart for financial data

Often, stock price data is combined with volume data in a single plot to also provide


information with regard to market activity. The following code, with the result shown in


Figure 5-22, illustrates such a use case based on historical data for the stock of Yahoo!


Inc.:


In  [ 30 ]: quotes  =   np.array(mpf.quotes_historical_yahoo(‘YHOO’,    start,  end))
In [ 31 ]: fig, (ax1, ax2) = plt.subplots( 2 , sharex=True, figsize=( 8 , 6 ))
mpf.candlestick(ax1, quotes, width=0.6, colorup=‘b’, colordown=‘r’)
ax1.set_title(‘Yahoo Inc.’)
ax1.set_ylabel(‘index level’)
ax1.grid(True)
ax1.xaxis_date()
plt.bar(quotes[:, 0 ] - 0.25, quotes[:, 5 ], width=0.5)
ax2.set_ylabel(‘volume’)
ax2.grid(True)
ax2.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation= 30 )
Free download pdf