AlphaVantage.jl v0.1

Dec 23, 2017 · 376 words · 2 minutes read alpha vantagefinancejuliapackagesstock market

AlphaVantage.jl is a Julia package for the Alpha Vantage API, a free API for stock and cryptocurrency time series data. AlphaVantage.jl provides functions that wrap the API endpoints to Julia functions.

Note: Endpoints for stock time series data, foreign exchange rates, and cryptocurrencies have been fully implemented but technical indicators are underdevelopment.

Quick tutorial

Although the Alpha Vantage API is free you are required to register and use an API key. Start by getting a free API key from Alpha Vantage and set it as an environment variable, ALPHA_VANTAGE_API_KEY.

Install the package using Pkg.clone("git://") as it is not yet registered. Then import the package.

using AlphaVantage

Stock Time Series

You can access stock time series data using one of the time_series_* functions, where * corresponds to one of four temporal resolutions: intraday, daily, weekly, or monthly.

For example, the following function retrieves daily time series for the S&P 500.

gspc = time_series_daily("^GSPC");
Base.KeyIterator for a Dict{String,Any} with 2 entries. Keys:
  "Time Series (Daily)"
  "Meta Data"

The functions returns a Dict with data and metadata. Unfortunately the Dict key corresponding to the requested data is different for different methods; in the example above gspc has the keys Time Series (Daily) and Meta Data however the key for the data would be Time Series (1min) if you used the time_series_intraday function. Therefore you may want to pass datatype="csv" to return an array.

Digital Currencies

The Alpha Vantage API provides price and volume quotes for 392 cryptocurrencies. The functions to access this data is similar to that of the stock market data functions above.

If you want to request data for multiple cryptocurrencies you can use Julia’s dot syntax:

coins = ["btc", "eth", "ltc"]
cryptodata = digital_currency_intraday.(coins, datatype="csv")

In this example cryptodata is an array of arrays containing the intraday price and volume.

Example: Plotting the S&P 500

using AlphaVantage
using DataFrames
using StatPlots
gr(size=(800, 470))

# Get daily S&P 500 data
gspc = time_series_daily("^GSPC", datatype="csv");

# Convert to a DataFrame
data = DataFrame(gspc[2:end, :]);

# Add column names
names!(data, convert.(Symbol, gspc[1,:]));

# Convert timestamp column to Date type
data[:timestamp] = Dates.Date.(data[:timestamp]);

# Plot the timeseries
@df data plot(:timestamp, [:close],
             label=["Close"], xlabel="Date", ylabel="Price",
             ylims=(2400, 2700),
             colour=[:red], fill=(0, 0.25, :red), w=2,
             title="S&P 500 Closing Price", legend=false,
             yformatter=y -> "\$$(string(Int(y)))")