Package 'alphavantager'

Title: Lightweight Interface to the Alpha Vantage API
Description: Alpha Vantage has free historical financial information. All you need to do is get a free API key at <https://www.alphavantage.co>. Then you can use the R interface to retrieve free equity information. Refer to the Alpha Vantage website for more information.
Authors: Matt Dancho [aut, cre], Davis Vaughan [aut]
Maintainer: Matt Dancho <[email protected]>
License: GPL (>= 3)
Version: 0.1.3
Built: 2024-09-21 03:08:50 UTC
Source: https://github.com/business-science/alphavantager

Help Index


alphavantager: A lightweight R interface to the Alpha Vantage API

Description

A lightweight R interface to the Alpha Vantage API

Details

The alphavantager package provides a lightweight interface to the Alpha Vantage API. Alpha Vantage is a free source for financial data that in many cases is more accurate than Yahoo Finance and Google Finance. Get a free API KEY at https://www.alphavantage.co. Then use the R interface functions av_api_key("YOUR_KEY") to set the API key and the av_get() function to get financial data.


Set the Alpha Vantage API Key

Description

Set the Alpha Vantage API Key

Usage

av_api_key(api_key)

Arguments

api_key

A character string with your Alpha Vantage API Key.

Details

The Alpha Vantage API key must be set prior to using av_get(). You can obtain an API key at the Alpha Vantage Website.

Value

Invisibly returns API key once set. Use print method to view.

See Also

av_get()

Examples

## Not run: 
av_api_key("YOUR_API_KEY")
av_get(symbol = "MSFT", av_fun = "TIME_SERIES_INTRADAY", interval = "15min", outputsize = "full")

## End(Not run)

Get financial data from the Alpha Vantage API

Description

Get financial data from the Alpha Vantage API

Usage

av_get(symbol, av_fun, ...)

Arguments

symbol

A character string of an appropriate stock or fund. See parameter "symbol" in Alpha Vantage API documentation.

av_fun

A character string matching an appropriate Alpha Vantage "function". See parameter "function" in Alpha Vantage API documentation.

...

Additional parameters passed to the Alpha Vantage API. For a list of parameters, visit the Alpha Vantage API documentation.

Details

The av_fun argument 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 apikey parameter as an argument to av_get(). The required method is to set the API key using av_api_key("YOUR_API_KEY").

There is no need to specify the datatype parameter 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.

Get more than one symbol. The Alpha Vantage API is setup to return one symbol per API call. Use the tidyquant::tq_get() API to get multiple symbols.

ForEx "FROM/TO" symbol details. FOREX symbols in the av_get() function are supplied in "FROM/TO" format, which are then parsed in the Alpha Vantage API into from_currency and to_currency API parameters. Usage example: av_get(symbol = "EUR/USD", av_fun = "FX_DAILY")

Value

Returns a tibble of financial data

See Also

av_api_key()

Examples

## Not run: 

# SETUP API KEY
av_api_key("YOUR_API_KEY")

# ---- 1.0 STOCK TIME SERIES ----

# 1.1 TIME SERIES INTRADAY
av_get("MSFT", av_fun = "TIME_SERIES_INTRADAY", interval = "5min", outputsize = "full")

# 1.2 TIME SERIES DAILY ADJUSTED
av_get("MSFT", av_fun = "TIME_SERIES_DAILY_ADJUSTED", outputsize = "full")

# 1.3 QUOTE ENDPOINTS
av_get("MSFT", av_fun = "GLOBAL_QUOTE")

# ---- 2.0 FOREX ----

# 2.1 CURRENCY EXCHANGE RATES
av_get("EUR/USD", av_fun = "CURRENCY_EXCHANGE_RATE")

# 2.2 FX INTRADAY
av_get("EUR/USD", av_fun = "FX_INTRADAY", interval = "5min", outputsize = "full")

# 2.3. FX DAILY
av_get("EUR/USD", av_fun = "FX_DAILY", outputsize = "full")

# ---- 3.0 TECHNICAL INDICATORS ----

# 3.1 SMA
av_get("MSFT", av_fun = "SMA", interval = "weekly", time_period = 10, series_type = "open")

# ---- 4.0 SECTOR PERFORMANCE ----

# 4.1 Sector Performance
av_get(av_fun = "SECTOR")

## End(Not run)