Getting StockPrices for every Ticker in the NYSE

Here I am trying to get the stock prices for every symbol in the NYSE, but for some reason I keep getting a very unhelpful error that there are 50 or more warnings.

I first defined the exchange, and then used the vector symbol.

exchange <- tq_exchange("NYSE")
prices <- exchange$symbol %>%
  tq_get( from = "2020-06-02", to ="2020-06-04", get="stock.prices")


Shouldn't this work since symbol is a character vector? Isn't it the same as c("MSFT, "AAPL", ...)

When looking at warnings

Warning messages:
1: Problem with `mutate()` input `data..`.
x x = 'AEL^B', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "AEL^B", env = <environment>, verbose = FALSE, : Unable to import “AEL^B”.
Operation was aborted by an application callback
 Removing AEL^B.

Any help would be greatly appreciated

Disclosure: I am wholly unfamiliar with tidyquant.

The error message will help you if you read it.

It is erroring out on the ticker symbol AEL^B. I'm not terribly familiar with the stock market -- poor graduate students don't have much money to invest, but it doesn't look like any stock symbol I've seen on the regular.

So, looking at the tidyquant source code, the function tq_exchange() pulls its stock ticker data from https://old.nasdaq.com/. If we look there we can see on the page for the stock https://old.nasdaq.com/symbol/ael%5Eb that this is specifically for,

American Equity Investment Life Holding Company Depositary Shares, each representing a 1/1,000th interest in a share of 6.625% Fixed-Rate Reset Non-Cumulative Preferred Stock, Series B (AEL^B)

So, now we're getting somewhere!

If we turn our attention now to tq_get() (where the error happened) we see the error originated in getSymbols.yahoo(). So let's look there...

After some digging we find tq_get() is ultimately trying to get data from https://query1.finance.yahoo.com/v7/finance/

If you run this command separately,

tq_get("AEL^B", from = "2020-06-02", to ="2020-06-04", get="stock.prices")

You'll get a bit more helpful information:

[1] NA
Warning messages:
1: x = 'AEL^B', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "AEL^B", env = <environment>, verbose = FALSE, : Unable to import “AEL^B”.
AEL^B download failed after two attempts. Error message:
HTTP error 404.
 
2: In for (ns in list(...)) namespaceImportFrom(self, asNamespace(ns),  :
  closing unused connection 4 (https://query1.finance.yahoo.com/v7/finance/download/AEL^B?period1=1591056000&period2=1591228800&interval=1d&events=history&crumb=xbppWv2X/ho)
3: In for (ns in list(...)) namespaceImportFrom(self, asNamespace(ns),  :
  closing unused connection 3 (https://query1.finance.yahoo.com/v7/finance/download/AEL^B?period1=1591056000&period2=1591228800&interval=1d&events=history&crumb=c7wFMmTXYbG)

Particularly, we get the exact URLs it is trying to grab, https://query1.finance.yahoo.com/v7/finance/download/AEL^B?period1=1591056000&period2=1591228800&interval=1d&events=history&crumb=c7wFMmTXYbG
NOTE: Your URLs will be different and these URLs might not work if you click on them (there may be some tracking cookie issues).
Anyway, when I copy one of those URLs into a web browser, I get the following error message from Yahoo!,

404 Not Found: No data found, symbol may be delisted

In my admittedly ultra-limited knowledge, I don't believe Series A, B, C shares are publicly traded, though I welcome any and all corrections. So, what seems to be happening is the site from which tidyquant pulls ticker names is a bit more comprehensive than the site from which it pulls actual stock data.

The solution will almost certainly be to filter out any private funding series stock tickers from your exchange data. Perhaps,

exchange <- tq_exchange("NYSE")
exchange <- exchange[!grepl("\\^", exchange$symbol), ]
prices <- exchange$symbol %>%
  tq_get( from = "2020-06-02", to ="2020-06-04", get="stock.prices")

will work for you?

As it is I think you will get the same results you are getting now. tq_get() appears to ultimately use a try/catch to allow it to throw a warning instead of an error (though it includes the original error as part of the warning message), so when it can't pull the information you want for one particular stock ticker symbol it can continue on.

If you remove the non-tradable stocks, you should get the save result as is currently in your prices object, you just won't have to see those annoying warnings. If you are at all OCD like me, they'll drive you crazy.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.