The dollar continued to surge yesterday, posting extraordinary gains as the Federal Reserve and other central banks entered the markets for the second day in a row to buy dollars and strengthen the currency.

Following Monday's pattern, yesterday's dollar rally also gave a lift to the stock market, where the Dow Jones industrial average rose 16.25 points to close at 2031.50.

The Dow index was up about 50 points at one stage before profit-taking reduced the gain. Nevertheless, in the first two days of stock market trading of the year the Dow was up a total of 92.67 points, or 4.7 percent. {Details, Page D1.}

The extent of the dollar's rise in this period took some experts by surprise. The gains yesterday were described as among the biggest one-day advances ever. In New York, the dollar rose yesterday to 127.55 yen, up 5 yen, or 4 percent, for the day. From its low point of 120.25 yen on Monday, the dollar was up more than 6 percent.

Against the West German mark, the dollar rose more than 4 pfennigs to 1.6290 marks, or 2.73 percent for the day. From Monday's low of 1.57 marks, the dollar was up about 4 percent in response to the heavy, coordinated intervention.

Also bolstering the dollar yesterday was rising optimism about a report due next week on the U.S. trade deficit.

The dollar rose 3.15 yen to open at 128.20 yen in Tokyo trading today but lost ground later, closing the morning session at 127.15 yen, The Associated Press reported.

"The expectation is crystalizing that the news may be taking a favorable turn," said Henry Kaufman, a Salomon Brothers economist. Financial market observers said that the trade report for November, to be issued Jan. 15, will show an improvement from the staggering $17.6 billion deficit of October.

"It may be no worse than $15 to $16 billion, and maybe a little better than that," Kaufman said. Later on, when the figures reflect the trade balance for the first quarter of 1988, the improvement in the deficit "may be even more substantial," he said.

"The market was beginning to assume that the dollar was bottoming out anyway," said Robert Hormats of Goldman, Sachs & Co., "and then the central banks came in to buy. The intervention took place at the right psychological moment. All the anecdotal evidence you get talking to businessmen is that there will be a big improvement in exports.

"In intervention, timing is everything, and this time, their {the central banks} timing was right."

The dollar's chronic weakness has caused concern that it could lead to a new bout of inflation and increases in interest rates, which could slow the economy. The Federal Reserve, it is feared, could be forced to raise interest rates in order to make the dollar more attractive to foreign investors.

The dollar's surge yesterday was interrupted briefly when a remark by White House press aide Marlin Fitzwater that the dollar appeared "to have stabilized" was seized upon as an excuse by some to sell dollars and take profits.

"'Stable' wasn't the right word to use," said Charles Taylor, international economist at Prudential Bache here. "Saying the dollar is stable when it's been jumping around like a yo-yo on a string is hardly credible."

And Mark Johnson, a Fidelity Bank trader in Philadelphia, said Fitzwater's comment was "probably the dumbest thing I've heard. The dollar is about as stable as a man with a heart attack."

At that point, the dollar, which had been selling at around 1.6325 marks and 1.2725 yen in New York, slipped to about 1.63 marks and 1.27 yen.

But the persistence of central bank intervention started the dollar back up against the yen. Some dealers, who had sold dollars short on the bet that the U.S. currency would turn down again, had to scurry to cover their positions.

The gains at the end of a two-day period were rated by observers as impressive, and perhaps suggesting that for the time being, at least, the dollar had reached a turning point.

But Prudential-Bache's Taylor warned that the markets won't know for sure how favorable the outlook for the dollar and the trade balance is until the pace of the U.S. economy recedes, dampening consumer willingness to spend money -- especially for imports. Said Taylor, "we'll see how strong the U.S. economy is looking when we get the unemployment number {for December} on Friday."

The dollar's gain against the yen put the U.S. currency above the 126-yen level of Dec. 22, when the Group of Seven industrial nations said it had fallen far enough. The rise against the West German mark put the dollar almost at its 1.63-mark level at the time of the G-7 statement.

Traders appeared to feel yesterday that the dollar may have hit bottom when it touched 120.25 yen in Sydney on Monday, and that the G-7 nations had probably set 120 yen as the point at which they would make a stand with coordinated intervention. Assuming the ministers set their goals in round numbers, the floor for the dollar against the West German currency was probably 1.55 marks, a level it did not quite reach before starting to recover.

Although dealers recognize the limitations of intervention, they were impressed with the round-the-world activity of the central banks, which for the most part took pains to announce that they were in the market buying dollars.

"Whereas the central banks were buying dollars at a low price last week, this week they are buying dollars at progressively higher prices, and they are staying in the market. That is a significant change in intervention policy," one trader said.

Kaufman and others stressed that the dollar was ready for a technical rebound. "We have had a massive decline over a long period, and that ought to produce a technical strengthening, especially when you have massive intervention," Kaufman said.

He added that the markets seemed to be accepting the evidence that the G-7 partners want to coordinate their economic policies, "but it is being accepted that for the time being, that coordination will exclude a tightening of monetary policy in the United States. So we have a period of temporary relief, but not necessarily permanent change."

In Japan, Finance Minister Kiichi Miyazawa told a news conference that the G-7 countries -- the United States, Japan, West Germany, France, Britain, Canada and Italy -- would continue to intervene in response to sudden exchange rate changes.