U.S. companies are reporting mostly upbeat news this earnings season, surprising investors who had been bracing for a gloomier outlook on both businesses and the economy.

More than halfway into the second-quarter reporting period, S&P 500 company earnings are estimated to have increased 8.1% over the year-ago quarter, compared with a 5.6% estimate at the start of July, according to IBES data from Refinitiv as of Tuesday.

Some 78% of earnings reports are beating Wall Street expectations, above the long-term average.

Profit growth estimates for the third and fourth quarters have come down, but remain sharply positive. S&P 500 earnings for all of 2022 are now forecast to grow 8.1% versus a 9.5% estimated in July, based on Refinitiv data.

Investors had been worried that if high inflation and rising interest rates were about to tip the economy into recession, earnings estimates for 2022 were too high.

Raising the risk that the economy was on the cusp of a recession, the U.S. Commerce Department said last week the American economy unexpectedly contracted in the second quarter - the second straight quarterly decline in gross domestic product.

Concerns over a possible recession had driven a sharp selloff in stocks in the first half of the year. But the S&P 500 and Nasdaq ended July with their biggest monthly percentage gains since 2020, partly because of stronger-than-expected earnings.

"The consensus view (was) that earnings were going to just fall apart," said Jonathan Golub, chief U.S. equity strategist & head of quantitative research at Credit Suisse Securities. "And it just didn't play out that way."

Company reports are showing that demand remains robust and sales are holding up, he said.

"If you want to say, what's the health of the economy, it's measured in sales," Golub said.

Year-over-year revenue for S&P 500 companies in the quarter is expected to have risen 12.5% as of Tuesday, compared with 10.4% estimated at the start of July, based on Refinitiv data.

Upbeat forecasts from heavyweights Apple and Amazon.com boosted investors' mood late last week, while Chevron Corp and Exxon Mobil reported record quarterly revenues.

Apple said parts shortages were easing and that demand for iPhones was continuing, while Amazon.com forecast a jump in third-quarter revenue.

"It's held up pretty well, particularly for large-cap names, but of course people were expecting the worst," said Rick Meckler, partner at Cherry Lane Investments, a family investment office in New Vernon, New Jersey.

To be sure, the news has not been positive all around. Walmart rattled investors early last week when it cut its full-year profit forecast, blaming surging prices for food and fuel.

That's raised worried about the health of the consumer and prospects for other retailers, most of which have yet to report results on the last quarter.

Also, analysts have been cutting their third-quarter earnings growth estimates by more than usual when compared with "either pre-pandemic or over the last two years," Nicholas Colas, co-founder of DataTrek Research, wrote in a note this week.

Whether earnings forecasts hold up is key to valuations. The S&P 500's forward 12-month price-to-earnings ratio, at 17.5 as of Tuesday, is down from 22.1 at the end of December but still above the long-term average of about 16, Refinitiv data showed.

Other strategists said the season is following a normal pattern: Companies often are more negative than positive with their outlooks, so earnings forecasts for upcoming quarters tend to go down typically during a reporting period.

"So far, what's happened isn't something that's worse than feared. And the market was already braced for bad news," said Keith Lerner, chief market strategist at Truist Advisory Services in Atlanta.