Processing and Analyzing Financial Data with R by Marcelo S. Perlin

Processing and Analyzing Financial Data with R by Marcelo S. Perlin

Author:Marcelo S. Perlin [S. Perlin, Marcelo]
Language: eng
Format: azw3
Published: 2017-05-01T04:00:00+00:00


## ticker src download.status total.obs ## 1 MSFT yahoo OK 21 ## 2 GOOGL yahoo OK 21 ## 3 JPM yahoo OK 21 ## 4 GE yahoo OK 21 ## perc.benchmark.dates threshold.decision ## 1 1 KEEP ## 2 1 KEEP ## 3 1 KEEP ## 4 1 KEEP

Object df.control shows all tickers were valid, and we got 21 observations (rows) for each.

As for the actual financial data, it is contained in element df.tickers of l.out. Let's look:

# print df.tickers print(tail(l.out$df.tickers))

## price.open price.high price.low price.close volume ## 79 29.45 29.60 29.32 29.45 39764600 ## 80 29.52 29.55 29.26 29.26 36606000 ## 81 29.29 29.31 29.02 29.08 32777900 ## 82 29.10 29.16 28.93 28.99 23929100 ## 83 29.01 29.17 28.93 28.94 23695700 ## 84 29.01 29.05 28.91 28.99 31475900 ## price.adjusted ref.date ticker ## 79 29.45 2017-04-25 GE ## 80 29.26 2017-04-26 GE ## 81 29.08 2017-04-27 GE ## 82 28.99 2017-04-28 GE ## 83 28.94 2017-05-01 GE ## 84 28.99 2017-05-02 GE

As expected, the information about prices and volume is there. Notice it also includes a column, called ticker, containing the symbols of the stocks. Later, in chapter 9, we will use this column to make calculations for each stock in our dataset.

Another useful function of BatchGetSymbols is GetSP500Stocks, which imports the current composition of the SP500 index, including the tickers of the stocks. So, by using GetSP500Stocks and BatchGetSymbols together, you can easily download a large amount of stock data for the US market. Consider the following chunk of code, where we performed such operation:

library(BatchGetSymbols) # set tickers my.tickers <- GetSP500Stocks()$ticker # set dates first.date <- Sys.Date()-30 last.date <- Sys.Date() l.out <- BatchGetSymbols(tickers = my.tickers, first.date = first.date, last.date = last.date)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.