# Libraries
library(timetk, exclude = "FANG")
library(forcats)
library(dplyr)
# --- Basic Usage ----
SUM(1:10)
PCT_CHANGE_FIRSTLAST(c(21, 24, 22, 25))
# --- Usage with tidyverse ---
# Go from daily to monthly periodicity,
# then calculate returns and growth of $1 USD
FANG %>%
mutate(symbol = forcats::as_factor(symbol)) %>%
group_by(symbol) %>%
# Summarization - Collapse from daily to FIRST value by month
summarise_by_time(
.date_var = date,
.by = "month",
adjusted = FIRST(adjusted)
)
Run the code above in your browser using DataLab