The military stalemate between the United States and Iran is crippling the flow of oil around the world. Gas prices are soaring. Inflation is back above 3 percent. Consumer confidence is tanking, and most Americans are pessimistic about the economy. Yet the S&P 500 has risen 29 percent over the past 12 months, and hit an all-time high last week. After a sell-off at the start of the war, stocks are up 13 percent in 30 days. Despite oil blockades and a threat to a whole civilization, investors have shrugged and kept buying. The stock market looks completely out of touch with reality.But there is a logic at work: Stocks keep going up because corporate profits have continued to soar. If investors have learned to ignore President Trump’s chaos, it’s not because they’re oblivious to reality, but because this chaos has hardly dented corporate profits. Yes, there’s a disconnect between the stock market’s buoyancy and how ordinary Americans feel about the economy. But the stock market isn’t about the price of milk; it’s about how corporations are doing, and right now they are doing quite well.Consider the so-called Magnificent Seven, the major tech companies with some of the most valuable stocks in the world, many of which reported record quarterly earnings last week. Alphabet is now on track to make more than $120 billion in profits this year alone. Nvidia is on pace to earn more than that, and has nearly doubled its profits from last year. Meta’s latest earnings rose 61 percent year over year. These companies will collectively make more than half a trillion dollars in profit this year.[Rogé Karma: So, about that AI bubble]This phenomenon goes beyond tech. Close to 80 percent of S&P 500 companies that have reported earnings so far have beaten expectations. The average profit margin for S&P 500 companies is now at its highest point in 15 years, continuing a trend that began post-pandemic. There are several possible reasons for this: Inflation and market consolidation have granted companies more pricing power, productivity has been rising (perhaps because of AI tools), and the AI build-out has fueled huge tech profits. But regardless of why it’s happening, future profits are an essential ingredient for stock valuations, so stocks are naturally rising, too.This is not to say that today’s stock market makes complete sense. Two weeks ago, the former shoe company Allbirds announced that it was pivoting to artificial intelligence, and its stock septupled overnight. Since COVID began, retail investors have also gotten used to “buying the dip,” treating every sell-off as a clearance-sale opportunity, regardless of geopolitical turmoil.But there’s plenty of evidence that investors are paying attention to the metrics that matter. Companies that report disappointing sales numbers or miss earnings expectations are being punished by the market. When Nike reported in late March that it expected revenues to drop, the stock fell by more than 15 percent in a day. Investors are also noting future threats to profitability, selling off stocks in software-as-service businesses that may soon be gouged by AI. [Listen: On the brink of global recession]There is some concern that the stock market’s price-to-earnings ratio—the amount investors pay for every dollar of corporate earnings—is high (albeit not near the levels we saw during the internet-stock bubble). But in general, investors seem to be sensibly accounting for the fact that corporate earnings are not just high, but growing at a sustainably fast clip. The question now is just how sensible that assumption will prove to be. The war’s high energy prices are hitting corporate bottom lines and taking about $4 billion a month out of the pockets of American consumers. If this continues into the summer, businesses should prepare for less consumer spending and weaker profits.Investors are also wagering heavily on the AI boom, and the next year or so should reveal whether the valuations of various tech companies have been overinflated. Tech companies have been pouring money into building new data centers and AI chips, which could prove savvy if public demand for their products continues to grow, but will be a serious problem if AI fails to be as lucrative as everyone is promising.For most investors, buoyed by years of growth, that is a concern for another day. Although many people, including Trump, understand the stock market as a measure of the economy’s health, the divide between what investors see and what most people feel is wide and growing.