Created
December 1, 2021 09:57
-
-
Save dchakro/0b3a11f490c622acf6ff221f25c782f3 to your computer and use it in GitHub Desktop.
R function to parse historical quotes from markets.ft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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