Learn R Programming

quantmod (version 0.4.25)

getSymbols.av: Download OHLC Data from Alpha Vantage

Description

Downloads historical or realtime equity price data from https://www.alphavantage.co/. Free registration is required.

Usage

getSymbols.av(Symbols, env, api.key,
              return.class = "xts",
              periodicity = "daily",
              adjusted = FALSE,
              interval = "1min",
              output.size = "compact",
              data.type = "json",
              ...)

Value

A call to getSymbols(Symbols, src="av") will create objects in the specified environment, one object for each Symbol specified. The object class of the object(s) is determined by return.class. Presently this may be "ts", "zoo", "xts", or "timeSeries".

Arguments

Symbols

a character vector specifying the names of the symbols to be loaded

env

where to create objects (environment)

api.key

the API key issued by Alpha Vantage when you registered (character)

return.class

class of returned object, see Value (character)

periodicity

one of "daily", "weekly", "monthly", or "intraday"

adjusted

if TRUE, include a column of closing prices adjusted for dividends and splits

interval

one of "1min", "5min", "15min", "30min", or "60min" (intraday data only)

output.size

either "compact" or "full"

data.type

either "json" or "csv"

...

additional parameters as per getSymbols

Author

Paul Teetor

Details

Meant to be called internally by getSymbols only. This method is not meant to be called directly, instead a call to getSymbols("x", src="av") will in turn call this method. It is documented for the sole purpose of highlighting the arguments accepted.

You must register with Alpha Vantage in order to download their data, but the one-time registration is fast and free. Register at their web site, https://www.alphavantage.co/, and you will receive an API key: a short string of alphanumeric characters (e.g., "FU4U"). Provide the API key every time you call getSymbols; or set it globally using setDefaults(getSymbols.av, api.key="yourKey").

The Alpha Vantage site provides daily, weekly, monthly, and intraday data. Use periodicity to select one. Note that intraday data will includes today's data (delayed) if downloaded while the market is open, which is pretty cool.

Set adjusted=TRUE to include a column of closing prices adjusted for dividends and stock splits (available only for daily, weekly, and monthly 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 bars, 5 minutes bars, 15 minutes bars, etc.

By default Alpha Vantage returns the 100 most-recent data points (output.size="compact"). Set output.size="full" to obtain the entire available history. For daily, weekly, and monthly data, Alpha Vantage says the available data is up to 20 years; for intraday data, the available history is the most recent 10 or 15 days. Be forewarned that downloading full data requires more time than compact data, of course.

Alpha Vantage provides access to data via two APIs. You can choose the API via the data.type argument. data.type="json", the default, will import data using the JSON API. This API includes additional metadata (e.g. last updated time, timezone, etc) that is not provided via the CSV API.

References

Alpha Vantage documentation available at https://www.alphavantage.co/

See Also

getSymbols, getSymbols.yahoo, getSymbols.google

Examples

Run this code
if (FALSE) {
# You'll need the API key given when you registered
getSymbols("IBM", src="av", api.key="yourKey")

# The default output.size="compact" returns only the most recent 100 rows.
# Set output.size="full" for all available data.
getSymbols("IBM", src="av", api.key="yourKey", output.size="full")

# Intraday data is available for the most recent 10 or 15 days
# and includes quasi-realtime data (i.e., 20-minute delayed)
getSymbols("IBM", src="av", api.key="yourKey", output.size="full",
  periodicity="intraday")

# Repeating your API key every time is tedious.
# Fortunately, you can set a global default.
setDefaults(getSymbols.av, api.key="yourKey")
getSymbols("IBM", src="av")
}

Run the code above in your browser using DataLab