Skip to content

Incorporate Alpha Vantage as a source of historical equity prices #176

Closed
@pteetor

Description

Description

The Alpha Vantage web service provides real-time and historical equity data. The service is free, requiring only a free, one-time registration. The service provides daily, weekly, and monthly history for both domestic and international markets, with up to 20 years of history. For daily data, adjusted close prices are available to account for dividends and splits. The service can also provide real-time price bars at a resolution of 1 minute or higher, for up to 10 recent days. They have a clean, documented, public API that returns JSON-encoded data.

I propose incorporating Alpha Vantage into getSymbols as a source of historical data, much like Yahoo and Google.

Expected behavior

The caller would invoke the Alpha Vantage downloader through the usual mechanism; i.e.,

getSymbols("IBM", src="av")`.

The associated function, getSymbols.av, would have this signature.

getSymbols.av(Symbols, env, apikey,
                 return.class = "xts",
                 periodicity = "daily",
                 adjusted = FALSE,
                 interval = "1min",
                 outputsize = "compact",
                 ...)
  • Symbols - a character vector specifying the names of the symbols to be loaded
  • env - where to create objects.
  • apikey - the API key issued by Alpha Vantage when you registered (character)
  • return.class - class of returned object
  • periodicity - one of "daily", "weekly", "monthly", or "intraday"
  • adjusted - if TRUE, include a column of closing prices adjusted for dividends and splits (daily data only)
  • interval - one of "1min", "5min", "15min", "30min", or "60min" (intraday data only)
  • outputsize - either "compact" or "full"

You must register with Alpha Vantage in order to download their data, but the on-time registration is fast and free. A.V. will assign an API key to you, a short string of alphanumeric characters (e.g., "FOO4").

You must provide your API key every time you call getSymbols.av. Alternatively, you can set it globally using

setDefaults(getSymbols.av, apikey="yourKey")

The Alpha Vantage site provides daily, weekly, monthly, and intraday data. Use periodicity to select one.

Set adjusted=TRUE to include a column of closing prices adjusted for dividends and stock splits (available only for daily data).

The intraday data is provided as a sequence of OHLC bars. Use the interval argument to determine the "width" of the bars: 1 minute, 5 minutes, 15 minutes, etc.

By default Alpha Vantage returns the 100 most-recent data points. Set outputsize="full" to obtain the entire available history (which requires more download time, of course). Alpha Vantage says they provide up to 20 years of daily data: or the most recent 10 or 15 days of intraday data.

Issues and Limitations

The web service is free, but registration is required. Alpha Vantage provides an API key at registration, and that key is needed to download data.

The A.V. API returns its data via JSON. In my experience, pulling large, historical datasets can be slower than Google or Yahoo (but not crippling slow). At this point, I don't know if the bottleneck is the A.V. server itself or the encoding/decoding process for (inefficient) JSON.

Beyond historical data, the A.V. API can also provide sector performance data and technical indicators (e.g., moving averages). I am not planning to provide access to those data elements. The sector performance stuff is kind of orthogonal to quantmod scope; and the technical indicators are already available via the TTR package.

I believe the intraday data is available only for domestic stocks, not international; but I'm not sure.

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions