<div dir="ltr">Hi Marco,<div><br></div><div>Very Strange! I update quantmod, still get this error...</div><div><br></div><div>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:</div><div><br></div><div><b>Error in 1:nrow(symbols) : argument of length 0</b><br></div><div><br></div><div>I runned nrow(symbols) and get <br></div><div><div>nrow(symbols)</div><div>NULL</div></div><div><br></div><div>The symbols should not have any rows, right?</div><div><br></div><div>The For should look at the datasets for the tickers and store in to the database, right?</div><div><br></div><div><br></div><div><div><i>#Initialization</i></div><div><i>library(quantstrat)</i></div><div><i>library(TTR)</i></div><div><i>startDate <- "2010-01-01"</i></div><div><i>endDate <- "2013-07-31"</i></div><div><i>symbols = c("XLF","XLP","XLE","XLY","XLV","XLI","XLB","XLK","XLU")</i></div><div><i>Sys.setenv(TZ="UTC")</i></div><div><i>getSymbols(symbols, src="yahoo", from=startDate, to=endDate, adjust=TRUE)</i></div><div><i><br></i></div><div><i># Save data to MySQL</i></div><div><i><br></i></div><div><i>library(RMySQL)</i></div><div><i><br></i></div><div><i>con <- dbConnect(RMySQL::MySQL(), host="localhost", user="donedge",password="p@ssw0rd", dbname= "daily")</i></div><div><i><br></i></div><div><i># Loop through each symbol</i></div><div><i>for (i in 1:nrow(symbols)){</i></div><div><i>  symbol <- symbols[i,]$Symbol</i></div><div><i>  df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))</i></div><div><i>  setNames(df,c("Date","Open","High","Low","Close","Volume","Adjusted"))</i></div><div><i>  </i></div><div><i>  if(dbExistsTable(con, symbol)){</i></div><div><i>    dbRemoveTable(con, symbol)</i></div><div><i>  }</i></div><div><i>  dbWriteTable(con, name=symbol, value=df, row.names=FALSE, overwrite = TRUE)</i></div><div><i>}</i></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 24, 2015 at 2:56 PM, Marco Sun <span dir="ltr"><<a href="mailto:hs13322@my.bristol.ac.uk" target="_blank">hs13322@my.bristol.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="">Hi Isak,<div><br></div><div>I have checked your scripts and there is no error reported on my platform. getSymbols correctly downloads historical prices for `ZB-PA`</div></span><div><span class=""><div>> library(quantstrat)</div><div>> all.symbols <- stockSymbols(c("NYSE"),<a href="http://sort.by" target="_blank">sort.by</a>=c("MarketCap","Exchange"),quiet=TRUE)</div><div>> biggest.symbols <- tail(all.symbols,n=5)</div><div><div>> clean.symbols <- subset(biggest.symbols, select = c("Symbol","Name","LastSale","MarketCap","Sector"))</div><div>> row.names(clean.symbols) <- NULL</div></div><div>> i=1 #trying i=1 instead of doing the entire loop</div></span><span class=""><div>> symbol <- clean.symbols[i,]$Symbol</div></span><span class=""><div>> try (getSymbols(symbol, verbose=FALSE, warnings=FALSE, from='2015-01-01'))</div><div>[1] "ZB-PA”</div></span></div><span class=""><div>And a dataframe named `df` can also be constructed via your script</div><div>> df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))</div><div><br></div><div>I would recommend you to update `quantmod` package if it is not the latest released version on your console.</div><div><br></div><div>Best,</div><div>Marco</div><div><br></div></span><div><span class=""><div>On 24 Feb 2015, at 08:33 pm, Isak Engdahl <<a href="mailto:isak.engdahl@gmail.com" target="_blank">isak.engdahl@gmail.com</a>> wrote:</div><br></span><blockquote type="cite"><div><div class="h5"><div dir="ltr">Hello,<div><br></div><div>Tickers with - get error when trying to download ZB-PA but not ZBK.</div><div><br></div><div>When I manually download it from Yahoo I get this link, that works.</div><div><br></div><div><div><a href="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" target="_blank">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</a></div><div><br></div><div>The Quantmod tried to download from this link, which does not exist.</div><div><a href="http://ichart.finance.yahoo.com/table.csv?s=ZB-PA&a=0&b=01&c=2015&d=1&e=24&f=2015&g=d&" target="_blank">http://ichart.finance.yahoo.com/table.csv?s=ZB-PA&a=0&b=01&c=2015&d=1&e=24&f=2015&g=d&</a><b>q=q&y=0&z=ZB-PA&x</b>=.csv</div><div><br></div><div>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.<br></div><div><br></div><div>Maybe this forum is not the correct place to suggest this improvement, please point me in right direction.</div><div><br></div><div>Maybe someone can help me out to fix this script error?</div><div>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?</div><div><br></div><div>Please find attached scripts.</div><div><br></div><div>Error when trying to download ticker data from Yahoo Finance for ZB-PA.</div><div><br></div><div>=================================</div><div><i>"Downloading ZB-PA</i><br></div><div><i>Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  : </i></div><div><i>  cannot open URL '<a href="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" target="_blank">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</a>'</i></div><div><i>In addition: Warning message:</i></div><div><i>In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :</i></div><div><i>  InternetOpenUrl failed: 'The operation timed out'</i></div><div><i>, error - did not download (likely due to rate limiting</i></div><div><i>Downloading ZBK</i></div><div><i>Warning message:</i></div><div><i>In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :</i></div><div><i>  downloaded length 1653 != reported length 200</i></div><div><i>> View(clean.symbols)</i></div><div><i>> "</i></div><div>=============================</div><div><br></div><div><div>========================================</div><div>> # Save data to MySQL</div><div>> </div><div>> library(RMySQL)</div><div>> </div><div>> con <- dbConnect(RMySQL::MySQL(), host="localhost", user="donedge",password="p@ssw0rd", dbname= "daily")</div><div>> </div><div>> # Loop through each symbol</div><div>> </div><div>> for (i in 1:nrow(clean.symbols)){</div><div>+   symbol <- clean.symbols[i,]$Symbol</div><div>+   df = data.frame(Date=index(get(symbol)), coredata(get(symbol)))</div><div>+   setNames(df,c("Date","Open","High","Low","Close","Volume","Adjusted"))</div><div>+   </div><div>+   cat("Storing",symbol,"\n")</div><div>+   </div><div>+   if(dbExistsTable(con, symbol)){</div><div>+     dbRemoveTable(con, symbol)</div><div>+   }</div><div>+   </div><div>+   dbWriteTable(con, name=symbol, value=df, row.names=FALSE, overwrite = TRUE)</div><div>+   </div><div>+ }</div><div><b>Error in get(symbol) : object 'ZB-PA' not found</b></div><div>> </div></div><div>========================================</div><div><br></div><div>Kind Regards</div><div>Isak</div></div></div>
</div></div><span class=""><span><downloadData.R></span><span><mysqlData.R></span><span><init.R></span>_______________________________________________<br><a href="mailto:R-SIG-Finance@r-project.org" target="_blank">R-SIG-Finance@r-project.org</a> mailing list<br><a href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a><br>-- Subscriber-posting only. If you want to post, subscribe first.<br>-- Also note that this is not the r-help list where general R questions should go.</span></blockquote></div><br></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><br></div><div><br></div><div>Kind Regards</div><div>Isak Engdahl</div></div></div></div></div>
</div>