Joseph W
Joseph W

Reputation: 23

Exists() and getSymbols() can't find symbol listed in yahoo

For some reason, even though PRIO3F.SA is listed on yahoo(and also other symbols aside from this one specifically), when I do exists() it simply doesn't find anything. This is for a school project and quite a few symbols can't be found with this method. Is quantmod (or maybe yahoo finance) not my best place to go to?

I've tried multiple different symbol variations and still failing.

> exists("PRIO3F.SA")
[1] FALSE
> exists("PRIO3.SA")
[1] FALSE
> exists("PRIO3F")
[1] FALSE
> exists("PRIO3")
[1] FALSE

If by any chance I try to use getSymbols() instead, this is what greets me:

> getSymbols("PRIO3F.SA", src = "yahoo", auto.assign = FALSE)
Error in getSymbols.yahoo(Symbols = "PRIO3F.SA", env = <environment>,  : 
  Unable to import “PRIO3F.SA”.
attempt to set an attribute on NULL

Upvotes: 2

Views: 491

Answers (2)

Joshua Ulrich
Joshua Ulrich

Reputation: 176648

Yahoo does not provide historical daily data for every ticker symbol. That's the problem in this case.

enter image description here

Upvotes: 2

r2evans
r2evans

Reputation: 160437

Since I can call getSymbols("MSFT",src="yahoo",auto.assign = FALSE) successfully while getSymbols("PRIO3F.SA",src="yahoo",auto.assign = FALSE) fails (for me as well), that suggests the API may have changed. I debugged the call to getSymbols.yahoo (internal) and it appears that the URL being generated automatically

yahoo.URL
# [1] "https://query2.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?period1=1167609600&period2=1688688000&interval=1d"

and the URL shown within Yahoo!'s own finance page are different. While debugging, if I replace it with (while deep within debugging)

yahoo.URL <- "https://query1.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?region=US&lang=en-US&includePrePost=false&interval=2m&useYfid=true&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance"

## for comparison ...
https://query2.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?period1=1167609600&period2=1688688000&interval=1d
https://query1.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?region=US&lang=en-US&includePrePost=false&interval=2m&useYfid=true&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance

it works. Note that the url generated by getSymbols.yahoo includes the period whereas the url I sniffed in the browser does not. I'm sure this will be the source of some more investigation.

I suggest you submit a bug-report to the authors, since it appears Yahoo! may have updated their API and/or tightened their expectations. (Perhaps it's CORS or the source country of my request or any number of things.)

Upvotes: 1

Related Questions