如何通过pandas-datareader从雅虎获得“今日报价”

时间:2015-10-15 23:20:28

标签: python pandas-datareader

使用pandas-datareader和yahoo,当我开始和结束的时间相同,当我在那个日期询问时,我没有收到任何信息。如果我问一天后,它会起作用。但我希望今天今天结束。

import sys
from sqlalchemy import *
import os
import datetime
import pandas_datareader.data as web

end = datetime.datetime(2015, 10, 15)
start = datetime.datetime(2015, 10, 15)

path = 'c:\\python34\\myprojects\\msis\\' 
try:
    os.mkdir(path)
except:
    pass
fname = path + 'test.txt'
fhand = open(fname, 'w')

engine = create_engine('mysql+mysqlconnector://root:@localhost     /stockinfo')
connection = engine.connect()

result1 = engine.execute("select symbol from equities where daily = 'Y'")

for sqlrow in result1:
    try:
        info = web.DataReader(sqlrow[0], 'yahoo', start, end)
        print (info)
        close = info['Close'].ix['2015-10-14']
        print ("=========================" + str(round(close,4)))
        answer = "Closing price for " + sqlrow[0] + " is " + str(round(close,4)) + "\n"
    except:
        answer = "No success for " + sqlrow[0] + "\n"
    fhand.write(answer)
#   result2 = engine.execute("update holdings set lasrprice = " + round(close,4) + " where symbol = '" + sqlrow[0] + "'")
#   result2.close()

result1.close()
fhand.close()

代码采用第二条“除”路线。

我做错了什么/发生了什么?

0 个答案:

没有答案