最近,我开始进行股票价格分析,以优化我的投资组合。我从一个Excel文件和几个VBA宏开始。它工作得很好,但是非常慢。因此,我现在正尝试在服务器上建立并建立适当的“股票价格”数据库(基于此帖子)。
在“ stock_prices”数据库中,有一个“ daily_price”表,用于存储某些行情的每日股票价格。为了更新“每日价格”表,每天都会启动python脚本,其中包括以下Python / SQL语句。
df = pdr.get_data_yahoo(ticker, start_date)
for row in df.itertuples():
values = [YAHOO_VENDOR_ID, ticker_index[ticker]] + list(row)
cursor.execute("INSERT INTO daily_price (data_vendor_id, ticker_id, price_date, open_price, high_price, low_price, close_price, adj_close_price, volume) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", tuple(values))
不幸的是,“ cursor.execute ...”行返回以下错误:“ AttributeError:“ Timestamp”对象没有属性“ translate””
“值”元组的打印输出是:[1、2,时间戳('2004-08-19 00:00:00'),49.81328582763672、51.83570861816406、47.80083084106445、49.9826545715332、49.9826545715332、44871300]<