[R-SIG-Finance] Quantmod Yahoo ticker download error

Isak Engdahl isak.engdahl at gmail.com
Tue Feb 24 16:16:30 CET 2015


Hello Erol,

Thank your for your help!

When I run it with lenght I get the below error:

*Error in symbols[i, ] : incorrect number of dimensions*
*> *

Any ideas?

//Isak

# Loop through each symbol
nrow(symbols)
for (i in 1:length(symbols)){
  symbol <- symbols[i,]$Symbol
  df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))
  setNames(df,c("Date","Open","High","Low","Close","Volume","Adjusted"))

  if(dbExistsTable(con, symbol)){
    dbRemoveTable(con, symbol)
  }
  dbWriteTable(con, name=symbol, value=df, row.names=FALSE, overwrite =
TRUE)
}



On Tue, Feb 24, 2015 at 4:10 PM, Erol Biceroglu <EBiceroglu at optrust.com>
wrote:

>  I don’t think you can use “nrow()” since it’s a character vector, you
> need “length()”
>
>
>
> *Erol Biceroglu, MFin*
>
> Senior Risk Analyst
>
> *OPSEU Pension Trust*
>
> P: 416-681-2707   F: 416-681-6175
>
> e: EBiceroglu at OPTrust.com
>
>
>
> *From:* R-SIG-Finance [mailto:r-sig-finance-bounces at r-project.org] *On
> Behalf Of *Isak Engdahl
> *Sent:* Tuesday, February 24, 2015 10:02 AM
> *To:* Marco Sun
> *Cc:* r-sig-finance
> *Subject:* Re: [R-SIG-Finance] Quantmod Yahoo ticker download error
>
>
>
> Hi Marco,
>
>
>
> Very Strange! I update quantmod, still get this error...
>
>
>
> Instead of downloading a lots of tickers, I tried to limit the list to
> those tickers and tired to simplify the code. I get this error on the code
> below:
>
>
>
> *Error in 1:nrow(symbols) : argument of length 0*
>
>
>
> I runned nrow(symbols) and get
>
> nrow(symbols)
>
> NULL
>
>
>
> The symbols should not have any rows, right?
>
>
>
> The For should look at the datasets for the tickers and store in to the
> database, right?
>
>
>
>
>
> *#Initialization*
>
> *library(quantstrat)*
>
> *library(TTR)*
>
> *startDate <- "2010-01-01"*
>
> *endDate <- "2013-07-31"*
>
> *symbols = c("XLF","XLP","XLE","XLY","XLV","XLI","XLB","XLK","XLU")*
>
> *Sys.setenv(TZ="UTC")*
>
> *getSymbols(symbols, src="yahoo", from=startDate, to=endDate, adjust=TRUE)*
>
>
>
> *# Save data to MySQL*
>
>
>
> *library(RMySQL)*
>
>
>
> *con <- dbConnect(RMySQL::MySQL(), host="localhost",
> user="donedge",password="p at ssw0rd", dbname= "daily")*
>
>
>
> *# Loop through each symbol*
>
> *for (i in 1:nrow(symbols)){*
>
> *  symbol <- symbols[i,]$Symbol*
>
> *  df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))*
>
> *  setNames(df,c("Date","Open","High","Low","Close","Volume","Adjusted"))*
>
>
>
> *  if(dbExistsTable(con, symbol)){*
>
> *    dbRemoveTable(con, symbol)*
>
> *  }*
>
> *  dbWriteTable(con, name=symbol, value=df, row.names=FALSE, overwrite =
> TRUE)*
>
> *}*
>
>
>
> On Tue, Feb 24, 2015 at 2:56 PM, Marco Sun <hs13322 at my.bristol.ac.uk>
> wrote:
>
> Hi Isak,
>
>
>
> I have checked your scripts and there is no error reported on my platform.
> getSymbols correctly downloads historical prices for `ZB-PA`
>
> > library(quantstrat)
>
> > all.symbols <- stockSymbols(c("NYSE"),sort.by
> =c("MarketCap","Exchange"),quiet=TRUE)
>
> > biggest.symbols <- tail(all.symbols,n=5)
>
> > clean.symbols <- subset(biggest.symbols, select =
> c("Symbol","Name","LastSale","MarketCap","Sector"))
>
> > row.names(clean.symbols) <- NULL
>
> > i=1 #trying i=1 instead of doing the entire loop
>
> > symbol <- clean.symbols[i,]$Symbol
>
> > try (getSymbols(symbol, verbose=FALSE, warnings=FALSE,
> from='2015-01-01'))
>
> [1] "ZB-PA”
>
> And a dataframe named `df` can also be constructed via your script
>
> > df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))
>
>
>
> I would recommend you to update `quantmod` package if it is not the latest
> released version on your console.
>
>
>
> Best,
>
> Marco
>
>
>
> On 24 Feb 2015, at 08:33 pm, Isak Engdahl <isak.engdahl at gmail.com> wrote:
>
>
>
>   Hello,
>
>
>
> Tickers with - get error when trying to download ZB-PA but not ZBK.
>
>
>
> When I manually download it from Yahoo I get this link, that works.
>
>
>
>
> http://real-chart.finance.yahoo.com/table.csv?s=ZB-PA&a=00&b=2&c=2015&d=01&e=23&f=2015&g=d&ignore=.csv
>
>
>
> The Quantmod tried to download from this link, which does not exist.
>
>
> http://ichart.finance.yahoo.com/table.csv?s=ZB-PA&a=0&b=01&c=2015&d=1&e=24&f=2015&g=d&
> *q=q&y=0&z=ZB-PA&x*=.csv
>
>
>
> If this part could be replaced "q=q&y=0&z=ZB-PA&x" with "d&ignore" and it
> will work both with ZB-PA and ZBK.
>
>
>
> Maybe this forum is not the correct place to suggest this improvement,
> please point me in right direction.
>
>
>
> Maybe someone can help me out to fix this script error?
>
> My script stop writing to the database if one of these tickers get this
> error described above (no data exist for symbol ZB-PA to be stored in the
> database. Anyone know how to ignore tickers that get this error so the
> script can continue to load all tickers that has downloaded data?
>
>
>
> Please find attached scripts.
>
>
>
> Error when trying to download ticker data from Yahoo Finance for ZB-PA.
>
>
>
> =================================
>
> *"Downloading ZB-PA*
>
> *Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=",
> from.m,  : *
>
> *  cannot open URL
> 'http://ichart.finance.yahoo.com/table.csv?s=ZB-PA&a=0&b=01&c=2015&d=1&e=24&f=2015&g=d&q=q&y=0&z=ZB-PA&x=.csv
> <http://ichart.finance.yahoo.com/table.csv?s=ZB-PA&a=0&b=01&c=2015&d=1&e=24&f=2015&g=d&q=q&y=0&z=ZB-PA&x=.csv>'*
>
> *In addition: Warning message:*
>
> *In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :*
>
> *  InternetOpenUrl failed: 'The operation timed out'*
>
> *, error - did not download (likely due to rate limiting*
>
> *Downloading ZBK*
>
> *Warning message:*
>
> *In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :*
>
> *  downloaded length 1653 != reported length 200*
>
> *> View(clean.symbols)*
>
> *> "*
>
> =============================
>
>
>
> ========================================
>
> > # Save data to MySQL
>
> >
>
> > library(RMySQL)
>
> >
>
> > con <- dbConnect(RMySQL::MySQL(), host="localhost",
> user="donedge",password="p at ssw0rd", dbname= "daily")
>
> >
>
> > # Loop through each symbol
>
> >
>
> > for (i in 1:nrow(clean.symbols)){
>
> +   symbol <- clean.symbols[i,]$Symbol
>
> +   df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))
>
> +   setNames(df,c("Date","Open","High","Low","Close","Volume","Adjusted"))
>
> +
>
> +   cat("Storing",symbol,"\n")
>
> +
>
> +   if(dbExistsTable(con, symbol)){
>
> +     dbRemoveTable(con, symbol)
>
> +   }
>
> +
>
> +   dbWriteTable(con, name=symbol, value=df, row.names=FALSE, overwrite =
> TRUE)
>
> +
>
> + }
>
> *Error in get(symbol) : object 'ZB-PA' not found*
>
> >
>
> ========================================
>
>
>
> Kind Regards
>
> Isak
>
>
> <downloadData.R><mysqlData.R><init.R>_______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>
>
>
>
>
>
>
> --
>
>
>
>
>
> Kind Regards
>
> Isak Engdahl
>
> ------------------------------
> Disclaimer
> ---------------
> This e-mail and files transmitted with it are confidential and intended
> solely for the use of the individual or entity to whom they are addressed.
> If you have received this in error, contact OPTrust by telephone toll free
> at 1-800-906-7738 and delete the email without making a paper or electronic
> copy. The recipient should check this e-mail and attachments for the
> presence of viruses. OPTrust accepts no liability for any damage caused by
> any virus transmitted by e-mail.
> Please consider the environment before printing this e-mail message.
>
> Avis de non-responsabilité
> --------------------------------------
> Ce message et toutes les pièces jointes sont établis à l'intention
> exclusive de leur destinataire et sont confidentiels. Si vous recevez ce
> message par erreur, veuillez le détruire sans produire de copie papier ou
> électronique, et avertir immédiatement OPTrust par téléphone ou sans frais
> au 1-800-906-7738. Le destinataire doit s’assurer que ce message et toutes
> les pièces jointes ne contiennent pas de virus. OPTrust n’accepte aucune
> responsabilité pour les dommages causés par d’éventuels virus transmis par
> courriel.
> Pensez à l’environnement avant d’imprimer ce message.
>
>


-- 


Kind Regards
Isak Engdahl

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list