NEW YORK, JAN. 31 -- Stocks closed higher today as optimism about the outcome of the Persian Gulf War, hope for a revitalized economy and some positive earnings surprises rallied investors.

The Dow Jones industrial average rose 23.27 points to 2736.39, a new six-month high. Gaining issues led losers by a 2-to-1 ratio on the New York Stock Exchange, where volume was a heavy 204.2 million. Traders said the market closed on a wave of computer-driven "buy" programs that lifted the Dow sharply, similar to Wednesday's closing, when the Dow gained 50 points.

"The market tells you what's going to happen in the future," said block trader Brad Weekes at Donaldson, Lufkin & Jenrette. "This stock market is telling you that the war is going to be short, the recession is going to be mild, and interest rates are coming down as the Fed continues to do exactly what the White House wants it to do."

An unexpected increase in German interest rates roiled European markets and knocked the dollar, but had little apparent effect on stocks, traders said.

"The catalyst {for stocks} has been the tremendous amount of cash," said Jeffrey Kaminsky of Mabon Nugent. "People with huge positions are getting a little itchy."

The market seemed to take in stride reports of an Iraqi missile attack on the Israeli-occupied West Bank and warnings from Federal Reserve Chairman Alan Greenspan about potential damage to the economy from a longer war.

"People seem to be guessing that this will be a short war," said Rao Chalasani, an investment strategist at Prescott Ball & Turben.

Oil prices, after falling nearly $1 Wednesday, regained some of their losses, but analysts said trading on the New York Mercantile Exchange was subdued. Crude oil for March delivery closed 57 cents higher at $21.54 a barrel. Unleaded gasoline for February delivery ended 3.37 cents up at 68.33 cents a gallon. Heating oil for February delivery gained 1.06 cents to 71.25 cents a gallon.

"It's war nerves," one trader said, explaining the rise. Said another, "The start of the ground war is pushing prices up."

On the stock market, Chase Manhattan topped the most active list in dividend-related trading. It rose 1/8 to 11 7/8 on volume of more than 3 million shares.

Reebok International climbed 2 1/4 to 14 3/4 after reporting fourth-quarter earnings on target with the company's forecasts.

Freddie Mac jumped 4 to 61 3/8. It reported a fourth-quarter profit after a provision for loan losses that was more than double the provision in the year-earlier quarter. Chubb added 3 3/8 to 60 3/8. It reported quarterly profits that were higher than expected, analysts said.

Lotus shares added 1 1/2 to 16 3/4. Its stock, depressed this week by concerns of sharply lower earnings, rose after the company reported a fourth-quarter loss in line with Wall Street estimates, analysts said.

Compaq continued its strong advance after Wednesday's report of strong fourth-quarter profit. It added 3 to 69 3/4 after rising 3 1/2 on Wednesday.

Xerox Corp., whose fourth-quarter results exceeded expectations, jumped 5 3/8 to 48 3/4.

Several airline stocks, which gained Wednesday, slipped as First Boston said the shares should trade lower in the near-term based on expectations of weak traffic patterns.

UAL Corp. lost 5/8 to 128 3/4 and USAir Group fell 1/2 to 20 3/8.

The NYSE composite index rose 1.57 to 187.59, the Standard & Poor's 500 rose 3.02 to 343.93, the American Stock Exchange index gained 3.07 to 317.54 and the Nasdaq over-the-counter index was up 5.67 to 414.20.