Here you’ll find a series of example of calls to
yf_get(). Most arguments are self-explanatory, but you can
find more details at the help files.
The steps of the algorithm are:
library(yfR)
# set options for algorithm
my_ticker <- 'GM'
first_date <- Sys.Date() - 30
last_date <- Sys.Date()
# fetch data
df_yf <- yf_get(tickers = my_ticker,
first_date = first_date,
last_date = last_date)
# output is a tibble with data
head(df_yf)## # A tibble: 6 × 11
## ticker ref_date price_open price_high price_low price_close volume
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GM 2026-02-04 86.2 87.6 85.3 86.3 8838900
## 2 GM 2026-02-05 85.2 85.7 83.3 83.3 9142700
## 3 GM 2026-02-06 83.5 84.7 82.6 84.2 8052700
## 4 GM 2026-02-09 82.3 82.4 80.6 80.7 9766800
## 5 GM 2026-02-10 81.1 81.5 79.4 80.3 7425800
## 6 GM 2026-02-11 80.5 82 79.1 79.8 9654400
## # ℹ 4 more variables: price_adjusted <dbl>, ret_adjusted_prices <dbl>,
## # ret_closing_prices <dbl>, cumret_adjusted_prices <dbl>
library(yfR)
library(ggplot2)
my_ticker <- c('TSLA', 'GM', 'MMM')
first_date <- Sys.Date() - 100
last_date <- Sys.Date()
df_yf_multiple <- yf_get(tickers = my_ticker,
first_date = first_date,
last_date = last_date)
p <- ggplot(df_yf_multiple, aes(x = ref_date, y = price_adjusted,
color = ticker)) +
geom_line()
plibrary(yfR)
library(ggplot2)
library(dplyr)
my_ticker <- 'GE'
first_date <- '2005-01-01'
last_date <- Sys.Date()
df_dailly <- yf_get(tickers = my_ticker,
first_date, last_date,
freq_data = 'daily') %>%
mutate(freq = 'daily')
df_weekly <- yf_get(tickers = my_ticker,
first_date, last_date,
freq_data = 'weekly') %>%
mutate(freq = 'weekly')
df_monthly <- yf_get(tickers = my_ticker,
first_date, last_date,
freq_data = 'monthly') %>%
mutate(freq = 'monthly')
df_yearly <- yf_get(tickers = my_ticker,
first_date, last_date,
freq_data = 'yearly') %>%
mutate(freq = 'yearly')
# bind it all together for plotting
df_allfreq <- bind_rows(
list(df_dailly, df_weekly, df_monthly, df_yearly)
) %>%
mutate(freq = factor(freq,
levels = c('daily',
'weekly',
'monthly',
'yearly'))) # make sure the order in plot is right
p <- ggplot(df_allfreq, aes(x = ref_date, y = price_adjusted)) +
geom_line() +
facet_grid(freq ~ ticker) +
theme_minimal() +
labs(x = '', y = 'Adjusted Prices')
print(p)library(yfR)
library(ggplot2)
my_ticker <- c('TSLA', 'GM', 'MMM')
first_date <- Sys.Date() - 100
last_date <- Sys.Date()
df_yf_multiple <- yf_get(tickers = my_ticker,
first_date = first_date,
last_date = last_date)
print(df_yf_multiple)## # A tibble: 201 × 11
## ticker ref_date price_open price_high price_low price_close volume
## * <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GM 2025-11-26 72.4 73.4 72.2 72.8 7704300
## 2 GM 2025-11-28 72.9 73.9 72.9 73.5 3755000
## 3 GM 2025-12-01 73.1 73.9 72.9 72.9 9826900
## 4 GM 2025-12-02 73.2 73.8 72.1 73.7 8973700
## 5 GM 2025-12-03 73.6 74.9 73.6 74.7 8392400
## 6 GM 2025-12-04 75 76.2 74.9 75.3 12659100
## 7 GM 2025-12-05 75.1 77 75 76.1 8817800
## 8 GM 2025-12-08 76.3 76.7 75.2 75.7 10018200
## 9 GM 2025-12-09 76.1 77.3 75.9 77.2 7970100
## 10 GM 2025-12-10 77.2 80.9 77.1 80.8 14421300
## # ℹ 191 more rows
## # ℹ 4 more variables: price_adjusted <dbl>, ret_adjusted_prices <dbl>,
## # ret_closing_prices <dbl>, cumret_adjusted_prices <dbl>
## [1] "price_open" "price_high" "price_low"
## [4] "price_close" "volume" "price_adjusted"
## [7] "ret_adjusted_prices" "ret_closing_prices" "cumret_adjusted_prices"
## # A tibble: 6 × 4
## ref_date GM MMM TSLA
## <date> <dbl> <dbl> <dbl>
## 1 2025-11-26 72.7 170. 427.
## 2 2025-11-28 73.4 171. 430.
## 3 2025-12-01 72.8 170. 430.
## 4 2025-12-02 73.5 171. 429.
## 5 2025-12-03 74.5 172. 447.
## 6 2025-12-04 75.1 169. 455.