R: Getting Yahoo Finance data with a brand-new library, yfR ver. 1

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.

(New R package yfR)

II. Fetch data

I have fetched data and created some plots with RStudio Cloud.

Sample 1

# 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:

https://rstudio.cloud/project/3829335

To be continued.

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.