Well you have to remember that indexes such as S&P are made up of good companies, nearly all of which are profitable. Nearly none go broke. Compare that to the real world, where 90% of businesses fail in the first year. So the stock market does not take into account any of the failures. These are companies that routinely outpace GDP growth rate with their own revenue and profit growth rate. Companies that don’t cut the mustard get removed from indexes, generally before they go bankrupt. So the stock market (indexes) is really pretty much the best of the best.
Think about your city. The stock market is Home Depot, not the mom and pop hardware store on the corner that is getting beat out by Home Depot. It’s red lobster, not corner cafe. It’s the big land developer, not your friend with his own remodeling business with himself as the only employee, who can’t find work in recessions.