0

对于将 pandas-datareader 与雅虎一起使用,当我在同一日期开始和结束时,当我在该日期询问时没有返回任何信息。如果我在一天后询问,它会起作用。但我想今天收盘。

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()

该代码采用第二条“例外”路线。

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

4

0 回答 0