Skip to content

Instantly share code, notes, and snippets.

@iangow
Created September 13, 2017 09:36
Show Gist options
  • Save iangow/9a04743ffe0fc2003e62bdb7edadad96 to your computer and use it in GitHub Desktop.
Save iangow/9a04743ffe0fc2003e62bdb7edadad96 to your computer and use it in GitHub Desktop.
Code to get ASX 300 constituents
fix_names <- function(df) {
names(df) <- c("ticker", "company", "sector", "mkt_cap", "weight")
df
}
get_asx_300 <- function(date) {
url <- paste0("https://www.asx300list.com/uploads/csv/",
format(as.Date(date), "%Y%m%d"),
"-asx300.csv")
df <-
suppressMessages(suppressWarnings(read_csv(url, skip=1))) %>%
select(1:5) %>%
fix_names() %>%
mutate(date = as.Date(date)) %>%
arrange(desc(mkt_cap)) %>%
mutate(rank = row_number()) %>%
select(date, everything())
df
}
dates <- seq(from=as.Date("2017-01-01"), by="month", length=9)
df <-
bind_rows(lapply(dates, get_asx_300))
asx_100 <-
df %>%
filter(rank <= 100) %>%
arrange(desc(date), desc(mkt_cap))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment