我正在使用雅虎财经将股票数据读取到python中。然而,它适用于股票,它给出了商品的错误。
下面的代码运行得很好:
import pandas as pd
import numpy as np
import pandas.io.data as web
import datetime
# We will look at stock prices over the past year, starting at January 1, 2016
start = datetime.datetime(2016,1,1)
end = datetime.date.today()
stock = "AAPL"
# get stock data, from yahoo finance within the dates specified
stock = web.DataReader(stock, "yahoo", start, end)
stock.head(n=3)
但是,如果您更改商品的句柄而不是股票的句柄,则会出现以下错误:
import pandas as pd
import numpy as np
import pandas.io.data as web
import datetime
# We will look at stock prices over the past year, starting at January 1, 2016
start = datetime.datetime(2016,1,1)
end = datetime.date.today()
stock = "GCG17.CMX"
# get stock data, from yahoo finance within the dates specified
stock = web.DataReader(stock, "yahoo", start, end)
stock.head(n=3)
OSError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.finance.yahoo.com/table.csv?s=GCG17.CMX&a=0&b=1&c=1970&d=0&e=22&f=2017&g=d&ignore=.csv'
有谁可以帮我?
发布于 2020-10-15 23:18:18
取而代之的是著名的yfinance
。以下是糖期货的信息:
import yfinance as yf
df = yf.download('SB=F', '2020-03-23')
如果你想要黄金期货,只需使用符号GC=F
即可。如果您希望绘制它:
import finplot as fplt
fplt.candlestick_ochl(df[['Open','Close','High','Low']])
fplt.show()
发布于 2017-01-23 15:41:53
您可以使用YQL Console并尝试使用SQL来提取所需的数据。
例如,我尝试使用select * from yahoo.finance.historicaldata where symbol = "AAPL" and startDate = "2016-01-01" and endDate = "2017-01-22
,并成功地获得了我想要的表。
如果我把"AAPL“替换成"GCG17.CMX”,我什么也得不到。因此,我不认为python中的库(如pandas和yahoo_finance )有任何问题。问题出现在雅虎方面。
您可以尝试查找其他数据库,如沃顿数据服务等,以获得您想要的表。希望这能有所帮助。
发布于 2017-04-03 10:46:30
你得到了一个错误,因为雅虎财经没有保存历史商品价格。
https://stackoverflow.com/questions/41798831
复制相似问题