Last Updated on April 4, 2022 by shibatau
I. What is yfR?
The author says:
Package BatchGetSymbols facilitates importation of Yahoo Finance data directly into R and is one of my most popular R packages, with over 100k installations since conception (around 2500 downloads per month). However, I developed BatchGetSymbols back in 2016, with many bad structural choices from my part.
For years I wanted to improved the code but always restrained myself because I did not want to mess up the execution of other people’s code that was based on BatchGetSymbols. In order to implement all the breaking changes and move forward with the package, I decided to develop a new (and fresh) package called yfR.
II. Fetch data
I have fetched data and created some plots with RStudio Cloud.
# install devtools install.packages("devtools") # Github (dev version) devtools::install_github('msperlin/yfR') # install libraries install.packages("scales") install.packages("ggplot2") # import libraries library(yfR) library(ggplot2) # set options for algorithm ticker <- 'FB' first_date <- Sys.Date() - 360 last_date <- Sys.Date() # fetch data fb <- yf_get(tickers = ticker, first_date = first_date, last_date = last_date) # show the table head(fb) # create a line plot p <- ggplot(fb, aes(x = ref_date, y = price_adjusted, color = ticker)) + geom_line() p
You can see the script here:
To be continued.