The mood of deep gloom that had gripped the nation's bond markets for nearly two months was broken last week by a rallying U.S. dollar. It was as if spring had finally arrived. Muted optimism replaced depression.

Long-term interest rates, up 1 1/2 percentage points since March, fell back a bit. Several corporations quickly rushed bond issues to market before things could turn sour again. Holders of some U.S. government bonds, shell-shocked by a 16 percent drop in the value of their investment, breathed a little easier.

However, the new optimism is carefully tempered. Virtually no one thinks that rates are likely to fall very far -- unless the economy slides unexpectedly into a recession. And everyone remains wary about the dollar.

Moreover, as one observer put it, "Higher rates have given the economy a swift kick."

There already is evidence that the jump in home mortgage interest rates from 8 1/2 percent to 11 percent for 30-year fixed rate loans is sapping the strength of the single-family housing market, after multifamily construction had already turned down.

Most economists believe the rise in rates will have substantially less impact on other interest-sensitive sectors of the economy, such as business investment in new plants and equipment. However, business investment already has been falling as a result of cutbacks in the oil and gas industry, completion of modernization plans and the ready availability of excess production capacity in other industries.

Economist George Perry of the Brookings Institution, who had expected both higher interest rates and strong economic growth this year, is one of a number of forecasters who have shaved their predictions because rates went so high so fast.

"The mortgage market reacted almost instantly to what happened to bonds, so you have to take a little off," Perry said. "That still makes me think you could be looking at something like 3 percent growth over the last three quarters of this year."

Given the level of rates, such a forecast marks Perry as an optimist. For instance, Scott E. Pardee, vice chairman of Yamaichi International (America) Inc., the U.S. arm of a major Japanese securities house, said, "We have a potentially slower economy than we had expected as a result of higher rates. Also, the consumer has become more cautious.

"We are not looking at an economy that is growing 3 or 4 percent but more like 2 percent. If interest rates continued higher, the economy could slip into a recession," Pardee warned.

Nevertheless, Pardee shared much of the market's new-found optimism, which flowed not so much from the size of the dollar's rally but from the fact that it occurred at all. The dollar moved up only from about 140 Japanese yen to about 144, but evidently it did so as the result of private demand for dollars, not massive buying of the U.S. currency by industrialized countries' central banks -- the only prop for the dollar earlier this year.

Changes in the value of the dollar do not directly determine the level of U.S. interest rates, of course, but it has become a sort of all-purpose indicator.

As the dollar's slide continued through the first part of this year, financial market participants saw it as evidence that private foreign investors were becoming less willing to put their money in the United States. Since the United States needs about $140 billion worth of capital from abroad this year to make up for a shortfall in its own savings, less interest in U.S. investment by foreigners would mean less available capital. Higher interest rates therefore would be needed to attract the foreign capital and to discourage some borrowing in the United States.

At the same time, a cheaper dollar meant that the prices of many imported goods were likely to rise rapidly -- and many have. To hold down inflation, market participants figured, the Federal Reserve would have to defend the dollar even if it took higher interest rates to attract those foreign investors, who would have to sell their own currencies and buy dollars with which to make U.S. investments.

Meanwhile, commodity prices began to go up more rapidly, reinforcing the belief that the Fed would have to boost interest rates to keep inflation under control.

All of those concerns remain. Last week's rally only suggested that the market's initial response to these forces may have run its course. Virtually no one thinks interest rates are about to fall back to their levels of early March, when 30-year government bonds were yielding about 7 1/2 percent and 30-year home mortgages could be had at fixed 8 1/2 percent rates.

The Federal Reserve did respond explicitly to the dollar's plight by "snugging" -- tightening credit conditions slightly -- and there is no indication that the central bank is about to reverse that action. However, a number of analysts said the shift in outlook in the market last week probably removed any pressure on the Fed for now to raise its 5 1/2 percent discount rate, the rate it charges on loans to financial institutions.

"To me the Federal Reserve has just won not the whole battle but a skirmish," said Yamaichi's Pardee. "There was a relaxation of tensions in the bond market, the stock market and the commodity markets.

"It came first from the foreign exchange side when the dollar finally broke out of a narrow trading range it had been in and moved up to between 143 and 144 yen. That was not much but it was enough," Pardee said, adding that the groundwork was laid by central bank intervention "in face of constant pressure on the dollar and from higher interest rates and {bank} reserve restraint by the Fed. In the face of an economy that is not very strong for the Fed to be snugging up on reserves is an act of courage," Pardee declared.

Pardee, who for several years was in charge of the Fed's foreign exchange intervention activities, said the dollar might well take another jump upward to, say, 150 yen. If the dollar recovers enough, it could take the pressure off interest rates here, he said, adding, "That's important because the higher rates have given the economy a swift kick."

Donald H. Straszheim, chief economist at Merrill Lynch & Co., believes any decline in interest rates will be small and has raised his forecast for interest rates for the rest of the year. "By now, the reasons are depressingly familiar," he wrote in a weekly economic commentary. "The continued softness of the dollar restricts the Federal Reserve's freedom of action. Dollar weakness and rising fears of inflation -- whether justified or not -- have forced bond yields higher."

Straszheim expects 30-year Treasury bonds to be yielding about 9 percent at the end of the year, about where they were prior to last week's rally. He also predicts that the yield on three-month Treasury bills, which along with most other short-term rates have gone up much less than long-term rates, will edge up toward 6 1/2 percent by then.

"Domestic economic activity is sluggish, with two consecutive months of decline in industrial production and housing starts," Straszheim said. "Retail sales are anemic, and durable-goods orders fell in April. Higher interest rates will further restrain the economy."

While the realization that inflation has moved up a notch is part of the reason that rates have gone up, the "chief problem" is the vast deficit the United States has in its trade and other financial transactions with the rest of the world, the Merrill Lynch economist continued. To finance that international deficit, the United States "must pay returns high enough to attract private foreign capital. The result is higher interest rates than would otherwise be the case."

In a forecast published last week, economist Alan Greenspan of Townsend-Greenspan & Co. put that so-called current account deficit at $143 billion for 1987, virtually unchanged from last year's $142 billion.

According to actual figures for 1986, gross private saving in the United States totaled $679 billion. Gross private domestic investment was only a tiny bit higher, $684 billion. But the federal budget deficit of $203 billion, only partially offset by a state and local government surplus of $63 billion, meant that the United States wound up about $140 billion short of capital to support the actual level of investment. The foreign inflow of capital made up the difference.

These government budget figures are calculated somewhat differently than those in the federal unified budget (which are those usually quoted) and are on a calendar rather than a fiscal year basis. For fiscal 1986, which ended last Sept. 30, the unified budget deficit was $221 billion.

Greenspan predicts in his forecast that the need for foreign investment both this year and next will remain above $140 billion as total saving stays far short of total investment. The alternative to the foreign capital inflow would be to reduce investment, a development that higher interest rates are already causing in housing.

At the Brookings Institution, Perry said, "If policymakers can convince markets that the dollar will be stable, then the interest rate differentials {between the United States and Japan or Europe} are large enough to attract capital. What frightened foreigners was the dollar.

"We know that on balance, private investment from abroad has been negative this year," he continued. One sign of the drying up of foreign private investment has been the way in which the yields on long-term bonds, which are bought by private investors, have gone up so much more than, say, yields on Treasury bills, which are bought by foreign central banks after they have acquired dollars as a result of intervening in foreign exchange markets.

"The markets may not realize it," Perry said, "but I think the policymakers have won on this one as far as the dollar goes. The big decline in the dollar is behind us, not ahead of us. If markets become convinced of that, then bonds could rise some . . . but they are not going back where they were."

To Perry, there are two possible wild cards in his economic forecast, one that would push interest rates up, the other that would push them down.

If the West German government should continue "to be so stubborn {about stimulating its economy} as to let a recession happen, then I would have to revise my forecast downward. I don't think they will do that, but it is important for the United States. There are enough problems out there that you don't want them getting worse."

Perry's second concern is food prices, which have been rising much more rapidly than he expected. "If food prices do not continue up, we are looking at 5 percent inflation this year. If food prices turn out to be a real surprise -- if this resembles 1973 in any way -- then there will be a bad reaction. For one thing, the Fed could react with higher interest rates," he said.