[R-SIG-Finance] Interaction with Alpha Vantage?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Nov 6 19:37:45 CET 2017


On 06/11/2017 10:41 AM, Dirk Eddelbuettel wrote:
> 
> Credit where credit is due---the 'tidyquant' folks first mentioned it, but it
> in the fullest and most glorious tradition of the tibbliesverse require half
> a dozen or more other packages for not apparent reason.  So I followed up
> with a quick tweet on Sep 5 about a one-liner not needing anything else
> besides data.table: >
>    https://twitter.com/eddelbuettel/status/905066349294219264
> 
> and cooked up a helper function in a so-far-unreleased package of personal
> functions (this one is below) which I shared with at least Josh.  The larger
> function added to quantmod is AFAIK contributed by Paul.
> 
> Now, as for interchaning with them: Nope. I too need ETFs, Canadian stocks
> and whatnot for the little personal finance app I have had as a daily cronjob
> since the 1990s (and been meaning to rewrite in R since then too as it is,
> gasp, Perl -- see eg https://github.com/eddelbuettel/beancounter and other
> online resources). It may now be time to rewrite this as the underlying
> (Perl) data grabber Finance::YahooQuote is now dead due to Yahoo! walking
> away from that API.  I have an unpublished R-based drop-in replacement for
> just the data gathering ...
> 
> Anyway, alphavantage looks good.  We should test it some more.

I'm not so sure.  I haven't noticed any problems in their data (though I 
haven't done extensive testing), but in my opinion it is a bad sign if 
there's no way to contact them.

Duncan

> 
> Dirk
> 
> 
> 
> ##' Fetch a real-time market data series from AlphaVantage
> ##'
> ##' Several optional parameters could be set, but are not currently.
> ##' @title Retrieve real-time data from AlphaVantage
> ##' @param sym Character string value for the ticker
> ##' @param datatype Character string value for the supported type of data, currently one of
> ##' \dQuote{intraday}, \dQuote{daily}, \dQuote{adjdaily}, \dQuote{weekly}, \dQuote{monthly}.
> ##' @param outputsize Character string value, one of \dQuote{compact} or \dQuote{full}. Applies
> ##' only daily or intraday data.
> ##' @return A data.table object
> ##' @author Dirk Eddelbuettel
> alphavantage <- function(sym,
>                           datatype=c("intraday", "daily", "adjdaily", "weekly", "monthly"),
>                           outputsize=c("compact", "full")) {
>      datatype <- match.arg(datatype)
>      outputsize <- match.arg(outputsize)
>      datatypeArg <- switch(datatype,
>                            intraday = "TIME_SERIES_INTRADAY",
>                            daily    = "TIME_SERIES_DAILY",
>                            adjdaily = "TIME_SERIES_DAILY_ADJUSTED",
>                            weekly   = "TIME_SERIES_WEEKLY",
>                            monthly  = "TIME_SERIES_MONTHLY")
> 
>      cmd <- paste0("https://www.alphavantage.co/query?",
>                    "function=", datatypeArg, "&",
>                    "symbol=", sym, "&",
>                    "interval=1min&",
>                    "apikey=", getOption("alphavantageKey", "demo"), "&",
>                    "datatype=csv&")
>      if (datatype %in% c("intraday", "daily", "adjdaily")) {
>          cmd <- paste0(cmd, "outputsize=", outputsize)
>      }
>      #print(cmd)
>      data <- data.table::fread(cmd, showProgress=FALSE)
> }
> 
>



More information about the R-SIG-Finance mailing list