给定公司名称,退货证券交易所和股票代码(使用R)

时间:2017-09-12 17:35:20

标签: r finance

想知道某人是否有能力获取公司名称并输出其交易所和股票代码。例如,可以采用字符向量输入:

company <- c("Google", "General Motors Company", "singtei")

并返回

stockinfo <- ("NASDAQ: GOOGL", "NYSE: GM", "SGX: Z74")

可能没有这么简单(使用像ggmap这样繁重的包),但作为类似功能的一个示例,此代码返回给定城市名称的地理坐标:

# Cities needing geocodes
cities <- c("Phoenix", "Los Angeles", "Portland")
# Geocode function
library(ggmap)
coord <- geocode(cities)
# Geographic coordinates
coord  

输出:

        lon      lat
1 -112.0740 33.44838
2 -118.2437 34.05223
3 -122.6765 45.52306
> 

1 个答案:

答案 0 :(得分:1)

> company <- "Microsoft"
> symbolData <- stockSymbols(exchange = c("AMEX", "NASDAQ", "NYSE"))
Fetching AMEX symbols...
Fetching NASDAQ symbols...
Fetching NYSE symbols...

> exc <- symbolData[agrep(company, symbolData[,2]), 8]
> sym <- symbolData[agrep(company, symbolData[,2]), 1]
> STK <- paste(exc,":",sym, sep = "")

> STK
[1] "NASDAQ:MSFT"