Обновление: я вроде понял это ... но он не работает отлично. Мне, вероятно, придется разбивать каждый обмен и формат, как я делал для Гонконга, чтобы он мог искать финансы Yahoo. По сути, мне нужно было добавить «.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)
Если кто-то думает, что это можно сделать более эффективно или правильно, пожалуйста, не стесняйтесь сообщать мне или оставлять сообщения в этой теме.