US stocks have added to their recent rally after upbeat forecasts from Apple and Amazon.com as the S&P 500 and Nasdaq posted their biggest monthly percentage gains since 2020.
Most S&P 500 sectors ended higher, with energy rising 4.5 per cent, the most of any S&P sector.
Chevron Corp rose 8.9 per cent and Exxon Mobil shares jumped 4.6 per cent after the companies reported record quarterly revenues.
Apple Inc shares gained 3.3 per cent after the company said parts shortages were easing and that demand for iPhones was continuing.
Amazon.com Inc shot up 10.4 per cent after it forecast a jump in third-quarter revenue from bigger fees from its Prime loyalty subscriptions.
"In today's market, the Amazon and Apple numbers are giving the market support (on) the idea that two large companies that are a large part of the S&P seem so far to be able to navigate through these tougher times," said Rick Meckler, partner at Cherry Lane Investments, a family investment office in New Vernon, New Jersey.
Stocks have also rallied this week on investor speculation that the Federal Reserve may not need to be as aggressive with interest rate hikes as some had feared.
The Dow Jones Industrial Average rose 315.5 points, or 0.97 per cent, to 32,845.13; the S&P 500 gained 57.86 points, or 1.42 per cent, to 4,130.29 and the Nasdaq Composite added 228.10 points, or 1.88 per cent, to 12,390.69.
All three major indexes gained for the month and for the week.
The S&P 500 gained about 9.1 per cent for July in its biggest monthly percentage gain since November 2020 while the Nasdaq jumped about 12.3 per cent in July in its biggest monthly gain since April 2020.
In other earnings, Intel Corp shares fell 8.6 per cent after the company cut annual sales and profit forecasts and missed second-quarter estimates.
Second-quarter US corporate results have mostly been stronger than expected.
Of the 279 S&P 500 companies that have reported earnings so far, 77.8 per cent have exceeded expectations.
Earnings for S&P 500 companies now are expected to have increased 7.1 per cent in the quarter versus an estimated 5.6 per cent at the start of July, according to IBES data from Refinitiv.
The day's economic data showed US labour costs increased strongly in the second quarter as a tight jobs market boosted wage growth.
But on Thursday, a government report showed the US economy unexpectedly contracted in the second quarter, suggesting to some investors that the economy was on the cusp of a recession.
They said it might deter the Fed from continuing to aggressively increase rates as it battles high inflation.
Volume on US exchanges was 11.35 billion shares, compared with the 10.79 billion-share average for the full session over the last 20 trading days.
Advancing issues outnumbered declining ones on the NYSE by a 2.92-to-1 ratio; on Nasdaq, a 1.44-to-1 ratio favoured advancers.
The S&P 500 posted three new 52-week highs and 33 new lows; the Nasdaq Composite recorded 63 new highs and 82 new lows.