Skip to content
Back to formatted view

Raw Message

Message-ID: <8cca69990912110856q6cbd37c6j51ea65bd19e3ab93@mail.gmail.com>
Date: 2009-12-11T16:56:34Z
From: Joshua Ulrich
Subject: Accessing getSymbols data
In-Reply-To: <BAY143-W110AA33B1A8E6759335BB8FE8C0@phx.gbl>

>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.
>