Skip to content

Instantly share code, notes, and snippets.

@dchakro
Created December 1, 2021 09:57
Show Gist options
  • Save dchakro/0b3a11f490c622acf6ff221f25c782f3 to your computer and use it in GitHub Desktop.
Save dchakro/0b3a11f490c622acf6ff221f25c782f3 to your computer and use it in GitHub Desktop.
R function to parse historical quotes from markets.ft
# R function to parse historical quotes from markets.ft
# 1) Go to URL for your traded instrument e.g. https://markets.ft.com/data/etfs/tearsheet/historical?s=SPPY:FRA:EUR
# 2) Set date range
# 3) Copy the quotes to a text file
# 4) Use marketsFT_parse (pass the text file as argument) to get quotes
marketsFT_parse <- function(FILE=NULL){
dat <- data.table::fread(FILE)
if (colnames(dat)[1] != "Date"){
colnames(dat) <- c("Date","Open","High","Low","Close","Volume")
}
dat$Date <-
lubridate::as_date(dat$Date, format = "%A, %B %d, %Y")
write.table(
x = dat[, .(Date, Close)],
file = gsub(".txt", ".csv", FILE),
sep = ",",
quote = F,
row.names = F,
col.names = F
)
}
marketsFT_parse("~/Desktop/dat.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment