library(BatchGetSymbols) ticker <- '^GSPC' first_date <- '1950-01-01' last_date <- '2021-01-01' df_SP500 <- BatchGetSymbols(tickers = '^GSPC', first.date = first_date, last.date = last_date)[[2]] select_n <- 5 tab <- dplyr::tibble(position = 1:select_n, top5_positive = sort(df_SP500$ret.adjusted.prices, decreasing = TRUE)[1:select_n], top5_negative = sort(df_SP500$ret.adjusted.prices, decreasing = FALSE)[1:select_n]) print(tab) my_sol <- sum(tab$top5_positive)
# none my_answers <- make_random_answers(my_sol)
Use the BatchGetSymbols
package to download the SP500 index data ('^GSPC'
) from r first_date
to r last_date
. What is the sum of the r select_n
highest positive returns on the index?
exams::answerlist(my_answers, markup = "markdown")
extype: schoice
exsolution: r mchoice2string(c(TRUE, FALSE, FALSE, FALSE, FALSE), single = TRUE)
exname: "function 01"
exshuffle: TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.