The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
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
<- 'GM'
my_ticker <- Sys.Date() - 30
first_date <- Sys.Date()
last_date
# fetch data
<- yf_get(tickers = my_ticker,
df_yf 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_h…¹ price…² price…³ volume price…⁴ ret_ad…⁵
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GM 2023-01-17 36.5 37.1 36.2 36.6 1.39e7 36.6 NA
## 2 GM 2023-01-18 37.1 37.5 36.4 36.4 1.13e7 36.4 -0.00464
## 3 GM 2023-01-19 35.7 36.0 35.1 35.7 1.14e7 35.7 -0.0195
## 4 GM 2023-01-20 35.7 36.0 35.3 35.3 1.72e7 35.3 -0.0106
## 5 GM 2023-01-23 35.7 36.6 35.5 36.4 1.70e7 36.4 0.0308
## 6 GM 2023-01-24 36 36.7 35.8 36.2 1.21e7 36.2 -0.00659
## # … with 2 more variables: ret_closing_prices <dbl>,
## # cumret_adjusted_prices <dbl>, and abbreviated variable names ¹price_high,
## # ²price_low, ³price_close, ⁴price_adjusted, ⁵ret_adjusted_prices
library(yfR)
library(ggplot2)
<- c('TSLA', 'GM', 'MMM')
my_ticker <- Sys.Date() - 100
first_date <- Sys.Date()
last_date
<- yf_get(tickers = my_ticker,
df_yf_multiple first_date = first_date,
last_date = last_date)
<- ggplot(df_yf_multiple, aes(x = ref_date, y = price_adjusted,
p color = ticker)) +
geom_line()
p
library(yfR)
library(ggplot2)
library(dplyr)
<- 'GE'
my_ticker <- '2005-01-01'
first_date <- Sys.Date()
last_date
<- yf_get(tickers = my_ticker,
df_dailly
first_date, last_date, freq_data = 'daily') %>%
mutate(freq = 'daily')
<- yf_get(tickers = my_ticker,
df_weekly
first_date, last_date, freq_data = 'weekly') %>%
mutate(freq = 'weekly')
<- yf_get(tickers = my_ticker,
df_monthly
first_date, last_date, freq_data = 'monthly') %>%
mutate(freq = 'monthly')
<- yf_get(tickers = my_ticker,
df_yearly
first_date, last_date, freq_data = 'yearly') %>%
mutate(freq = 'yearly')
# bind it all together for plotting
<- bind_rows(
df_allfreq 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
<- ggplot(df_allfreq, aes(x = ref_date, y = price_adjusted)) +
p geom_line() +
facet_grid(freq ~ ticker) +
theme_minimal() +
labs(x = '', y = 'Adjusted Prices')
print(p)
library(yfR)
library(ggplot2)
<- c('TSLA', 'GM', 'MMM')
my_ticker <- Sys.Date() - 100
first_date <- Sys.Date()
last_date
<- yf_get(tickers = my_ticker,
df_yf_multiple first_date = first_date,
last_date = last_date)
print(df_yf_multiple)
## # A tibble: 204 × 11
## ticker ref_date price_open price_…¹ price…² price…³ volume price…⁴ ret_ad…⁵
## * <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GM 2022-11-08 39.5 39.5 38.5 39.0 1.09e7 39.0 NA
## 2 GM 2022-11-09 38.5 38.9 38.0 38.1 1.05e7 38.0 -0.0254
## 3 GM 2022-11-10 39.2 40.6 38.9 39.7 2.02e7 39.7 0.0441
## 4 GM 2022-11-11 39.9 41.6 39.8 41.1 1.30e7 41.0 0.0347
## 5 GM 2022-11-14 41.0 41.2 39.9 39.9 1.50e7 39.8 -0.0289
## 6 GM 2022-11-15 40.7 41.4 40.0 40.2 1.24e7 40.2 0.00776
## 7 GM 2022-11-16 39.8 39.9 38.5 38.5 1.20e7 38.4 -0.0440
## 8 GM 2022-11-17 38.0 39.6 37.5 38.6 2.60e7 38.6 0.00442
## 9 GM 2022-11-18 39.5 40.0 39.0 39.8 2.28e7 39.7 0.0292
## 10 GM 2022-11-21 39.4 39.7 39 39.5 1.23e7 39.4 -0.00629
## # … with 194 more rows, 2 more variables: ret_closing_prices <dbl>,
## # cumret_adjusted_prices <dbl>, and abbreviated variable names ¹price_high,
## # ²price_low, ³price_close, ⁴price_adjusted, ⁵ret_adjusted_prices
<- yf_convert_to_wide(df_yf_multiple)
l_wide
names(l_wide)
## [1] "price_open" "price_high" "price_low"
## [4] "price_close" "volume" "price_adjusted"
## [7] "ret_adjusted_prices" "ret_closing_prices" "cumret_adjusted_prices"
<- l_wide$price_adjusted
prices_wide head(prices_wide)
## # A tibble: 6 × 4
## ref_date GM MMM TSLA
## <date> <dbl> <dbl> <dbl>
## 1 2022-11-08 39.0 124. 191.
## 2 2022-11-09 38.0 122. 178.
## 3 2022-11-10 39.7 128. 191.
## 4 2022-11-11 41.0 131. 196.
## 5 2022-11-14 39.8 130. 191.
## 6 2022-11-15 40.2 130. 194.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.