ffn是一個分析時間序列的package,可以很輕易的取得多檔股票的股價,並使用一些dataframe 既有的功能 ,ffn的底層是使用Yahoo! Finance,所以同樣也可以抓台股或其他國際股市
import ffn
#%pylab inline
# download price data from Yahoo! Finance. By default,
# the Adj. Close will be used.
prices = ffn.get('aapl,msft', start='2010-01-01')
# let's compare the relative performance of each stock
# we will rebase here to get a common starting point for both securities
ax = prices.rebase().plot()
輸出結果
# now what do the return distributions look like?
returns = prices.to_returns().dropna()
ax = returns.hist()
輸出結果