# Load packages
library(tidyverse)
library(tidyquant)
# Download symbols of DOW index
symbols <- tq_index(x = "DOW") |>
filter(company != "US DOLLAR")
# Download prices of DOW index constituents
prices <- tq_get(x = symbols, get = "stock.prices",
from = "2000-01-01", to = "2022-12-31")
# Calculate returns
returns <- prices |>
group_by(symbol) |>
mutate(ret = adjusted / lag(adjusted) - 1) |>
select(symbol, date, ret) |>
drop_na(ret)
Maintainers of tidy-finance.org