library(BatchGetSymbols) library(tidyverse) tickers <- GetSP500Stocks()$Tickers first_date <- Sys.Date() - 3*365 last_date <- Sys.Date() df_stocks <- BatchGetSymbols(tickers = tickers, first.date = first_date, last.date = last_date)[[2]] df_sp500 <- BatchGetSymbols(tickers = '^GSPC', first.date = first_date, last.date = last_date)[[2]] idx <- match(df_stocks$ref.date, df_sp500$ref.date) df_stocks$ret_mkt <- df_sp500$ret.closing.prices[idx] # calculate PLM beta library(plm) # estimate panel data model with fixed effects my_pdm <- plm(data = df_stocks, formula = ret.adjusted.prices ~ ret_mkt, model = 'within', index = c('ticker')) # print result print(summary(my_pdm))
# none #my_answers <- make_random_answers(my_sol) my_answers <- rep(NA, 5)
For previously imported data, estimate a panel data version for the market model (beta). In this version, each stock has a different intercept, but they share the same beta. Is the estimated beta significant at 5%?
extype: string
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.