The U.S. stock market hit record highs this week as a stunning surge of optimism has flooded Wall Street and fears of an imminent recession have all but disappeared.

The market “melt up” is driven by three main factors: belief that the trade war has peaked, belief that there won’t be a U.S. — or global — recession in 2020, and belief that the Federal Reserve has the market’s back. Investors are making a bet that corporate profits will be a bit better next year than this year. They see a future where American consumers keep spending and businesses start investing again as the economy stabilizes and President Trump hits pause on any more tariffs.

The three main stock indexes hit their peaks early in the week, retreated slightly for a few days but rose again Friday. The stock market is effectively at its highest level in U.S. history, a phenomenon that the White House has openly cheered.

“I am of the opinion that neither the U.S., nor the global, economy are facing a recession through the end of 2020,” said Ed Yardeni, head of Yardeni Research. “The market rightly anticipates Trump wants another term as president, and he’s got enough going on with impeachment issues that he wants to put trade on the back burner for a while.”

But there are a lot of “ifs” in the bullish scenario for next year, especially around trade, which is why markets have already pulled back slightly from their highs. This remains a tip-toe higher market, many analysts say. They point out that while the Dow Jones industrial average is up nearly 20 percent this year, it is about 4 percent higher than it was on Oct. 3, 2018, an indication of the hesitancy that remains among investors.

“It’s a nervous market," said Howard Silverblatt, senior analyst at S&P Dow Jones Indices. "Everyone is talking a great ballgame, but when you come down to it, everyone has their finger just over the sell button. You are one tweet away from concern.”

Goldman Sachs sent a note to clients on Nov. 3 declaring that “tariffs have peaked” and Trump was unlikely to implement any more taxes on China. In a sign of how quickly momentum can shift, the prominent investment bank sent another note on Nov. 19 saying risks of a tariff increase have risen again.

Trump largely credits himself for the recent record highs. The stock market is “through the roof” since Election Day, he said as cameras recorded his Cabinet meeting Tuesday. “That’s something nobody would have thought possible.” Trump adviser Peter Navarro has predicted that the Dow, which broke 28,000 for the first time Friday, will soon surpass 30,000.

Most market analysts praise the Fed, not Trump, for the rebound in the stock market this year. The Fed has cut interest rates three times, a move that is likely to stimulate the economy well into next year. The housing market is already showing signs of an uptick.

“I believe the stock rally is justifiable because of what Fed Chair Jay Powell said a few weeks ago when he made it clear there is a high bar for raising rates,” said Kristina Hooper, chief global market strategist at Invesco. “This is an environment in which monetary policy is going to be an important support for equities.”

Stocks rallied after Trump enacted the largest corporate tax cut in U.S. history, but his trade war has caused business investment to contract for the past two quarters, a drag on the economy and an indication of how concerned business leaders are. In a report out this week, researchers at the Federal Reserve Bank of Dallas found that policy uncertainty has triggered most of the downturns in the stock market since Trump took office.

“In the absence of such uncertainty, the Standard & Poor’s’ 500 Index would have been about 12 percent higher over the past two years,” wrote Pavel Kapinos and Alex Musatov from the Dallas Fed.

What has changed in recent weeks is that experts see less risk of a recession — or near-recession — in 2020. Few outside the White House are predicting an economic surge, but the growing consensus is that the economy will continue to chug along around 2 percent growth, enough to keep profits healthy and jobs fairly plentiful.

Yardeni and his research team describe it like this: Corporate revenue was flying high at 9 percent last year as economic growth ticked up in the wake of the big tax cuts. This year revenue for S&P 500 companies is widely expected to fall under 4 percent, a weak year but not the disaster some feared over the summer. The prediction for next year is revenue growth over 5 percent — a slight pickup and part of the reason the market has been rallying.

There are a number of factors playing into the market momentum. Historically, the stock market has risen by more than 10 percent in the six months following the Fed’s first rate cut, said Sam Stovall, chief investment strategist at CFRA Research. The third and fourth years of a president’s term have also had strong market performance, according to Bespoke Research.

A number of key economic indicators have also come in better than expected: Businesses in most industries continue to add jobs, consumers keep spending and even the manufacturing slump appears to be plateauing instead of getting worse. The yield curve, which flashed a major warning sign in August when it inverted, is now back to a normal shape.

Corporate earnings have also outperformed with 75 percent beating expectations, according to the latest data from S&P Dow Jones Indices. But long-time market analyst Silverblatt remains cautious. He has been pointing out to readers of his popular market emails that most companies cut their earnings expectations a lot this year. They are beating this much lower bar, not the initial bar they set heading into 2019.

Despite the fresh market highs, many investors continue to take money out of stocks and pour it into ultra-conservative money market funds, another sign of unease. In a report out this week, Morningstar said investors have removed more than $36 billion from U.S. equity funds so far this year, including pulling nearly $15 billion out in October alone. In contrast, money market funds are sitting on the largest pile of cash in a decade.

There’s growing belief the markets and the economy are unlikely to tank in 2020, but debate remains over how much upside is left in a bull market that has been running for more than a decade.

Related: