[R-SIG-Finance] Accessing getSymbols data

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Dec 11 17:56:34 CET 2009


>From ?getSymbols:

Details:

     'getSymbols' is a wrapper to load data from different sources - be
     them local or remote. Data is fetched through one of the available
     'getSymbols' methods and saved in the 'env' specified - the
     .GlobalEnv by default. Data is loaded in much the same way that
     'load' behaves. By default, it is assigned automatically to a
     variable in the specified environment, _without_ the user
     explicitly assigning the returned data to a variable.

     The previous sentence's point warrants repeating - getSymbols is
     called for its side effects, and _does not_ return the data object
     loaded. The data is ‘loaded’ silently by the function into a new
     environment by default - or the environment specified. This
     behavior can be overridden by setting auto.assign to FALSE, though
     it is not advised.

Best,
Josh
--
http://www.fosstrading.com



On Fri, Dec 11, 2009 at 10:51 AM, Nick Torenvliet
<n_torenvliet at hotmail.com> wrote:
>
> I'm working with the following code:
>
>        atmpt <- try(table <- getSymbols(yahooSymbol))
>        options(show.error.messages = TRUE)
>        if(inherits(atmpt, "try-error"){
>        } else {
>            # insert data from table here
>            for (i in 1:length(table)){
>                sql <- paste("Insert into ", myDBSymbol," (dayDate, dayOpen, dayHigh, dayLow, dayClose, dayVolume, dayAdjustment) values (",index(table[i]),",",  table[i,],",", table[i,2],",", table[i,3],",", table[i,4],",", table[i,5],",", symbolData[i,6],")")
>                atmpt <- try(dbGetQuery( con, sql))
>                options(show.error.messages = TRUE)
>                if(inherits(dataEntry, "try-error")){
>                    dataEntry <- NA
>                } else {
>                }
>            }
>        }
>
> I imagine you can see a heap of errors in the code above but my first problem is that I'm not accessing the data returned from getSymbols properly and the insert statement fails on bad data.
>
> AAB.TO happens to be the value of  yahooSymbol, from the R prompt I get
>
>> length(AAB.TO)
> [1] 4452
>> length(table)
> [1] 1
>> length(yahooSymbol)
> [1] 1
>
> Accessing AAB.TO is easy enough, but the code is part of a loop where the symbol in yahooSymbol changes each iteration, can anyone help me to access the values returned by getSymbol dynamically as by the insert statement above?
>
> Regards,
>
> Nick
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list