Stocks rose Wednesday, led by blue chips, as investors welcomed a narrower-than-expected U.S. trade deficit for May, better-than-expected earnings reports and brokerage upgrades. The Nasdaq and the S&P 500 posted their fifth straight day of gains.

The Dow Jones industrial average (search) rose 43.50 points, or 0.41 percent, to end at 10,557.39. The Standard & Poor's 500 Index (search) was up 1.08 points, or 0.09 percent, at 1,223.29. The technology-laced Nasdaq Composite Index (search) was up just 0.96 of a point, or 0.04 percent, to close at 2,144.11.

"Earnings are very good, corporations are flush with cash and we're seeing more dividend increases occurring," said Joe Lisanti, editor of Standard & Poor's weekly newsletter The Outlook. "We're going to see more investors pleased with their returns."

Brokerage upgrades led to a strong day for shares of International Business Machines Corp. (IBM) and Hewlett-Packard Co. (HPQ), which helped drive the Dow higher. IBM shares rose 1.8 percent, or $1.41, to $81.45 and the stock of Hewlett-Packard, a computer and printer maker, gained 1.3 percent, or 31 cents, to $24.42, both in New York Stock Exchange trading.

"Even though it's somewhat scant so far, it does seem that the earnings season may turn out to be somewhat better than expected," said Peter Cardillo, chief market analyst and chief strategist at SW Bach & Co., of New York.

After the closing bell, Apple (AAPL) shares rose to $38.53 on the Inet electronic brokerage network from a $38.35 Nasdaq close.

"It looks very solid," said Jim Fisher, portfolio manager at Univest Wealth Management, which owns Apple shares. "The thing that stands out for me is the iPod shipments, which were 1 million more than what the Street was anticipating. I know there were some concerns about inventory buildup several months ago, so that is very good news."

Oil prices swung between positive and negative territory throughout the day, before settling at $60.01 a barrel for light, sweet crude futures for August delivery, off 61 cents on the New York Mercantile Exchange (search).

U.S. crude oil inventories dropped 3.9 million barrels last week as stormy weather delayed offloading of imports passing through the Gulf of Mexico, a government report showed.

Oil's price fluctuations kept the Nasdaq and the S&P 500 alternating between declines and gains through the day.

"Crude's kind of flopping around, therefore, you've kind of got the market flopping around," said Dan McMahon, head of listed trading at CIBC World Markets Inc., of New York.

The U.S. trade deficit showed a slight improvement in May, reflecting a temporary decline in world oil prices. But a continued surge in clothing and textile shipments pushed the deficit with China to the highest level in six months.

The Commerce Department (search) reported that America's trade deficit fell by 2.7 percent in May to $55.3 billion, the best showing since March. The bulk of the improvement came from a big drop in oil prices which pushed petroleum imports down by 6.8 percent.

"The underlying economy is chugging along nicely," said Arnie Owen, managing director of Merriam Curhan Ford & Co. out of San Francisco.

Yum Brands Inc. (YUM), operator of KFC and Taco Bell fast food chains, beat analyst estimates but lowered third- and fourth-quarter guidance. Yum fell 67 cents in after-hours trading after slipping 55 cents to $51.71 in regular trading.

Motorcycle maker Harley-Davidson (HDI) said second-quarter profits declined 4 percent from last year, as lower motorcycle shipments outweighed a modest rise in revenue. But the results beat Wall Street expectations, and the company also raised its full-year earnings growth target. Harley rose 68 cents to $50.38.

Gannett Co. (GCI), the nation's largest newspaper publisher, posted a slight decline in second-quarter earnings on lower broadcasting revenues and higher costs for interest and new presses at The Detroit News. The result matched the average estimate from analysts surveyed by Thomson Financial and its stock fell 46 cents to $72.95.

Stock in Boston Scientific Corp. (BSX) fell 38 cents to $27.48 after The Wall Street Journal reported doctors are seeing continued injuries during the implantation of the company's cardiac stents. Problems with the stents have caused three deaths even after the devices' 2004 recall, the paper reported.

Trading was moderate, with 1.36 billion shares changing hands on the New York Stock Exchange, below the 1.46 billion daily average for last year. About 1.55 billion shares were traded on Nasdaq, below the 1.81 billion daily average last year.

The number of shares declining in value exceeded the number advancing by a ratio of about 6 to 5 on the NYSE and by more than 8 to 7 on Nasdaq.

The Russell 2000 index of smaller companies fell 3.14, or 0.47 percent, to 667.65.

Overseas, Japan's Nikkei stock average was down 0.28 percent. In Europe, Britain's FTSE 100 closed up 0.55 percent, France's CAC-40 was up 0.69 percent for the session, and Germany's DAX index was up 0.58 percent in late trading.

Reuters and the Associated Press contributed to this report.