For much of the year, the stock market has been on the ropes. Trade wars have erupted, the Federal Reserve raised rates, emerging market currencies collapsed, and major technology firms faced regulatory scrutiny — and, in the case of Amazon, presidential broadsides via messages on Twitter. Investors quailed at times, sending stocks down by as much as 10 percent.

But the nine-year-old bull market never completely crumbled. By April, stocks had started a fresh climb. And after a 0.6 percent rise on Friday, the Standard & Poor’s 500-stock index closed at a record high of 2,874.69 points, reflecting investor faith in a single fundamental fact: Big American companies are making lots of money.

“We’ve had record earnings growth, we’ve had record numbers of earnings and sales beats,” said Savita Subramanian, chief United States equity strategist for Bank of America Merrill Lynch. “Basically the fundamentals couldn’t look better.”

Because owners of stock are entitled to a share of the money a company makes, corporate profits are a key ingredient of stock market rallies. And profits for companies in the S. &P. 500 were up roughly 25 percent in the second quarter, after a surge of 27 percent in the first quarter, according to data from Thomson Reuters I/B/E/S.