I'm building out a stock database for my own learning. I've used pandas' time series tools to generate a list of business days (kind of close enough to trading days). Then I have stock prices from Quandl, but the question is - how should I handle stocks when they haven't traded? i.e., let's just say I want to calculate price momentum of every stock at the end of each month. A stock that is in suspension won't have a score. I can think of two ways to handle this, either insert yesterday's price as a repeat for today, or first get prices for end of month then separately go back and get last traded price for stocks that are missing. Thoughts?

Cheers, Steve

  • $\begingroup$ Inserting yesterday's price if there is no price today is a good solution in principle. But it is also important to understand how many missing prices there are and why. For major companies like AAPL there should be a price every day, for small companies there could be some missing prices. If there are too many missing (or erroneous) prices it suggests some problem with the quality of the underlying data. $\endgroup$ – Alex C Jul 2 '17 at 23:35
  • $\begingroup$ Perhaps someone who has used Quandl can comment on the data quality. I have not used it. $\endgroup$ – Alex C Jul 3 '17 at 1:42
  • 1
    $\begingroup$ Sometimes a stock can be suspended for a few days (i.e., announcing a takeover bid), but the problem is Quandl also includes stocks that went bankrupt or got taken over and I have no way of knowing if the stock has ended. So if I keep reinserting last price I will have months of repeats. I thought about just getting all the prices in pandas then use pandas fillna to fill down, but obviously this means I can't use sql for a lot of the stuff. $\endgroup$ – stevew Jul 3 '17 at 10:43
  • $\begingroup$ What exactly is the problem? You want to align things, i.e. what's the YTD of all stocks on a particular day? I would just insert the missing value indicator (NA) and use on-the-fly adjustments as needed, e.g. in R na.locf (the yesterday strategy). $\endgroup$ – hroptatyr Jul 5 '17 at 3:20
  • $\begingroup$ Yea kind of. I was just wondering what's the industry standard of handling non trading days. I can envisage repeating prices for non-trading days to make life easier (i.e., I can join onto end of month dates in sql and get monthly stock returns) $\endgroup$ – stevew Jul 6 '17 at 11:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.