Skip to content

Quantmod Yahoo ticker download error

7 messages · Marco Sun, Isak Engdahl, Pierre Org

#
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)*
*> "*
=============================

========================================
user="donedge",password="p at ssw0rd", dbname= "daily")
+   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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20150224/2923030c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: downloadData.R
Type: application/octet-stream
Size: 862 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20150224/2923030c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mysqlData.R
Type: application/octet-stream
Size: 593 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20150224/2923030c/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: init.R
Type: application/octet-stream
Size: 72 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20150224/2923030c/attachment-0002.obj>
#
Hi Isak,

I have checked your scripts and there is no error reported on my platform. getSymbols correctly downloads historical prices for `ZB-PA`
[1] "ZB-PA?
And a dataframe named `df` can also be constructed via your script
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:

            

  
  
#
Hi Isak,

I have checked your scripts and there is no error reported on my platform. getSymbols correctly downloads historical prices for `ZB-PA`
[1] "ZB-PA?
And a dataframe named `df` can also be constructed via your script
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:

            

  
  
#
Hi 

Thank you all for a great and very useful thread. Do you know if there is a package that can help to access the same type of information than stockSymbols fort the London stock exchange ? i.e download of price and market caps ? I am working on a Black & Litterman project and would like to somehow automatise a reverse optimisation of the expected returns for each sectors For this, I  need to download the market caps per stock/sector as well as the closing price...any help / pointer would be appreciated.


Thks

Pierre

-----Original Message-----
From: R-SIG-Finance [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Marco Sun
Sent: 24 February 2015 13:55
To: Isak Engdahl
Cc: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] Quantmod Yahoo ticker download error

Hi Isak,

I have checked your scripts and there is no error reported on my platform. getSymbols correctly downloads historical prices for `ZB-PA`
[1] "ZB-PA 
And a dataframe named `df` can also be constructed via your script
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:

            

  
  
#
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:

            

  
    
#
Hello Pierre,

https://github.com/cran/quantmod/blob/master/R/getSymbols.R

They have interface for Yahoo data and Yahoo have LSE Equity information so
I think you can query the symbols.

http://finance.yahoo.com/q;_ylt=AkquhlMP8R.OHhWpokxU7WvdgvME;_ylc=X1MDMjE0MjQ3ODk0OARfcgMyBGZyA3VoM19maW5hbmNlX3dlYl9ncwRmcjIDc2EtZ3AEZ3ByaWQDBG5fZ3BzAzEwBG9yaWdpbgNmaW5hbmNlLnlhaG9vLmNvbQRwb3MDMwRwcXN0cgMEcXVlcnkDQU1FQy5MLARzYWMDMQRzYW8DMQ--?p=http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3DAMEC.L%26ql%3D0&uhb=uhb2&fr=uh3_finance_vert_gs&s=AMEC.L


I still get this error

Error in download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=",
 :
  cannot open URL '
http://ichart.finance.yahoo.com/table.csv?s=AMEC.L&a=0&b=01&c=1900&d=1&e=24&f=2015&g=v&ignore=.csv
'
In addition: Warning messages:
1: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  downloaded length 51965 != reported length 200
2: In download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=",  :
  cannot open: HTTP status was '404 Not Found'

If I add AMEC.L in my vector in: symbols =
c("AMEC.L","XLF","XLP","XLE","XLY","XLV","XLI","XLB","XLK","XLU")

But I think this is something with my installation as Marco did not have
this issue.

Please let me know it works.

//Isak
On Tue, Feb 24, 2015 at 3:02 PM, Pierre Org <pierre at lequeux.org> wrote:

            

  
    
#
Hi Isak,

 

Many thanks for this, it   should be  really useful  for my project

 

 

Kind regards

 

Pierre

                    

From: Isak Engdahl [mailto:isak.engdahl at gmail.com] 
Sent: 24 February 2015 15:12
To: Pierre Org
Cc: r-sig-finance
Subject: Re: [R-SIG-Finance] Quantmod Yahoo ticker download error

 

Hello Pierre,

 

https://github.com/cran/quantmod/blob/master/R/getSymbols.R

 

They have interface for Yahoo data and Yahoo have LSE Equity information so I think you can query the symbols.

 

http://finance.yahoo.com/q;_ylt=AkquhlMP8R.OHhWpokxU7WvdgvME;_ylc=X1MDMjE0MjQ3ODk0OARfcgMyBGZyA3VoM19maW5hbmNlX3dlYl9ncwRmcjIDc2EtZ3AEZ3ByaWQDBG5fZ3BzAzEwBG9yaWdpbgNmaW5hbmNlLnlhaG9vLmNvbQRwb3MDMwRwcXN0cgMEcXVlcnkDQU1FQy5MLARzYWMDMQRzYW8DMQ--?p=http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3DAMEC.L%26ql%3D0 <http://finance.yahoo.com/q;_ylt=AkquhlMP8R.OHhWpokxU7WvdgvME;_ylc=X1MDMjE0MjQ3ODk0OARfcgMyBGZyA3VoM19maW5hbmNlX3dlYl9ncwRmcjIDc2EtZ3AEZ3ByaWQDBG5fZ3BzAzEwBG9yaWdpbgNmaW5hbmNlLnlhaG9vLmNvbQRwb3MDMwRwcXN0cgMEcXVlcnkDQU1FQy5MLARzYWMDMQRzYW8DMQ--?p=http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3DAMEC.L%26ql%3D0&uhb=uhb2&fr=uh3_finance_vert_gs&s=AMEC.L> &uhb=uhb2&fr=uh3_finance_vert_gs&s=AMEC.L

 

 

I still get this error

 

Error in download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=",  : 

  cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=AMEC.L <http://ichart.finance.yahoo.com/table.csv?s=AMEC.L&a=0&b=01&c=1900&d=1&e=24&f=2015&g=v&ignore=.csv> &a=0&b=01&c=1900&d=1&e=24&f=2015&g=v&ignore=.csv'

In addition: Warning messages:

1: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :

  downloaded length 51965 != reported length 200

2: In download.file(paste(yahoo.URL, Symbol.name, "&a=", from.m, "&b=",  :

  cannot open: HTTP status was '404 Not Found'

 

If I add AMEC.L in my vector in: symbols = c("AMEC.L","XLF","XLP","XLE","XLY","XLV","XLI","XLB","XLK","XLU")

 

But I think this is something with my installation as Marco did not have this issue.

 

Please let me know it works.

 

//Isak
On Tue, Feb 24, 2015 at 3:02 PM, Pierre Org <pierre at lequeux.org> wrote:
Hi

Thank you all for a great and very useful thread. Do you know if there is a package that can help to access the same type of information than stockSymbols fort the London stock exchange ? i.e download of price and market caps ? I am working on a Black & Litterman project and would like to somehow automatise a reverse optimisation of the expected returns for each sectors For this, I  need to download the market caps per stock/sector as well as the closing price...any help / pointer would be appreciated.


Thks

Pierre


-----Original Message-----
From: R-SIG-Finance [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Marco Sun
Sent: 24 February 2015 13:55
To: Isak Engdahl
Cc: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] Quantmod Yahoo ticker download error

Hi Isak,

I have checked your scripts and there is no error reported on my platform. getSymbols correctly downloads historical prices for `ZB-PA`
[1] "ZB-PA
And a dataframe named `df` can also be constructed via your script
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: