# Load packages
# Core
library(tidyverse)
library(tidyquant)
Examine how each asset contributes to portfolio standard deviation. This is to ensure that our risk is not concentrated in any one asset.
# Choose stocks
symbols <- c("AAPL", "NVDA", "ADBE", "AVGO", "AMD")
# Using tq_get() ----
prices <- tq_get(x = symbols,
get = "stock.prices",
from = "2012-12-31",
to = "2023-12-13")
asset_returns_tbl <- prices %>%
# Calculate monthly returns
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
type = "log") %>%
slice(-1) %>%
ungroup() %>%
# remane
set_names(c("asset", "date", "returns"))
# period_returns = c("yearly", "quarterly", "monthly", "weekly")