It is late in the day, but leaders of both parties are lurching toward realism on fundamental economic issues that they have been doing their best to avoid. Democrats are starting to talk sensibly about trade, and Republicans are shutting down some of their posturing on taxes. With a bit of luck, there may yet be an opportunity this year and next to take some substantial steps to improve America's competitive position in the world and hand on something better than a hangover of debt to the next generation.

These uncharacteristically upbeat observations are occasioned by a series of developments in the last few weeks that suggest a welcome attack of sanity has hit Washington. It began well before Senate Republicans began publicly their latest effort to mandate a balanced budget by the end of the decade. I first noticed this phenomenon when James C. Miller III, the newly appointed director of the Office of Management and Budget, testified Sept. 24 at his confirmation hearing. Instead of repeating the ritual administration opposition to any form of deficit-cutting tax increase, Miller said he would not rule out that option as part of a budget package. "Nothing is off-base," Miller said. "Nothing is sacrosanct."

This comment from the incoming budget director was considerably more helpful than his predecessor's acknowledging last Sunday that what America needs is a good $100 billion tax increase. David Stockman offered this judgment on ABC's "This Week With David Brinkley" precisely 60 days after his resignation as director of OMB became effective.

It would have been more important -- and principled -- for him to have said that while he was in office, and especially a year ago. Then, a fellow named Walter Mondale was being cuffed around pretty good by Stockman's boss, President Reagan, and the rest of the GOP establishment, for arguing that a tax increase had to be part of an overall budget-deficit solution.

But late as he was, Stockman told the country and his fellow Republicans what is palpably the case. "It is very clear to me, after five years," he said, "that the spending-cut episode is over. We've had a referendum on what we want in the budget, and what we don't. What's left, most of the people want. And we're going to have to raise taxes to pay for it."

That simple truth -- accepted by the Democratic Party in 1984 and by the Senate Republicans in 1985 -- can become the basis for sound national policy in 1986, if Reagan can be persuaded by Miller, Treasury Secretary James A. Baker III and others to perform another of his famous flip- flops. Let us hope that they are eloquent.

Meantime, in the Democratic ring of the Washington policy circus, there are hopeful signs of returning sanity on the trade issue. For months, the Democrats have been doing nip-ups on trade, happily exploiting the Reagan administration's peculiar indifference to the damage major sectors of American manufacturing have suffered at the hands of foreign competitors.

What was first seen by them as a way to show the home folks that they put America first, or as a way to send a message to the administration to get cracking on a trade policy, or as a warning signal to the Japanese to open their home markets to American goods, became a matter of high policy and political strategy to some victory-starved Democrats.

But, as a serious policy, protectionism long ago earned the public's distrust. Belatedly, the Democrats are showing signs of realizing that bad policy really cannot be good politics for them.

Last week, the Democratic Leadership Council, a group of elected officials that likes to think of itself as being in the mainstream of the party, issued a report on international economic competition. It clearly identified intrinsic American factors as the major causes of the worsening trade balance and the declining U.S. position in the world economy.

The inflated value of the dollar (in large part, probably, the result of our budget deficit), the lag in U.S. productivity growth, relatively high real interest rates and a drop in personal savings rates account for at least 80 percent of the problem of America's failing performance in international trade competition, the Democrats said.

These are problems that we -- and only we -- can solve. Sen. Lawton Chiles (D-Fla.), ranking senator on the Budget Committee and a participant in the briefing on the Democratic report, said that identifying the real problems was the necessary first step in getting Congress and the administration to move past "quick fix" solutions.

Rep. Richard Gephardt (D-Mo.), another leader of the group, acknowledged that the legislation he and other prominent Democrats have sponsored to slap a 25 percent tariff on Japan and other countries that protect their home markets against American goods can be only "a small part of the solution -- a short-term effort to stop the hemorrhage" of trade deficits.

House Majority Whip Tom Foley (D-Wash.), as shrewd and principled a politician as the Democrats have, cautioned last week that "the intensity factor" is still propelling protectionist measures to passage in the House. But he held out hope that Reagan's expected vetoes would be upheld, provided the administration sustains its own belated trade policy offensive.

Slowly, slowly, the forces of reasonableness are gaining ground in both parties.