【发布时间】:2018-07-21 20:14:15
【问题描述】:
我使用 R 包 quantmod 没有问题,它使用 Yahoo 来获取股票数据,如下所示:
get_stock_prices <- function(target, return_format = "tibble", ...) {
# Get stock prices
print(target)
stock_prices_xts <- getSymbols(Symbols = target, auto.assign = FALSE, ...)
# Rename
names(stock_prices_xts) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")
# Return in xts format if tibble is not specified
if (return_format == "tibble") {
stock_prices <- stock_prices_xts %>%
as_tibble() %>%
rownames_to_column(var = "Date") %>%
mutate(Date = ymd(Date))
} else {
stock_prices <- stock_prices_xts
}
write.csv(stock_prices, file = paste(target, "csv", sep = '.'))
}
我只知道 Python 中的 pandas_datareader 可以实现类似的功能。不幸的是,随着 yahoo 和 google API 的变化,这个包被破坏了。这段代码:
import pandas_datareader as pdr
panel_data = pdr.get_data_yahoo('MSFT')
结果:
Yahoo Actions has been immediately deprecated due to large breaks in the API without the
introduction of a stable replacement. Pull Requests to re-enable these data
connectors are welcome.
是否有当前工作的 Python 包来实现上述目标。我知道quandl,但这是一项付费服务。谢谢。
【问题讨论】:
-
为什么要近距离投票?
-
您可能会喜欢iexfinance module。它有多种方法可以在 pandas 数据框中使用显示股票价格数据。
标签: python r stockquotes