The midterm elections are certain to have implications for Wall Street, regardless of how they shape the balance of power in Congress.

That’s because in every scenario there could be winners and losers in key sectors of the market, including banking, pharmaceuticals, companies that would benefit from government infrastructure projects and those that rely on healthy consumer spending, analysts say.

The scenario deemed most likely by recent polls and analyst projections has Democrats regaining control of the House of Representatives and Republicans keeping control of the Senate. The odds are longer for Republicans or Democrats emerging with majorities in both chambers.

“Divided government equals gridlock,” said Terry Haines, head of US policy and political analysis at Evercore ISI. “Gridlock is a good thing for markets because markets like certainty.”

Here’s a look at how the market might react to the different scenarios:

SPLIT DECISION

In the scenario where Democrats regain control of the House, major policy initiatives from the White House will be dead on arrival. Compromise could be difficult, especially if the Democrats move to impeach President Donald Trump.

But Democrats might find common ground with the GOP in some areas. Agreement on an infrastructure bill could give a boost to construction equipment and transportation companies. And legislation to control drug pricing would likely be a drag on pharmaceutical company stocks.

A Democrat-led House could also lead to heightened oversight and investigations of big banks and Wall Street firms, which could weigh on financial sector stocks.

The possibility of a government shutdown also increases with a divided Congress, according to a report from UBS on the potential impact of the midterm elections. That could unnerve investors. The S&P 500 slumped nearly 20 percent during the government shutdown that occurred during Congress’ 2011 debt ceiling impasse.

THE BLUE WAVE

The odds of the Democrats taking both houses of Congress have diminished of late, possibly to the relief of Wall Street.

In this scenario, Democrats could push to shore up the Affordable Care Act, but any move to reverse the Trump administration’s hefty tax cut on corporations or its steady rollback of government regulations on businesses could be fruitless in the face of Trump’s veto.

“With this in mind, this election is really about how dysfunctional Washington will be for the second half of President Trump’s first term,” Mike Ryan, chief investment officer, Americas, for UBS Global Wealth Management, noted in the company’s report.

MORE OF THE SAME

Should Republicans remain in control of Congress, it’s likely the Trump administration will try to make the personal tax cuts included in last year’s reform package permanent. Also, on the possible to-do list: reforming entitlements, more easing of government regulations on banks and other businesses and perhaps tackling the issue of drug price controls, according to the UBS report.

If the GOP extends its majority, there also could be a push to lower capital gains taxes and enact an infrastructure spending bill.

The midterms add to the uncertainty that has buffeted the market for the past month.

After a solid third quarter that saw records for the S&P 500 and Dow Jones industrials, stocks have swooned on fears that rising interest rates and the U.S. trade dispute with China could undo some of the benefits of the GOP tax cuts and eventually squeeze corporate profit margins. October snapped a six-month winning streak for the S&P 500, giving the benchmark index its worst monthly loss in seven years.

Still, regardless of how the midterm elections turn out, history suggests stocks will be fine.

The S&P 500 has generated an average price return of 16.7 percent in the 12 months after each of the midterm elections going back to 1946, according to CFRA. That’s 18 elections, many of which ended up shuffling the balance of power in Congress.

“It turns out that under every political makeup in Washington, stocks have gone up and the economy has grown,” said Kate Warne, an investment strategist for Edward Jones.

© The Associated Press. All rights reserved.