Why are stock prices going up when the economy is in ruins? Here’s some helpful context

It’s the question on every investor’s mind.

Google “Why is the stock market going up?” and you get 2.8 billion answers. Yet many of them (we haven’t checked them all) ignore or minimize a significant factor. The once-a-century strangeness of this downturn has combined with the way stock indexes are calculated and an element of sheer chance to produce this apparent contradiction. Understand how that happens, and it all makes sense. Sort of.

There’s a lot to make sense of. Back in January, the economy was growing at a respectable 2.1% annual rate, unemployment was a minuscule 3.6%, and Americans were still spending more money every month, as they had been doing in a nearly unbroken 11-year rise. By all those measures, the economy is now in the worst shape since the Great Depression, with GDP plunging, unemployment officially at 13.3% (suspected by many economists to be higher), and consumption spending in free fall. Yet the S&P 500 index, the most widely cited gauge of U.S. stock performance, was recently down just 1.4% from Jan. 1. It’s up 11.2% from a year ago. 

It’s disorienting. Does anyone think the business environment is 11.2% better than it was last June? With some 30 million not working, are things only 1.4% worse than they were in January? That’s the mystery.

To solve it, understand first that the S&P 500 index is weighted by market value, meaning the stock performance of extremely valuable companies like Microsoft and Apple (recently Nos. 1 and 2 by market capitalization) influence the index far more heavily than do companies like Gap and Alliance Data Systems (Nos. 499 and 500). Most stock indexes are weighted the same way. In this odd, sudden downturn, vast sectors of the economy have remained virtually unscathed so far—and those sectors just happened to be the ones that were already most heavily weighted in the index.

Market analysts sometimes mention the weighting issue fleetingly, but a close look shows that it’s highly significant in explaining the seeming disconnect between the market and the economy. S&P divides the 500 index companies into 11 sectors. Before the coronavirus hit, the four most heavily weighted sectors were information technology (such as Microsoft, Apple, and Visa), health care (such as Johnson & Johnson, UnitedHealth Group, and Pfizer), communication services (such as Alphabet, Facebook, and Netflix), and consumer discretionary (such as Amazon, Home Depot, and Nike). Not every company in those four sectors is a winner, but of the 11 sectors, those four have achieved the best stock performance this year, as homebound consumers worldwide bought more tech products, watched more TV, and ordered from Amazon, with trillions of dollars of help from government stimulus programs. 

When the most heavily weighted sectors and companies outperform the others, they become even more heavily weighted, while the struggling sectors become even less weighted. Some of the results can seem ridiculous. For example, Amazon alone outweighs the entire energy sector, dominated by such giants as Exxon Mobil, Chevron, and ConocoPhillips. Energy is by far the worst performing sector year to date, but in the index, its historic decline is wiped out by Amazon’s rocketing stock. 

Again, it’s only by chance that the most heavily weighted pre-coronavirus sectors should happen to be the ones that would prosper most in the pandemic. It could have been otherwise. Suppose a novel computer virus rather than a coronavirus had struck the economy, aimed at the tech giants, hobbling them. Most companies and consumers across the economy would feel the impact, but businesses would remain open, and the great majority of workers would keep working, earning, and spending. Technology stock prices would crater, however, and because the tech-dominated sectors were so heavily weighted going in, their sudden crisis would initially cause the whole S&P 500 index to drop like a cannonball. As most of the economy carried on, we’d wonder why the plunging S&P was so untethered to reality—for exactly the opposite reasons that we wonder about it today.

There’s nothing wrong with an index that’s weighted by market capitalization. It reflects how investors value America’s publicly traded companies as a whole. But the past three months remind us that a company’s or an industry’s financial value doesn’t always reflect its importance to the economy. Think of the airlines. The economy to which we’re accustomed couldn’t function without them, which is why both parties in Congress supported bailing them out. Yet even in the good times during the past year, the big four—American, Delta, Southwest, and United —were collectively worth only about $110 billion; today they’re worth a mere $68 billion. By contrast, a decidedly nonessential enterprise, McDonald’s, is worth $148 billion. Millions of consumers and employees would hate to live without McD’s, but we could manage.

Yes, a high and rising stock market with some 30 million not working seems crazy. But it has its logic. As stock indexes rise or fall in the months ahead, it’s worth remembering that indexes don’t pretend to be anything more than what they are, a gauge of investor sentiment. They don’t tell us whether investors are right or wrong, and, perhaps most important, they don’t tell us what’s ahead for individuals in this dual crisis of personal finance and human health.

More must-read finance coverage from Fortune: