最近在学习爬数据,这是对matplotlib.finance下的quotes_historical_yahoo模块的功能学习。该模块用于从雅虎财经查询有用的信息。
Help on function quotes_historical_yahoo inmodule matplotlib.finance:
查询调用格式如下,其中ticker指的是股票简称(如‘AXP’,‘SOHU’,‘XINA’等);date1指的是数据起始日期,date2指的是数据终止日期。返回数据时,顺序是从过去到现在,也就是最近的数据会在最下方。
quotes_historical_yahoo(ticker, date1,date2, asobject=False, adjusted=True, cachename=None)
Get historical data for ticker between date1 and date2.
看注释说这个模块好像已经被抛弃了……我看的学习资料有点老了吗……
之后可以调用quotes_yahoo_historical_ochl或quotes_yahoo_historical_ohlc来完成同样的需求。
This function has been deprecated in 1.4 in favor of
`quotes_yahoo_historical_ochl`, which maintains the original argument
order, or `quotes_yahoo_historical_ohlc`, which uses the
open-high-low-close order. Thisfunction will be removed in 1.5
See :func:`parse_yahoo_historical` for explanation of output formats
and the *asobject* and *adjusted* kwargs.
Parameters
----------
ticker : str
stock ticker
date1 : sequence of form (year, month, day), `datetime`, or `date`
start date
date2 : sequence of form (year, month, day), `datetime`, or `date`
end date
cachename : str or `None`
is the name of the local file cache. If None, will
default to the md5 hash or the url (which incorporates the ticker
and date range)
以下为给出的使用实例:
Examples
--------
>>> sp = f.quotes_historical_yahoo('^GSPC', d1, d2, asobject=True,adjusted=True)
>>> returns = (sp.open[1:] - sp.open[:-1])/sp.open[1:]
>>> [n,bins,patches] = hist(returns, 100)
>>> mu = mean(returns)
>>> sigma = std(returns)
>>> x = normpdf(bins, mu, sigma)
>>> plot(bins, x, color='red', lw=2)