0

I use getSymbols.yahoo to get a time-series of a stock price. I usually set some starting point in the past (lets say a date a year ago) and always the latest possible price from the last trading day. Everything works fine but for one thing. If I want to include the latest close price, I have a problem with that. Even though the US stock exchanges close at 4:00 pm ET, and you can also see the latest close price already on yahoo finance website for any stock you look up; I am unable to get a time series with the latest close price.

For example, today if I try to download stock prices after 4:00 pm ET, I will only get prices up to the 8th of December. Only after few hours past trading (my experience is 4 hours and more) I will be successful and my time-series will include. Why there is such a delay for the latest close price to download? No matter what kind of stock I am interested in, there is always this delay problem.

Pat Amat
  • 23
  • 7

1 Answers1

2

getSymbols is accessing historical data (from CSI) which is updated a few hours after the closing of the markets. What you want is getQuote, which gives you the latest quotes (even realtime). So if you want for instance update some indicators during market hours or right after the close you should append the quote you receive with getQuote - after some data manipulation -, to the data you receive with getSymbols. Have a look at ?getQuote for different quote formats available.

hvollmeier
  • 2,956
  • 1
  • 12
  • 17
  • Thank you very much, this helped me a lot! – Pat Amat Dec 12 '16 at 15:53
  • @ Pat Amat, If this works, please consider to accept the solution by clicking on the tick mark next to the vote. – hvollmeier Dec 12 '16 at 16:49
  • The problem is, that if getQuote is unsuccessful with findind a quote for specific ticker, it will return "N/A", which is not a "typical" "NA" and I am unable to get rid of it. is.na cannot even identify it. – Pat Amat Dec 12 '16 at 23:10
  • 1
    Can you post an example? If `is.na` cannot identify it you can check for instance is `AMZN$Last == "N/A" ? (assuming you stored the quote as variable AMZN). Open this as a new question and I will look into it. – hvollmeier Dec 13 '16 at 06:26
  • @ hvollmeier, Some stock tickers have in its name `.`, some have `-`. Such example could be `getQuote("BRK.A")`. This returns information for `Trade Time Last Change % Change Open High Low Volume` The results are like this `BRK.A N/A N/A N/A N/A N/A N/A N/A` Only the first `` is identified via `is.na`. The other NAs - `N/A` act as NAs but they are not identified as NAs. This creates a problem, because I want to eliminate from a dataframe stocks, that returned `N/A`. However I cannot work with these. – Pat Amat Dec 14 '16 at 12:58
  • @ hvollmeier, One way would be to bypass this problem by replacing `-` with `.`. However, this is not a permanent solution. In the future, there still could be some tickers, which may be (at least) temporary unavailable. I have a dataframe, where columns are tickers. The first column is date. When I want to append my dataframe with the latest price for the latest day, I want to have in the last row both available prices and "unavailable" prices represented by NA strings, so that I will in the end eliminate stocks, for which I was unable to get the latest price. – Pat Amat Dec 14 '16 at 13:05
  • @ hvollmeier, when you save `getQuote` results, you will either get a price, or a string `N/A`, which cannot be identified with `is.na`. Only string `` is identified with `is.na`. However, this string is at position for Trade (see the example above with BRK.A or try it yourself). When you save results of `getQuote` you get `N/A` string which is representing `Last`. – Pat Amat Dec 14 '16 at 13:09
  • Appending daily Yahoo data as a data storage solution is not recommended at all ! You have to redownload all the data daily, unless you like to ensure that you have garbage after a few months. Historical data is adjusted after every cash dividend, split etc. If you work with adjusted data the data you see for instance for 12/12/2016 is likely to be different if you check in one year for the data for 12/12/2016! You either download all the data daily or build your own data solution where you keep a record for all the company actions affecting the price of every stock you are interested in! – hvollmeier Dec 14 '16 at 13:25
  • I do redownload the data daily. However If I redownload it after few minutes after market closes, I must use getQuote as well if I want to have price data for the latest date. The option number two would be wait several hours till I can download the data with the latest prices included. However this is not a solution for me, because I need every hour available to run my analysis in order to get results and prepare trading recommendations till market opens. – Pat Amat Dec 14 '16 at 13:39