是否有方法使用股票ISIN或使用tq_get提取R中的价格数据?(尤其是国际股市)



我正试图使用tidyquant包中的tq_get提取一批国际股票的价格数据,但在提取基于股票代码的数据时遇到问题,因为我的数据只有ISIN和SEDOL作为识别值。当我在雅虎金融的搜索栏中输入其中一个时,会显示正确的股权(我假设tq_get使用雅虎金融(,但当我在股票代码中输入时,我会收到一条错误消息。

我尝试在代码中输入ISIN和SEDOL值,但每个值都返回一个错误。

阿里巴巴(BABA(-在美国上市,所以这不是问题。。。

莎草醇:

test1 <- tq_get("BP41ZD1", get = "stock.prices",from = "2016-10-24",to = "2019-10-25")

ISIN:

test2 <- tq_get("US01609W1027",get = "stock.prices",from = "2016-10-24",to = "2019-10-25")

错误消息:

x = 'BP41ZD1', get = 'stock.prices': Error: BP41ZD1 download failed after two attempts. Error message: HTTP error 404. x = 'US01609W1027', get = 'stock.prices': Error: US01609W1027 download failed after two attempts. Error message: HTTP error 404.

理想情况下,我希望这能像股票代码中的"AAPL"或"MSFT"一样起作用。

任何帮助都将不胜感激!!!

更新:我有点想明白了。。。但效果并不好。我可能不得不像我在香港所做的那样,打破每一种交易所和格式,以便它在雅虎金融上搜索。本质上我需要添加"。XX’在各自交易所的股票代码后面(即:香港为HK或伦敦为.L(。如果有其他人经历过这个问题,以下是我最终所做的:

ixus_adr <- ixus %>%
filter(exchange %in% c("NASDAQ","New York Stock Exchange Inc."))
ixus_hk <- ixus %>%
filter(exchange == "Hong Kong Exchanges And Clearing Ltd") 
ixus_hk$ticker <- str_replace_all(ixus_hk$ticker, "[^[:alnum:]]", "")
ixus_hk$ticker <- as.numeric(ixus_hk$ticker) 
ixus_hk$ticker <- str_pad(ixus_hk$ticker, 4, pad = "0")
ixus_hk <- ixus_hk %>%
mutate(xch = "HK")
ixus_hk$xticker = str_c(ixus_hk$ticker, ixus_hk$xch, sep = ".")
ixus <- ixus %>%
filter(class == 'Equity') %>%
filter(exchange %in% c("Asx - All Markets", "Athens Exchange S.A. Cash Market", "Bolsa De Madrid", "Bolsa Mexicana De Valores", "Borsa Italiana", "Euronext Amsterdam", "Gretai Securities Market", "Indonesia Stock Exchange", "Irish Stock Exchange - All Market", "Istanbul Stock Exchange", "Johannesburg Stock Exchange", "Korea Exchange (Stock Market)", "London Stock Exchange", "Nasdaq Omx Helsinki Ltd.", "National Stock Exchange Of India", "New Zealand Exchange Ltd", "Nyse Euronext - Euronext Brussels", "Nyse Euronext - Euronext Lisbon", "Nyse Euronext - Euronext Paris", "Omx Nordic Exchange Copenhagen A/S", "Oslo Bors Asa", "Qatar Exchange", "Santiago Stock Exchange", "Saudi Stock Exchange", "Shanghai Stock Exchange", "Singapore Exchange", "SIX Swiss Exchange", "Six Swiss Exchange Ag", "Standard-Classica-Forts", "Taiwan Stock Exchange", "Tel Aviv Stock Exchange", "Tokyo Stock Exchange", "Toronto Stock Exchange", "Wiener Boerse Ag", "XBSP", "Xetra"))
ixus <- ixus %>%
mutate(xch = case_when(
exchange=="Asx - All Markets" ~ "AX",
exchange=="Athens Exchange S.A. Cash Market" ~ "AT",
exchange=="Bolsa De Madrid" ~ "MC",
exchange=="Bolsa Mexicana De Valores" ~ "MX",
exchange=="Borsa Italiana" ~ "MI",
exchange=="Euronext Amsterdam" ~ "AS",
exchange=="Gretai Securities Market" ~ "TWO",
exchange=="Indonesia Stock Exchange" ~ "JK",    
exchange=="Irish Stock Exchange - All Market" ~ "IR",
exchange=="Istanbul Stock Exchange" ~ "IS",
exchange=="Johannesburg Stock Exchange" ~ "JO",
exchange=="Korea Exchange (Stock Market)" ~ "KS",
exchange=="London Stock Exchange" ~ "L",
exchange=="Nasdaq Omx Helsinki Ltd." ~ "HE",
exchange=="National Stock Exchange Of India" ~ "NS",
exchange=="New Zealand Exchange Ltd" ~ "NZ",
exchange=="Nyse Euronext - Euronext Brussels" ~ "BR",    
exchange=="Nyse Euronext - Euronext Lisbon" ~ "LS",
exchange=="Nyse Euronext - Euronext Paris" ~ "PA",
exchange=="Omx Nordic Exchange Copenhagen A/S" ~ "CO",
exchange=="Oslo Bors Asa" ~ "OL",
exchange=="Qatar Exchange" ~ "QA",
exchange=="Santiago Stock Exchange" ~ "SN",
exchange=="Saudi Stock Exchange" ~ "SR",
exchange=="Shanghai Stock Exchange" ~ "SS",
exchange=="Singapore Exchange" ~ "SI",
exchange=="SIX Swiss Exchange" ~ "SW",
exchange=="Six Swiss Exchange Ag" ~ "SW",
exchange=="Standard-Classica-Forts" ~ "ME",
exchange=="Taiwan Stock Exchange" ~ "TW",
exchange=="Tel Aviv Stock Exchange" ~ "TA",
exchange=="Tokyo Stock Exchange" ~ "T",
exchange=="Toronto Stock Exchange" ~ "TO",
exchange=="Wiener Boerse Ag" ~ "VI",
exchange=="XBSP" ~ "SA",
exchange=="Xetra" ~ "DE"))
ixus$ticker <- str_replace_all(ixus$ticker, "[^[:alnum:]]", "")
ixus$xticker = str_c(ixus$ticker, ixus$xch, sep = ".")
hk_tickers <- as.vector(ixus_hk[,18]) %>%
na.omit
adr_tickers <- as.vector(ixus_adr[,1]) %>%
na.omit()
intl_tickers <- as.vector(ixus[,18]) %>%
na.omit()
ixus_hk %>%
select(xticker,equity,price,currency,sector,location)
ixus_adr %>%
select(ticker,equity,price,currency,sector,location)
ixus %>%
select(xticker,equity,price,currency,sector,location)
hk_data <- tq_get(hk_tickers, 
get = "stock.prices",
from = t0,
to = t1)
adr_data <- tq_get(adr_tickers, 
get = "stock.prices",
from = t0,
to = t1)
intl_data <- tq_get(intl_tickers, 
get = "stock.prices",
from = t0,
to = t1)

如果有人认为这可以更有效或更恰当地完成,请随时给我发信息或在这个帖子上发帖。

雅虎免责声明:

雅虎金融搜索并非为搜索而设计:

  • 分析师
  • ISIN代码
  • CEO姓名

雅虎的首页返回数据,这并不意味着api中的搜索引擎会返回数据。对ISIN代码的搜索大多属于经纪人。您可以使用来自交互式代理的API(可能通过ibrokers包(,但最有可能的是,您需要为一些数据流付费。

相关内容

  • 没有找到相关文章

最新更新