U.S. stocks climbed on Friday, with the Dow hitting a closing high for 2009, as investors anticipated positive news from next week's key earnings reports and bullish broker comments boosted tech shares.

U.S. stocks achieved their best weekly gains since July and snapped a two-week losing streak. The five-day rally pushed the Dow Jones industrial average up 4 percent for the week, while the Standard & Poor's 500 advanced 4.5 percent and the Nasdaq gained 4.5 percent.

In Friday's session, International Business Machines Corp rose 3 percent to $125.93 and led the Dow higher after Barclays Capital raised its price target to $140 from $119, and upgraded the information technology hardware sector to positive from neutral.

Separately, Deutsche Bank predicted late Thursday that semiconductor companies would report upside surprises in their earnings for the past three months.

The Philadelphia Semiconductor index <.SOXX> climbed 3.3 percent, while another Dow component Intel rose 1.5 percent to $20.17.

Both IBM and Intel are scheduled to report quarterly results next week.

The mood is ... reasonably optimistic (on earnings) which is part of the reason why we have seen 3-4 percent gains so far this week, said Fred Dickson, market strategist at D.A. Davidson & Co in Lake Oswego, Oregon.

The Dow Jones industrial average <.DJI> ended up 78.07 points, or 0.80 percent, at 9,864.94. The Standard & Poor's 500 Index <.SPX> gained 6.01 points, or 0.56 percent, to 1,071.49. The Nasdaq Composite Index <.IXIC> rose 15.35 points, or 0.72 percent, to 2,139.28.

The S&P 500 has climbed nearly 60 percent from a 12-year closing low in early March.

Two large merger deals attracted investor attention on Friday.

Kimberly-Clark said it plans to acquire I-Flow Corp , for $324 million, sending I-Flow shares up 7 percent to $12.58 on Nasdaq. Kimberly-Clark rose 0.3 percent to $59.26 on the New York Stock Exchange.

Citigroup agreed to sell its Phibro commodities trading business to Occidental Petroleum Corp . Citi's stock fell 0.4 percent to $4.63 while Occidental's stock was down 0.7 percent at $79.54.

According to the Commerce Department, the U.S. trade deficit unexpectedly narrowed in August, as trade in services pushed exports slightly higher and imports fell by a fractionally larger amount.

Stocks briefly dipped at the open on Friday, pressured by a rebounding U.S. dollar after Fed Chairman Bernanke said the Fed will eventually have to start tightening its monetary policy as the economy heals.

Volume was below average on the New York Stock Exchange, with 989.9 million shares changing hands, under last year's estimated daily average of 1.49 billion.

On the Nasdaq, about 1.96 billion shares traded, also below last year's daily average of 2.28 billion.

Advancing stocks outnumbered declining ones on the NYSE by a ratio of about 3 to 2, while on the Nasdaq, about two stocks rose for every one that fell.