BatchGetSymbols 2.2

[This article was first published on R on msperlin, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

One of the main requests I get for package BatchGetSymbols is to add the choice of frequency of the financial dataset. Today I finally got some time to work on it. I just posted a new version of BatchGetSymbols in CRAN. The major change is that users can now set the time frequency of the financial data: dailly, weekly, monthly or yearly. Let’s check it out:

library(BatchGetSymbols)
## Loading required package: rvest
## Loading required package: xml2
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 
library(purrr)
## 
## Attaching package: 'purrr'
## The following object is masked from 'package:rvest':
## 
##     pluck
library(ggplot2)

my.fct <- function(my.freq) {
  
  df <- BatchGetSymbols(tickers = c('GE'), 
                      first.date = '2010-01-01',
                      last.date = Sys.Date(), do.cache = FALSE,
                      freq.data = my.freq)$df.tickers
  
  df$freq <- my.freq

  return(df)
}

my.possible.freq <-  c('daily', 'weekly', 'monthly', 'yearly')

df.allfreq <- bind_rows(map(.x = my.possible.freq, .f = my.fct))
## 
## Running BatchGetSymbols for:
##    tickers = GE
##    Downloading data for benchmark ticker
## GE | yahoo (1|1) - Good stuff!
## Running BatchGetSymbols for:
##    tickers = GE
##    Downloading data for benchmark ticker
## GE | yahoo (1|1) - Good job!
## Running BatchGetSymbols for:
##    tickers = GE
##    Downloading data for benchmark ticker
## GE | yahoo (1|1) - You got it!
## Running BatchGetSymbols for:
##    tickers = GE
##    Downloading data for benchmark ticker
## GE | yahoo (1|1) - Feels good!
p <- ggplot(df.allfreq, aes(x=ref.date, y = price.adjusted)) + 
  geom_point() + geom_line() + facet_grid(freq ~ ticker)

print(p)

To leave a comment for the author, please follow the link and comment on their blog: R on msperlin.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)