我知道一些在R或Python中获取每日股票价格和成交量的方法,但我想知道是否有一种方法(使用R或Python),可以获取更多关于股票的信息,例如市盈率、公司网站、收益率等等,最好不仅是当前值,还包括历史数值。谢谢。
getQuote
函数,结合yahooQF
参数可以满足你获取当前数值的需求。require("quantmod")
getQuote("GS", what = yahooQF(c("Market Capitalization", "Earnings/Share",
"P/E Ratio", "Book Value", "EBITDA", "52-week Range")))
Trade Time Market Capitalization Earnings/Share P/E Ratio Book Value EBITDA 52-week Range
GS 2012-06-21 04:00:00 47.870B 6.764 14.27 134.476 0 84.27 - 139.25
还有,请尝试
getQuote("GS", what=yahooQF())
这将为您提供一个菜单,以选择要请求的字段。
您可以使用getFinancials
从Google Finance获取最近的财务报表。
还有FinancialInstrument包,其中包含几个update_instruments.*
函数,可下载有关工具(在此情况下是股票)的元数据。例如,以下是雅虎的做法。
require("FinancialInstrument")
stock("GS", currency("USD")) # define the stock
#[1] "GS"
update_instruments.yahoo("GS") #update with yahoo
#[1] "GS"
getInstrument("GS")
#primary_id :"GS"
#currency :"USD"
#multiplier :1
#tick_size :0.01
#identifiers : list()
#type :"stock"
#name :"Goldman Sachs Gro"
#exchange :"NYSE"
#market.cap :"47.870B"
#avg.volume :5480530
#EPS :6.76
#EPS.current.year.est:11.4
#EPS.next.year.est :12.9
#book.value :134
#EBITDA :0
#range.52wk :"84.27 - 139.25"
#defined.by :"yahoo"
#updated : POSIXct, format: "2012-06-21 19:31:11"
getDividends
(历史分红),getSplits
(历史拆分),getSymbols
(历史股票价格)和 getOptionChain
(快照报价期权链)功能。 - GSee仅回答我的问题中关于网站部分的内容:
str <- paste("http://investing.money.msn.com/investments/company-report?symbol=", ticker, sep = "")
page <- paste(readLines(url(str, open = "rt")), collapse = "\n")
match <- regexpr("<a href=\"http://www\\.(\\S+)\">Website</a>", page, perl = TRUE)
if (attr(match, "match.length") > 0) {
site <- substring(page, attr(match, "capture.start"), attr(match, "capture.start") + attr(match, "capture.length") - 1)
site <- strsplit(site, "/")[[1]][1]
}