Skip to content

get.hist.quote

7 messages · genx, Joshua Ulrich, Gabor Grothendieck +2 more

#
All of a sudden get.hist.quote cease to function, i switched to zoo after i
totally failed to get yahooImport to work. I've been using the below R
snippet for weeks without any problems what so ever. 

The error

R> source("OMX.R")
trying URL
'http://chart.yahoo.com/table.csv?s=^OMX&a=2&b=11&c=2005&d=1&e=08&f=2007&g=d&q=q&y=0&z=^OMX&x=.csv'
Content type 'text/csv' length unknown
opened URL
.......... .......... ..
downloaded 22Kb

Error in if (!quiet && dat[n] != start) cat(format(dat[n], "time series
starts %Y-%m-%d\n")) :
        missing value where TRUE/FALSE needed


The R snippet

OMX <- get.hist.quote("^OMX",start=(today <- Sys.Date())-735,quote="Cl")
save(OMX, file="OMX.csv")
#
<snip>
This is because Yahoo recently changed the date format of its CSV files from 
"%d-%m-%y" to "%Y-%m-%d".  All that needs to be changed in 'get.hist.quote' 
is this line of code:
from: dat <- as.Date(dat, "%d-%b-%Y")
to: dat <- as.Date(dat, "%Y-%m-%d")

Other similar functions (e.g. 'yahooImport') will likely have the same 
problem.

_________________________________________________________________
Check out all that glitters with the MSN Entertainment Guide to the Academy 
Awards?   http://movies.msn.com/movies/oscars2007/?icid=ncoscartagline2
#
Here is a kludge that will allow it to work until its fixed:


get.hist.quote <- function(...) {
	as.Date <- function(x, fmt, ...) {
		if (!missing(fmt)) fmt <- "%Y-%m-%d"
		base::as.Date(x, fmt, ...)
	}
	get.hist.quote <- tseries::get.hist.quote
	environment(get.hist.quote) <- environment()
	get.hist.quote(...)
}

# test
ibm <- get.hist.quote("ibm")
On 2/9/07, Josh Ulrich <joshulrich21 at hotmail.com> wrote:
#
Josh Ulrich wrote:
I suspected it was a Yahoo issue, ok, then i know for sure and hope rmetrics
and zoo update the packages to reflect to changes made by finance yahoo.

Thank you for your help, very much appreciated.
#
On 2/9/07, genx <info at genetrix.se> wrote:
This has nothing to do with with the zoo package.  Its a matter of
changing get.hist.quote in the tseries package to handle
the change in yahoo.
1 day later
#
Thanks.  Updated version of tseries on CRAN now.

Best
-k
2 days later
#
I am trying to use the yahooImport() and get the following error for the
default source as

    yahooImport('IBM')
trying URL 'http://chart.yahoo.com/table.csv?IBM'
Error in download.file(url = paste(source, query, sep = ""), destfile =
file,  :
         cannot open URL 'http://chart.yahoo.com/table.csv?IBM'
In addition: Warning message:
cannot open: HTTP status was '404 Not Found'
Error: attempt to apply non-function


Yahoo has changed the source URL to
http://ichart.finance.yahoo.com/table.csv?s=IBM
so the default might need changing as well.

I tried passing the new source as               
    a<-yahooImport('IBM','source=http://ichart.finance.yahoo.com/table.csv?s=')

I had to add s= to the source string.  I now get the following error
trying URL 'http://ichart.finance.yahoo.com/table.csv?s=IBM'
Content type 'text/csv' length unknown
opened URL
downloaded 567Kb

Read 11356 items
Error in matrix(unlist(x2), byrow = TRUE, nrow = length(x2)) :
         matrix: invalid 'ncol' value (< 0)
a now has the 'no internet access' as its value.

I am stuck here.  Any thoughts?

I included yahooImport below for reference

Thank you
Joe





function (query, file = "tempfile", source =
"http://chart.yahoo.com/table.csv?",
     save = FALSE, sep = ";", swap = 20, try = TRUE)
{
     if (try) {
         z = try(yahooImport(file = file, source = source, query = query,
             save = save, try = FALSE))
         if (class(z) == "try-error" || class(z) == "Error") {
             return("No Internet Access")
         }
         else {
             return(z)
         }
     }
     else {
         if (class(version) != "Sversion") {
             method = NULL
         }
         else {
             method = "wget"
         }
         download.file(url = paste(source, query, sep = ""), destfile =
file,
             method = method)
         x1 = rev(scan(file, what = "", skip = 1))
         x2 = strsplit(x1[regexpr("-...-..,", x1) > 0], ",")
         x1 = matrix(unlist(x2), byrow = TRUE, nrow = length(x2))
         z = matrix(as.numeric(x1[, -1]), ncol = dim(x1)[2] -
             1)
         rowNames = as.character(as.Date(x1[, 1], format = "%d-%b-%y"))
         colNames = scan(file = file, n = dim(x1)[2], what = "",
             sep = ",")[-1]
         dimnames(z) = list(rowNames, colNames)
         if (save) {
             write.table(t(c("%Y-%m-%d", colNames)), file, quote = FALSE,
                 row.names = FALSE, col.names = FALSE, sep = ";")
             write.table(z, file, quote = FALSE, append = TRUE,
                 col.names = FALSE, sep = ";")
         }
         else {
             unlink(file)
         }
         z = data.frame(DATE = rowNames, z, row.names = NULL)
         ans = new("fWEBDATA", call = match.call(), param =
c("Instrument Query" = query),
             data = z, title = "Web Data Import from Yahoo", description
= as.character(date()))
         return(ans)
     }
     invisible()
}