joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
809 stars 223 forks source link

add default handling to getQuote #291

Closed ethanbsmith closed 3 years ago

ethanbsmith commented 4 years ago

Description

Some of the getQuote functions do not import defaults

Expected behavior

missing in: getQuote (master function) getQuote.yahoo

helgasoft commented 3 years ago

Results are confusing. Docs say in setDefaults(name...), name = name of function, quoted or unquoted. Here is what happens with AV.

setDefaults(getQuote.av, api.key='xxx')
# Error in setDefaults(getQuote.av, api.key = "xxx") :   object 'getQuote.av' not found
setDefaults('quantmod:::getQuote.av', api.key='xxx')
# Error in get(fun, mode = "function", envir = envir) :   object 'quantmod:::getQuote.av' of mode 'function' was not found
setDefaults('getQuote.av', api.key='xxx')
# works, huh
joshuaulrich commented 3 years ago

@helgasoft Can you help me understand how this relates to the initial report. It looks like a separate issue.

helgasoft commented 3 years ago

Maybe I entered the wrong room. Was searching for issues with getQuote and defaults ... Sorry, I don't really understand what 'import defaults' means.

joshuaulrich commented 3 years ago

Oh, that makes sense. I don't think this is related to the issue you uncovered, so I'd appreciate it if you create a new issue.

For some examples of what Ethan is referring to by "import defaults", you can search for "importDefaults" in getSymbols.R.

A bit more background: setDefaults() and importDefaults() basically let you set global options that are injected into the function call. It allows you to change the default value of an argument for all subsequent calls.

For example, you can set the default "from" date to 1 year ago. Then all your calls to getSymbols() will use that date by default.

setDefaults("getSymbols.yahoo", from = Sys.Date() - 365)
getSymbols("SPY")
head(SPY)
## [1] "SPY"
##            SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
## 2019-10-24   300.91   301.07  299.46    300.37   35453100     294.6716
## 2019-10-25   299.74   302.20  299.68    301.60   45205400     295.8783
## 2019-10-28   302.94   303.85  302.91    303.30   42147000     297.5460
## 2019-10-29   303.00   304.23  302.86    303.21   44284900     297.4577
## 2019-10-30   303.43   304.55  301.99    304.14   49643900     298.3701
## 2019-10-31   304.13   304.13  301.73    303.33   69053800     297.5754