alphavantager: An R interface to the Free Alpha Vantage Financial Data API
Written by Matt Dancho
We’re excited to announce the
alphavantager package, a lightweight R interface to the Alpha Vantage API! Alpha Vantage is a FREE API for retreiving real-time and historical financial data. It’s very easy to use, and, with the recent glitch with the Yahoo Finance API, Alpha Vantage is a solid alternative for retrieving financial data for FREE! It’s definitely worth checking out if you are interested in financial analysis. We’ll go through the
alphavantager R interface in this post to show you how easy it is to get real-time and historical financial data. In the near future, we have plans to incorporate the
tidyquant to enable scaling from one equity to many.
If you like what you read, please follow us on social media to stay up on the latest Business Science news, events and information! As always, we are interested in both expanding our network of data scientists and seeking new clients interested in applying data science to business and finance. If interested, contact us.
Alpha Vantage is a free service that enables users to get real-time and historical equity data. New users will need to visit Alpha Vantage and obtain an API key.
R Interface: Getting Started
alphavantager package provides a convenient and lightweight interface to the Alpha Vantage API.
To get started, install the package from CRAN or from GitHub:
Load the package.
Set your API key (get one from Alpha Vantage if you don’t already have one… it’s free).
Getting Financial Data from Alpha Vantage
Now, you’re ready to get financial data via
av_get(), which accepts the same1 arguments as the API Documentation parameters. The function is setup with two primary arguments,
av_fun, which accepts an equity and one of the API “function” parameters. You can pass additional API parameters via the
av_get() for a test spin!
Time Series Data
We can get real-time intraday stock data by setting
av_fun = "TIME_SERIES_INTRADAY" and the
interval to one of the available resolutions (“1min”, “5min”, “15min”, “30min” or “60min”). We can also get daily, daily adjusted, weekly and monthly time series. Note that only 100 rows are returned by default, add the parameter
outputsize = "full" to get the full number of rows.
A full suite of real-time and historical technical indicators are available. The “SMA” (Simple Moving Average) is shown below.
Various real-time and historical sector performances are available.
Important Notes: av_get()
For the most part, the
av_get() function works the same as the Alpha Vantage API Parameters. However, users will want to understand a few important aspects to the R interface:
av_funargument replaces the API parameter “function” because function is a reserved name in R. All other arguments match the Alpha Vantage API parameters.
There is no need to specify the
apikeyparameter as an argument to
av_get(). The required method is to set the API key using
There is no need to specify the
datatypeparameter as an argument to
av_get(). The function will return a tibble data frame.
Some data sets only return 100 rows by default. Change the parameter
outputsize = "full"to get the full dataset.
We have plans to integrate
tidyquant, which will enable scaling from one equity to many! The change will be incorporated into
tq_get(), the one-stop shop for getting financial data. It’s coming soon!!!
We have a full suite of data science services to supercharge your organizations financial and business performance! For example, our experienced data scientists reduced a manufacturer’s sales forecasting error by 50%, which led to improved personnel planning, material purchasing and inventory management.
How do we do it? With team-based data science: Using our network of data science consultants with expertise in Marketing, Forecasting, Finance, Human Resources and more, we pull together the right team to get custom projects done on time, within budget, and of the highest quality. Learn about our data science services or contact us!
We are growing! Let us know if you are interested in joining our network of data scientist consultants. If you have expertise in Marketing Analytics, Data Science for Business, Financial Analytics, Forecasting or data science in general, we’d love to talk. Contact us!