library(httr2) # Read both funds' files; each has the date of its own issuer's file funds <- list() for (ticker in c("VOO", "QQQ")) { url <- paste0("https://tickerinside.com/api/v1/fund/", tolower(ticker), ".json") funds[[ticker]] <- request(url) |> req_user_agent("MyProject/1.0 (+https://example.com)") |> req_perform() |> resp_body_json() writeLines(paste(ticker, "holdings_as_of", funds[[ticker]]$holdings_as_of)) } # Overlap by weight, as the site computes it: for every ticker both funds # hold, add the smaller of its two weights a <- unlist(funds$VOO$holdings) b <- unlist(funds$QQQ$holdings) shared <- intersect(names(a), names(b)) overlap <- sum(pmin(a[shared], b[shared])) writeLines(sprintf("overlap by weight %.1f%%, %d companies in both", overlap, length(shared))) # The lines to print under the figure, one per fund file for (fund in funds) writeLines(fund$cite_as)