Free Data: Alternative to Yahoo Finance

Alpha Vantage have an API that offers free data. They have intraday data which spans the last 10 to 15 days at resolutions of 1min, 5min, 15min, 30min, 60min.

Daily, weekly, and monthly data which spans the past 20 years.

We can use R to interact with the aplha advantage API. We use the fread() command from the data.table package to directly download data to a data frame within R.

Note: insert your own Alpha Vantage API code inside the URL

require(lubridate)
require(data.table)
require(dplyr)
GE <- fread("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=GE&outputsize=full&apikey=YOUR_API_KEY_HERE&datatype=csv") #fread() data.table for downloading directly to a data frame
GE$timestamp <- ymd(GE$timestamp)   #Lubridate to change character date to date format
GE <- arrange(GE,timestamp)   #dplyr to sort data frame by date ascending order 

#Plot GE Data
plot(GE$timestamp,GE$close,type="l",main="Alpha Vantage - GE Close Prices")

alpha.vantage.GE

There are different variables that go into the alpha advantage URL and for full usage you may visit the documentation page.

Download Multiple .csv Files To Hard Drive

If we want to download multiple files at one time. We can self specify them in a vector and use a loop to download each file name in that vector.


# Download multiple .csv files to hard drive
# Self specify symbols in a vector
file.list <- c("DDM","MVV","QLD","SAA","SSO","TQQQ","UDOW","UMDD","UPRO","URTY","UWM", "BIB", "FINU","LTL","ROM", "RXL", "SVXY","UBIO","UCC","UGE","UPW","URE","USD","UXI","UYG","UYM","DOG","DXD","MYY","MZZ","PSQ","QID","RWM","SBB","SDD","SDOW","SDS","SH","SPXU","SQQQ","SRTY","TWM","SMDD","UVXY","VIXM","VIXY")

for (i in 1 : length(file.list)) {
  file.name.variable <-  file.list[i]
  url <- paste0("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=",file.name.variable,"&outputsize=full&apikey=YOUR_API_KEY_HERE&datatype=csv")
               destfile <- paste0("D:/R Projects/",
                                  file.name.variable, ".csv")
               download.file(url, destfile, mode="wb")

fread("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=GE&outputsize=full&apikey=YOUR_API_KEY_HERE&datatype=csv")
}

Or if we can find a list of symbols online we can import those into R and iterate through each symbol and download each file to our hard drive.

Import 1700 ETF Symbols From Nasdaq.com – Download .csv To Hard Drive

In this case we can read an ETF list of 1700 symbols from nasdaq.com.
Then we can download each symbol to our hard drive:

# Read ETF list csv file from nasdaq.com
# Use fread() from data.table package
# install.packages("data.table")
require(data.table)
read.data <- fread("http://www.nasdaq.com/investing/etfs/etf-finder-results.aspx?download=Yes")

# Make vector of symbol names
symbol.names <- read.data$Symbol

# Count Total ETF tickers
NROW(symbol.names)

for (i in 1 : length(symbol.names)) {
  file.name.variable <-  symbol.names[i]
  url <- paste0("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=",file.name.variable,"&outputsize=full&apikey=YOUR_API_CODE_HERE&datatype=csv")
  destfile <- paste0("D:/R Projects/",
                     file.name.variable, ".csv")
  download.file(url, destfile, mode="wb")
}

Also to note.. you may import a symbol list from your hard drive. The same principal applies.

Author: Andrew Bannerman

Integrity Inspector. Quantitative Analysis is a favorite past time.

One thought on “Free Data: Alternative to Yahoo Finance”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s