Stocks edged up slightly on Friday, capping a week in which a downturn in oil prices helped investors mount a modest rally despite the looming uncertainty of the presidential election Tuesday and lingering concern over the war in Iraq.

The markets have been going through a bumpy stretch, seesawing between gains and losses. Analysts say this week's rally could continue with a clear electoral victory next week by either presidential candidate. But even that is unlikely to alleviate investors' underlying anxiety about war and energy costs.

"The election being too close to call is bothersome, but it's not stay-out-of-the-market bothersome," said Art Hogan, chief market strategist at Jefferies & Co. "I think what is on investors' minds is Iraq, it's energy and then it's the election. I'd put energy at the top of the list."

One investor taking a wait-and-see attitude for now is 28-year-old Maryland resident Laverne Evans. Evans said she is staying in the market but is holding off on deciding to invest more until after she has a better sense of what will happen in Iraq. Knowing who the president will be for the next four years will help, she said, but won't on its own give her the kind of clarity she is looking for. "Congress is remaining the same. Everything else is staying the same," she said. "The war is still going to be the big thing."

Don Benedict, a 55-year-old retired federal employee living in the District, said he is likely to stay out of stocks as long as the United States -- and U.S. companies -- remain shadowed by the negative international opinion the war has generated. "In the eyes of the world, this country has got a very big black eye," he said.

With light volume yesterday on the last trading day of the month, the Dow Jones industrial average added 22.93 points, the Standard & Poor's 500-stock index was up 2.76 points and the Nasdaq composite index was virtually unchanged. For the week, the Dow gained 2.76 percent, to 10,027.47. The Nasdaq and the S&P 500 tacked on 3.1 percent, with the Nasdaq closing at 1974.99 and the S&P 500 finishing at 1130.20.

Although Wall Street traditionally favors Republicans over Democrats, the market has already factored in the possibility of a victory for Sen. John F. Kerry, experts say, so it could rally if the Democratic nominee wins decisively and ends the uncertainty over who will occupy the White House in 2005. A Bush win could ignite an even stronger rally as investors embrace continuity in Washington and the likely extension of the president's tax cuts.

If the market does not rally after the election, it could mean that investor views on the economy have turned decidedly sour.

The nightmare scenario for stocks is an uncertain election outcome that requires weeks of recounts and legal challenges. "Prolonging the pain would not be well-received," said Alfred E. Goldman, chief market strategist at A.G. Edwards & Sons.

But Goldman added that the experience of the 2000 fiasco in Florida could make another contested election easier for the market to bear. "I don't think it would be as dramatic as four years ago," he said. "Been there, done that."

Just as the election results could influence the markets, the markets' performance could have an effect on the outcome of the election. Strategists and traders say that viewed in historical terms, a lackluster showing by stocks this year, especially in recent months, could portend a Kerry victory.

Goldman said that in presidential election seasons since 1900, the Dow Jones industrial average has risen 16 times following the close of the last political convention. In 14 of those instances, the incumbent won. The market dropped 10 times after the last convention, Goldman said, and in seven of those cases, the incumbent or incumbent party lost. As of yesterday, the Dow was down 262.81 points since closing at 10,290.28 on the last day of the Republican National Convention.

But others said 2004 could confound the historic trend because so many voters are focused on the war on terrorism and the violence in Iraq.

Before this week, the markets had been sagging, with companies reporting earnings that were considered respectable but not outstanding. In addition to pressure from oil prices, a significant amount of recent weakness in the Dow has been caused by large declines in companies such as insurer American International Group, the subject of an investigation by New York state Attorney General Eliot L. Spitzer, and drugmaker Merck, which had to pull its top-selling painkiller, Vioxx, off the market after a study showed that it raised the risk of stroke or heart attack.

Other Indicators

* The New York Stock Exchange composite index rose 22.21, to 6692.71; the American Stock Exchange index rose 3.79, to 1311.39; and the Russell 2000 index of smaller-company stocks fell 1.84, to 583.79.

* Advancing issues outnumbered declining ones by 7 to 5 on the NYSE, where trading volume fell to 1.5 billion shares, from 1.63 billion on Thursday. On the Nasdaq Stock Market, declines narrowly outnumbered advances and volume totaled 1.62 billion, down from 1.8 billion.

* The price of the Treasury's 10-year note rose $2.50 per $1,000 invested, and its yield fell to 4.03 percent, from 4.06 percent on Thursday.

* The dollar fell against the Japanese yen and the euro. In late New York trading, a dollar bought 105.86 yen, down from 106.21 late Thursday, and a euro bought $1.2791, up from $1.2745.

* Light, sweet crude oil for December delivery settled at $51.76, up 84 cents, on the New York Mercantile Exchange.

* Gold for current delivery rose to $428.50 a troy ounce, from $425.10 on Thursday, on the New York Mercantile Exchange's Commodity Exchange.

White reported from New York.

The markets ended a recent losing streak, but energy costs, the war in Iraq and Tuesday's election are still adding to investor anxiety.