| Title: | 'Alphavantage Financial Data' API R Wrapper and Shiny Interface |
|---|---|
| Description: | Download, manage, and visualize via Shiny App 'Alphavantage financial data' <https://www.alphavantage.co/documentation/>. Data is downloaded into `data.table`s using one parameterized function. Results can be piped to optional helper functions to extract and simplify more complex data. A Shiny interface is also provided to download, manage, analyze and visualize market data. |
| Authors: | Derek Holmes [aut, cre, cph] |
| Maintainer: | Derek Holmes <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.9.22 |
| Built: | 2026-11-04 01:44:54 UTC |
| Source: | https://github.com/derekholmes0/alphavantagepf |
An R interface to the Alpha Vantage API which emphasizes normalized data nd data.table conventions
The alphavantagepf 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 avpf_api_key("YOUR_KEY") to set the API key and the av_get_pf()
function to get financial data.
Adds a user-defined function to the av Shiny app
av_add_analytic( runcode, func_name, helpstr = "user function", focus = "MAIN", data_req = "pxd;earn;earnest", message_str = "", delay_save_state = FALSE )av_add_analytic( runcode, func_name, helpstr = "user function", focus = "MAIN", data_req = "pxd;earn;earnest", message_str = "", delay_save_state = FALSE )
runcode |
Code string user must run to call the function. |
func_name |
Name of function run when analytic is called. If an empty string is supplied, the runcode will be de-registered. |
helpstr |
(default: "user function"): A string comment to ad to the av.h (help) command |
focus |
(default: "MAIN") String with tab name to set focus to when command is run |
data_req |
(default: "pxd;earn;earnest") A semicolon list of required data tables. Used for Lazy data loading. |
message_str |
(default "") Additional string to add to output messages |
delay_save_state |
(default: FALSE) Do not save state to cache files. Used for speed optimization |
Adds or removes a new command to the av_runShiny app
When the av_runShiny() app is run, users can call functions to provide analytics based on asset strings in the command line.
This function allows users to add their own analytics by registering a function which takes, as inputs
todo: The command line and any subsequent parameters as a space delimited string
rv: Reactive values supplied by the Shiny app. In particular the parameter rv$istr1 contains the semicolon delimited set of assets
prior to the command invocation.
The registered function should return a (possibly named, see vignette)
list containing one or more gt() tables, dygraphs(), or ggplots() to be displayed when the command is run. See vignette for specfic details
The function specified must be available (i.e in .GlobalENv()) to the Shiny app when the command is run. Otherwise an error message will be displayed.
If the specified command has already been registered, a message will be given and the internal data will be overridden.
String message with success or failure of function addition.
## Not run: my_testfunc <- function(todo,rv) { message("todO: ",todo," with asset string ",rv$istr1) n_to_return <- c(strsplit(todo," "),"3")[[2]] |> as.numeric() table1 <- head(mtcars,n_to_return) |> gt() table2 <- data.table(asset=strsplit(rv$istr1,";")) |> gt() plot1 <- ggplot(mtcars,aes(mpg,disp)) + geom_point() return(list(table1, table2, plot1)) } av_add_analytic("TEST","my_testfunc",helpstr="a test func") # From the app; run "QQQ;SPY test 5" # From the app: run "av.h" ## End(Not run)## Not run: my_testfunc <- function(todo,rv) { message("todO: ",todo," with asset string ",rv$istr1) n_to_return <- c(strsplit(todo," "),"3")[[2]] |> as.numeric() table1 <- head(mtcars,n_to_return) |> gt() table2 <- data.table(asset=strsplit(rv$istr1,";")) |> gt() plot1 <- ggplot(mtcars,aes(mpg,disp)) + geom_point() return(list(table1, table2, plot1)) } av_add_analytic("TEST","my_testfunc",helpstr="a test func") # From the app; run "QQQ;SPY test 5" # From the app: run "av.h" ## End(Not run)
Adds asset lists to av_runShiny() internal data.
av_add_assetgroups(indta)av_add_assetgroups(indta)
indta |
A data.frame with a minimum of two columns |
Add Asset Groups
Lists are specified in normalized form. Duplicate list names with those currently in use are replaced.
Nothing
## Not run: newtickers <- c("QQQ","QQQE","NDX") av_add_assetgroups(data.table(listnm=rep("nasdaq",length(newtickers)),ticker=newtickers)) # To remove an asset list, just use an empty string for the ticker av_add_assetgroups(data.table(listnm=c("new"),ticker=c(""))) ## End(Not run)## Not run: newtickers <- c("QQQ","QQQE","NDX") av_add_assetgroups(data.table(listnm=rep("nasdaq",length(newtickers)),ticker=newtickers)) # To remove an asset list, just use an empty string for the ticker av_add_assetgroups(data.table(listnm=c("new"),ticker=c(""))) ## End(Not run)
Adds earnings data to av_runShiny() internal data, either by download or with user data
av_add_earn( substitute_earn = NULL, substitute_earnest = NULL, equitylist = NULL, delay = 0 )av_add_earn( substitute_earn = NULL, substitute_earnest = NULL, equitylist = NULL, delay = 0 )
substitute_earn |
A (default NULL) data.frame with past earnings |
substitute_earnest |
(default NULL) A data.frame with earnings estimates |
equitylist |
(default NULL) A list with tickers for which to retrieve earnings (from AlphaVantage) |
delay |
(default 0) A numeric value specifying delay between Alphavantage calls (in seconds) |
Add Earnings Data
Entire set of columns from av_get_pf() can be added. First date column renamed to timestamp.
If just assetypes is given, the function downloads earnings as needed (respecting maximum age parameters defined
in the app's AVOPTS tab.)
Note that price data must always be added first
Data.table with summary of downloaded or added earnings
## Not run: # To add earnings for a set of tickers av_load_shinydata() # Make sure most recent data is loaded av_add_earn(equitylist=data.table(symbol=c("IBM","GS"))) ## End(Not run)## Not run: # To add earnings for a set of tickers av_load_shinydata() # Make sure most recent data is loaded av_add_earn(equitylist=data.table(symbol=c("IBM","GS"))) ## End(Not run)
Manages option database and creates vol surfaces
av_add_options( todo, dtstr = "-1w::", symbols = NULL, freq = "d", replace_data = FALSE, baddates_limits = 3, verbosity = "basic", external_path = NULL )av_add_options( todo, dtstr = "-1w::", symbols = NULL, freq = "d", replace_data = FALSE, baddates_limits = 3, verbosity = "basic", external_path = NULL )
todo |
What to do to add options. Choices are in the table below
|
||||||||||||
dtstr |
(default |
||||||||||||
symbols |
(default: NULL) List of symbols to download |
||||||||||||
freq |
(Default |
||||||||||||
replace_data |
(Default |
||||||||||||
baddates_limits |
(default 3): Consecutive business days of null data beyond which options are assumed not to exist. |
||||||||||||
verbosity |
(default
|
||||||||||||
external_path |
(default NULL) Path from which to replace existing data |
Manage option data
This function can take a long time to run. Full option quotes are stored by symbol in arrow/parquet format by symbol day, and contract.
Unless replace_data==TRUE, only dates and symbols that need to be downloaded will.
Except the OS S function, all analytics run in the app require options data to be downloaded using this function.
nothing
Adds price data to av_runShiny() internal data.
av_add_px(indta = NULL, assettypes = NULL, equitylist = NULL, dtstr = "-30y::")av_add_px(indta = NULL, assettypes = NULL, equitylist = NULL, dtstr = "-30y::")
indta |
(default: NULL) A data.frame with the following minimal columns: |
assettypes |
(default NULL) An optional data.frame with minimal columns |
equitylist |
(default NULL) If specified, function will get equity prices from |
dtstr |
(default |
Entire set of columns from av_get_pf() can be added. First date column renamed to timestamp internally.
Nothing
## Not run: # To add known symbols outside the app av_load_shinydata() # Make sure most recent data is loaded av_add_px(equitylist=c("IBM","GS","JPM")) # To add ad-hoc data from Alphavantage (e.g. Natgas spot at Henry Hub) # Note that "symbol" in indta must match same in assettypes asset_df <- data.frame(symbol=c("GAS_HH"),type=c("user"),currency=c("USD"), name=c("GAS_HH")) ng_data <- av_get_pf("","NATURAL_GAS")[,.(symbol="GAS_HH",timestamp,close=value)] av_add_px(ng_data, assettypes=asset_df) # To data from other sources suppressMessages(require(quantmod)) ffdta <- as.data.table(quantmod::getSymbols("FEDFUNDS",src="FRED",auto.assign=FALSE)) ffdta <- ffdta[,.(DT_ENTRY=index,close=FEDFUNDS,adjusted_close=FEDFUNDS,symbol="FEDFUNDS")] av_add_px(ffdta) ## End(Not run)## Not run: # To add known symbols outside the app av_load_shinydata() # Make sure most recent data is loaded av_add_px(equitylist=c("IBM","GS","JPM")) # To add ad-hoc data from Alphavantage (e.g. Natgas spot at Henry Hub) # Note that "symbol" in indta must match same in assettypes asset_df <- data.frame(symbol=c("GAS_HH"),type=c("user"),currency=c("USD"), name=c("GAS_HH")) ng_data <- av_get_pf("","NATURAL_GAS")[,.(symbol="GAS_HH",timestamp,close=value)] av_add_px(ng_data, assettypes=asset_df) # To data from other sources suppressMessages(require(quantmod)) ffdta <- as.data.table(quantmod::getSymbols("FEDFUNDS",src="FRED",auto.assign=FALSE)) ffdta <- ffdta[,.(DT_ENTRY=index,close=FEDFUNDS,adjusted_close=FEDFUNDS,symbol="FEDFUNDS")] av_add_px(ffdta) ## End(Not run)
av_extract_df() pulls out nested data.frames from mixed data returned by av_get_pf()
av_extract_fx() returns a simplified FX quote in data.table formfrom av_get_pf() calls.
av_extract_analytics() returns melted data.table from calls to av_get_pf("ANALYTICS_FIXED_WINDOW") or av_get_pf("ANALYTICS_SLIDING_WINDOW")
av_extract_divs_or_splits() returns melted data.table from calls to av_get_pf("DIVIDENDS") or av_get_pf("SPLITS")
av_extract_df(indta, grepstring = "", melt = FALSE, empty_dt_onerror = TRUE) av_extract_fx(indta, outputform = "common", cols = "", empty_dt_onerror = TRUE) av_extract_analytics(indta, separate_vars = FALSE, empty_dt_onerror = TRUE) av_extract_divs_or_splits(indta, empty_dt_onerror = TRUE)av_extract_df(indta, grepstring = "", melt = FALSE, empty_dt_onerror = TRUE) av_extract_fx(indta, outputform = "common", cols = "", empty_dt_onerror = TRUE) av_extract_analytics(indta, separate_vars = FALSE, empty_dt_onerror = TRUE) av_extract_divs_or_splits(indta, empty_dt_onerror = TRUE)
indta |
A data.table as returned by av_get() |
grepstring |
select which variable (data item) to unnest in data.table returned from av_get_pf |
melt |
Return data in melted/normalized form |
empty_dt_onerror |
(default : TRUE): Return gracefully an empty data.table if requested item is not present. |
outputform |
(default : |
cols |
(default : all columns: |
separate_vars |
(default : FALSE) separate out multiple levels of variable names into new keys |
av_get_pf() frequently returns a nested data.table, or a structure with nested data.frames. These are utilities functions to extract, filter and summarize returned values.
if av_get_pf() returns a valid response, but empty extracted data.tables, am empty data.table() will be returned
NOTE: (Change 20260724: Timestamp is returned in POSIXct form in local Sys.timezone() time)
Extracted data.tables for nested data returned from av_get_pf(), If grepstring is not specified, first nested table is returned. av_extract_fx() returns a shortened data.table with FX quotes.
## Not run: av_get_pf("","MARKET_STATUS") |> av_extract_df() av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers") av_get_pf("USD/BRL","CURRENCY_EXCHANGE_RATE") |> av_extract_fx() av_get_pf(c("ORCL","IBM"),"ANALYTICS_FIXED_WINDOW") |> av_extract_analytics(separate_vars=TRUE) ## End(Not run)## Not run: av_get_pf("","MARKET_STATUS") |> av_extract_df() av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers") av_get_pf("USD/BRL","CURRENCY_EXCHANGE_RATE") |> av_extract_fx() av_get_pf(c("ORCL","IBM"),"ANALYTICS_FIXED_WINDOW") |> av_extract_analytics(separate_vars=TRUE) ## End(Not run)
Extract data from Alpha Vantage retuned data
av_funhelp(av_fun_grep = "", verbose = TRUE)av_funhelp(av_fun_grep = "", verbose = TRUE)
av_fun_grep |
A Alpha Vantage function name or portions of one. For a list of parameters, visit the Alpha Vantage API documentation. |
verbose |
(Default: TRUE) Prints the help string |
Returns defaults and parameter lists for Alphavantage functions
Help Text and default parameters.
av_funhelp("GLOBAL_QUOTE")av_funhelp("GLOBAL_QUOTE")
Interface to alphavantage API.
av_get_pf( symbol, av_fun, symbolvarnm = "symbol", dfonerror = TRUE, melted = "default", delay = 0, verbose = FALSE, ... )av_get_pf( symbol, av_fun, symbolvarnm = "symbol", dfonerror = TRUE, melted = "default", delay = 0, verbose = FALSE, ... )
symbol |
A character string of an appropriate stock, fund, or currency 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. |
symbolvarnm |
(default: |
dfonerror |
(default: TRUE) Return an empty data.table when any error occurs |
melted |
(default: "default") String specifying when to melt, "default" is chosen by the package, "TRUE|always" always melt, "FALSE|never" never melts |
delay |
(default: 0) Delay in seconds after API call, used to embed within large single-symbol calls. If delay <=0 then delays are scheduled to keep within the request pace specified in |
verbose |
(default: FALSE) Print debug information helpful for errors. Also copies full url to clipboard. |
... |
Additional parameters or overrides passed to the Alpha Vantage API. For a list of parameters, visit the Alpha Vantage API documentation. |
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, datatype, outputsize or entitlement parameters as arguments to av_get_pf(). Before using, you must set the API key using av_api_key("YOUR_API_KEY"). outputsize defaults to "full" unless overridden with "compact in ...."
Required parameters other than symbol must be passed as named arguments via ....
Optional parameters have defaults which can be obtained by calling av_funhelp() and overridden via ....
There is no need to specify the datatype parameter as an argument to av_get_pf(). The function will return a data.table.
ForEx "FROM/TO" symbol details. FOREX symbols in the av_get_pf() 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_pf("USD/BRL", "FX_DAILY")
Returns a data.table with results dependent on the function called. Mixed data is returned as a melted data.table, possibly with nested data.frames. Time series are returned as data.tables.
avpf_api_key(), av_extract_df(), av_extract_fx(), av_grep_opts(),av_funhelp(), avpf_set_request_pace()
## Not run: avpf_api_key("YOUR_API_KEY","delayed") # or "realtime" if you have such access # example code # ---- 1.0 SINGLE NAME EQUITY SUMMARY INFORMATION AND SEARCH ---- av_get_pf("IBM","OVERVIEW") |> str() av_get_pf("EWZ","ETF_PROFILE") av_get_pf("EWZ","ETF_PROFILE") |> av_extract_df("holdings") av_get_pf("","SYMBOL_SEARCH",keywords="COMMERCE") # ---- 2.0 MARKET QUOTES ---- av_get_pf("IBM","GLOBAL_QUOTE") av_get_pf("USD/BRL","CURRENCY_EXCHANGE_RATE") |> av_extract_fx() av_get_pf(c("ORCL","IBM","EWZ","ARGT"),"REALTIME_BULK_QUOTES",melt=FALSE) # Note you need advanced permissioning for REALTIME_BULK_QUOTES # ---- 3.0 SINGLE NAME HISTORICAL DATA ---- av_get_pf("IBM","TIME_SERIES_DAILY") av_get_pf("IBM","TIME_SERIES_INTRADAY") # ---- 4.0 MARKET PRICING DATA ---- av_get_pf("","MARKET_STATUS") |> av_extract_df() av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers") av_get_pf("","TREASURY_YIELD",maturity='7year') # ---- 4.0 SINGLE NAME NON-PRICING DATA ---- av_get_pf("IBM","DIVIDENDS") av_get_pf("IBM","EARNINGS") |> av_extract_df("quarter",melt=TRUE) av_get_pf("IBM","NEWS_SENTIMENT") |> av_extract_df("feed") av_get_pf("IBM","EARNINGS_CALL_TRANSCRIPT",quarter="2024Q3") |> av_extract_df("transcript") # Note that quarter is a required parameter, not specifying will throw an error # ---- 5.0 SINGLE NAME OPTION PRICING DATA ---- av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2) # ---- 6.0 TECHNICAL INDICATORS ---- av_funhelp("SMA") # Shows parameters and defaults chosen by this package. av_get_pf("IBM","SMA",time_period=20) # ---- 7.0 WINDOW ANALYTICS ---- av_get_pf(c("ORCL","IBM","EWZ","ARGT"),"ANALYTICS_FIXED_WINDOW",verbose=TRUE) |> av_extract_analytics(separate_vars=TRUE) ## End(Not run)## Not run: avpf_api_key("YOUR_API_KEY","delayed") # or "realtime" if you have such access # example code # ---- 1.0 SINGLE NAME EQUITY SUMMARY INFORMATION AND SEARCH ---- av_get_pf("IBM","OVERVIEW") |> str() av_get_pf("EWZ","ETF_PROFILE") av_get_pf("EWZ","ETF_PROFILE") |> av_extract_df("holdings") av_get_pf("","SYMBOL_SEARCH",keywords="COMMERCE") # ---- 2.0 MARKET QUOTES ---- av_get_pf("IBM","GLOBAL_QUOTE") av_get_pf("USD/BRL","CURRENCY_EXCHANGE_RATE") |> av_extract_fx() av_get_pf(c("ORCL","IBM","EWZ","ARGT"),"REALTIME_BULK_QUOTES",melt=FALSE) # Note you need advanced permissioning for REALTIME_BULK_QUOTES # ---- 3.0 SINGLE NAME HISTORICAL DATA ---- av_get_pf("IBM","TIME_SERIES_DAILY") av_get_pf("IBM","TIME_SERIES_INTRADAY") # ---- 4.0 MARKET PRICING DATA ---- av_get_pf("","MARKET_STATUS") |> av_extract_df() av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers") av_get_pf("","TREASURY_YIELD",maturity='7year') # ---- 4.0 SINGLE NAME NON-PRICING DATA ---- av_get_pf("IBM","DIVIDENDS") av_get_pf("IBM","EARNINGS") |> av_extract_df("quarter",melt=TRUE) av_get_pf("IBM","NEWS_SENTIMENT") |> av_extract_df("feed") av_get_pf("IBM","EARNINGS_CALL_TRANSCRIPT",quarter="2024Q3") |> av_extract_df("transcript") # Note that quarter is a required parameter, not specifying will throw an error # ---- 5.0 SINGLE NAME OPTION PRICING DATA ---- av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2) # ---- 6.0 TECHNICAL INDICATORS ---- av_funhelp("SMA") # Shows parameters and defaults chosen by this package. av_get_pf("IBM","SMA",time_period=20) # ---- 7.0 WINDOW ANALYTICS ---- av_get_pf(c("ORCL","IBM","EWZ","ARGT"),"ANALYTICS_FIXED_WINDOW",verbose=TRUE) |> av_extract_analytics(separate_vars=TRUE) ## End(Not run)
Filter options from returned AV data
av_grep_opts( indta, grepstring = "F,M,C,otm", spot = NULL, mindays = 3, startdt = Sys.Date(), mindelta = 0.05, dropsymbol = FALSE )av_grep_opts( indta, grepstring = "F,M,C,otm", spot = NULL, mindays = 3, startdt = Sys.Date(), mindelta = 0.05, dropsymbol = FALSE )
indta |
A data.table as returned by |
||||||||||||||||||
grepstring |
(default
|
||||||||||||||||||
spot |
(default |
||||||||||||||||||
mindays |
(default 3). Minimum number of days to expiration to be passed through from |
||||||||||||||||||
startdt |
(default |
||||||||||||||||||
mindelta |
(default |
||||||||||||||||||
dropsymbol |
(default |
Alphavantage doesn't always return quarterly options
av_get_pf() returns a large list of options. This function helps to narrow down the list by maturity and moneyness.
A reduced set of options obtained from av_get_pf() using Alphavantage HISTORICAL_OPTIONS function.
## Not run: av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2) ## End(Not run)## Not run: av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2) ## End(Not run)
Loads internal data (prices, earnings, etc.
av_load_shinydata(item = NULL, verbose = TRUE, addfuncs = TRUE)av_load_shinydata(item = NULL, verbose = TRUE, addfuncs = TRUE)
item |
Any data name as seen by running |
verbose |
(default TRUE) write a status message to console |
addfuncs |
(default TRUE) Readd and re-source any user defined functions |
restore_lazy |
(default FALSE) Also restore all lazy data |
Load ShinyApp data from Cache
Data item specified by item or a nothing (but a message) if left blank
Extract data from Alpha Vantage retuned data
av_make_funcmap()av_make_funcmap()
Creates a data.table with API signatures and default values for Alphavantage API calls
function map dat.table, also written to data directory
## Not run: av_make_funcmap() ## End(Not run)## Not run: av_make_funcmap() ## End(Not run)
Add additional columns to returned option sets
av_opt_helper_cols(indta, scaling = NULL, spot_override = NULL)av_opt_helper_cols(indta, scaling = NULL, spot_override = NULL)
indta |
An option data.table as returned by |
scaling |
(default
|
spot_override |
(default |
Adds columns including
| Column | Definition |
daysExp |
Days to Expiration |
bo_pct |
Bid offer in percent of option mid |
bid_size_poi |
Bid size percent of open interest |
ncak |
Notional number of contracts |
An option data.table with extra columns helpful for further analysis
## Not run: av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2) |> av_opt_helper_cols() ## End(Not run)## Not run: av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2) |> av_opt_helper_cols() ## End(Not run)
Extract data from Alpha Vantage retuned data
av_reset_defaults(fileopts = TRUE, keep_apikeys = FALSE, resetgrep = "*")av_reset_defaults(fileopts = TRUE, keep_apikeys = FALSE, resetgrep = "*")
fileopts |
(default: TRUE) If TRUE, then remove all files and subdirectories |
keep_apikeys |
(default: FALSE) Keep whatever API keys are stored |
resetgrep |
(default "*") Only reset grepped default variables |
Resets av_runShiny() defaults to original (newly installed) state
No return
## Not run: av_reset_defaults() ## End(Not run)## Not run: av_reset_defaults() ## End(Not run)
av_runShiny() runs an interactive RShiny app with a professional command line interface to download, manage, and visualize data from
the Alpha Vantage data service.
The app treats equities, ETFs, indices, and FX equally, so users do not need to know specific API calls to integrate data. Downloaded data is cached to reduce
API calls, all data can be saved for external use, and both external data and external commands (that call user functions) can be added to the app.
Sets of securities can be easily added and managed.
av_runShiny()av_runShiny()
Invocation starts Shiny application. See vignettes for full details.
On first use, In the AVOPTS tab, fill in the following fields, and hit the "Set Opts" button.
AV API Key: API key obtained from Alpha Vantage
Entitlement Entitlement status (either delayed or realtime)
Other options that can be set are given below.
To get data and run analyses: Enter in the top yellowed line a semicolon delimited set of securities (Equity, ETF, FX, Crypto, indices) followed by a command to run analytics on those securities. Commands without securities are always prefixed by '"AV.". The results are shown as tables, plots, or dygraphs below the command line, and possibly in an additional tab to the right of the main tab. The secondary tab will change names as approprriate, and the focus may be changed off the MAIN tab.
Commands are not case sensitive, and may refer to a counterasset in the second yellowed line. A few examples include:
| Command | Description |
AV.H |
List all available functions |
AV.INV |
Inventory of all available data |
AV.TICKERS |
Inventory of indices and crypto pairs available from Alpha Vantage |
SPACE S |
Search for all tickers with SPACE in their names |
IBM;QQQ;NDX;USD/MXN GPI |
Produce a rebased time series graph of the securities |
IBM;QQQ GV |
Time series graph of rolling volatiliies |
ibm;qqq rv |
Relative Value /Active Return Analysis |
IBM;AAPL;USD/MXN Q |
Table of latest prices for each instrument |
USD/BRL;USD/MXN SCATI |
Scatterplot of rebased levels and returns |
IBM;AAPL EA |
Table of Earnings data for each instrument |
IBM;AAPL CN |
Table of recent news items for each asset, with links |
IBM;AAPL RV |
Graph of excess returns over counterasset (SPY by default) |
IBM OS F,M,P,otm |
Search for (e.g.) Out of the money front month puts |
If an analysis requires price, dividend or earnings data that is not in the app's internal store, then it will download it as necessary from Alpha Vantage. Other data (e.g. News, options) are downloaded freshly each time. One of the key contributions of this app is to abstract out the asset-specific functions calls that are necessary to do cross-asset analyses.
Other niceties:
Groups of assets can be named, saved, and recalled easily. The saved name can then be used in lieu of the original list. See Basic Usage vignette
Internal data can be stored and used (as data.table()s) in a directory of the users' choosing. See Options vignette
to set the directory, and the Data vignette for details on how the data is structured.
Events and other plotting options can be specified in the app. See functions vignette and e.g. FinanceGraphs
Data within each produced graph or table can be copied to the clipboard (option in AVOPTS page), See Setup vignette to see where to turn this on.
Raw downloaded data can be saved into a "dump directory" (option in AVOPTS page)
A current inventory list is always kept in a separate tab, avoiding having to run AV.INV repeatedly.
User price data, earnings data, and asset groups can be added using helper functions av_add_px(), av_add_earn(), av_add_assetgroups(). See data vignette.
Adding data from the console immediately adds the data to the app.
User analytics can be added using av_add_analytic(). See examples in the Extensions vignette
Nothing
A ShinyAppHandle object.
## Not run: av_runShiny() ## End(Not run)## Not run: av_runShiny() ## End(Not run)
Adds analytics in code taken from single directory.
av_runShiny_addFunctions(fun_dir = NULL)av_runShiny_addFunctions(fun_dir = NULL)
fun_dir |
Directory containing functions with input signatures to add |
Add a set of analytics from a code direcory
Each file will be read in the specified directory and any function with a valid signature will be added to the list of available functions in the shiny app. The function signature is a call to the function with a single argument "signature" which returns a list of four items:
a short name for the function,
the function name,
a help string for the function.
A semicolon delimited list of data tables necessary to run the function. Used for Lazy Loading
If those conditions obtain, the function will be added to av_runShiny()
Nothing
retrieves internal data state of av_runShiny()
dump_state(typegrep="*")
dump_inv(invgrep="*")
dump_assetgroups()
dump_captured(todo="byfunction")
av_shiny_px()
dump_state(stategrep = "*", trunc_length = 35) dump_inv(invgrep = "*") dump_assetgroups() dump_av_funcs() dump_captured(todo = "byfunction")dump_state(stategrep = "*", trunc_length = 35) dump_inv(invgrep = "*") dump_assetgroups() dump_av_funcs() dump_captured(todo = "byfunction")
stategrep |
: Grep string for internal state parameters, either a class or a name |
trunc_length |
: (default: 35) Maximumlength of character values returned. |
invgrep |
: A regular expression string |
todo |
: One of c("byfunction","pxhist",any av function name) |
Return av_runShiny data and states
data.table with desired data.
## Not run: `dump_state()` `dump_inv()` `dump_av_funcs()` `dump_assetgroups()` `dump_captured(todo="byfunction")` ## End(Not run)## Not run: `dump_state()` `dump_inv()` `dump_av_funcs()` `dump_assetgroups()` `dump_captured(todo="byfunction")` ## End(Not run)
avpf_api_key() sets Alphavantage API key and entitlement code
avpf_api_key(api_key, entitlement = NULL)avpf_api_key(api_key, entitlement = NULL)
api_key |
A character string with your Alpha Vantage API Key. |
entitlement |
An optional character string with your Alpha Vantage entitlement status. If not "delayed" or "realtime" entitlement not added to API string. |
The Alpha Vantage API key must be set prior to using av_get_pf(). You can obtain
an API key at the Alpha Vantage Website.
Invisibly returns two item list with API key and entitlement string once set). Use print method to view.
## Not run: avpf_api_key("YOUR_API_KEY",entitlement="delayed") av_get_pf("IBM", "TIME_SERIES_INTRADAY") ## End(Not run)## Not run: avpf_api_key("YOUR_API_KEY",entitlement="delayed") av_get_pf("IBM", "TIME_SERIES_INTRADAY") ## End(Not run)
avpf_set_request_pace() sets Alphavantage API key and entitlement code
avpf_set_request_pace(max_requests_per_min = 60)avpf_set_request_pace(max_requests_per_min = 60)
max_requests_per_min |
(default 60) Maximum requests per minute |
Change this if you have a better plan with AlphaVantage
Nothing
Copies a data.frame to the clipboard, with a status message if relevant
avsh_clipboard(x, title = "")avsh_clipboard(x, title = "")
x |
A |
title |
String to add to a message printed if relevant |
Copy data to clipboard
Nothing
Displays a message underneath an input box
avsh_quick_message(this_message, eval = TRUE, color = "#1f78b4")avsh_quick_message(this_message, eval = TRUE, color = "#1f78b4")
this_message |
(default "") A text message to be used. If empty string, the current message is cleared. |
eval |
(default TRUE) OPtional parameter to suppress execution. |
color |
Optional text color |
Display a user message in the av_runShiny app
logical value of eval
Sets the title for the Details tab
avsh_set_tabtitle(newtext = "DETAIL", tabnm = "detail", makefocus = TRUE)avsh_set_tabtitle(newtext = "DETAIL", tabnm = "detail", makefocus = TRUE)
newtext |
(default"DETAIL") What to name the tab as |
tabnm |
(default "detail") inputID of relevant tab |
makefocus |
(default: TRUE) Upon setting the tab title, select the tab. |
Set an av_runShiny Tab Title
Nothing
Adds default elements to gt() table
gt.basetheme( x, gtopts = "all", sizepct = 100, style = 4, digits = 2, interactive_mult = 1.14, seps = FALSE, na_format = "-", size = "", interactive = "" )gt.basetheme( x, gtopts = "all", sizepct = 100, style = 4, digits = 2, interactive_mult = 1.14, seps = FALSE, na_format = "-", size = "", interactive = "" )
x |
Input data or |
gtopts |
Which elements to add |
sizepct |
(default: 70) How big to make tables |
style |
(default: 4) Style number (see |
digits |
(default: 2) Number formatting |
interactive_mult |
(default: 80/70) Multtiple of |
seps |
(default: FALSE) Number formatting thousands separators |
na_format |
(default: "-") WHat to show for NAs |
size |
(default: "") Size of text, either |
interactive |
(default: "") String with interative elements: contains one of |
Prints message if condition met
message_if(reallydothis, ...)message_if(reallydothis, ...)
reallydothis |
Condition to be met |
... |
Additional items to be passed to |