WASHINGTON — As America’s stock markets have reached record highs, they have had few louder cheerleaders than President Trump.

“Highest Stock Market EVER,” he said on Twitter on Monday.

Before the stock exchanges’ opening bell on Tuesday, Mr. Trump pointed out in a tweet that the Dow Jones industrial index’s recent surge started just after he was elected. (He also lamented, incorrectly, that the press was downplaying that fact: “Mainstream media seldom mentions!”)

The Run-Up

The podcast that makes sense of the most delirious stretch of the 2016 campaign.

And on Thursday, Mr. Trump made clear that he thinks he deserves credit for the latest record high, tweeting, “That doesn’t just happen!”

But it was not long ago that Mr. Trump, as a presidential candidate bent on casting the economy as a disaster, said that the stock market was a bubble that should make investors wary.

‘They’ll get wiped out’

In the early days of his candidacy, Mr. Trump assailed the economic recovery as a mirage and mused about a potential conspiracy that was being plotted between Janet L. Yellen, the Federal Reserve chairwoman, and President Barack Obama. The theory was that she was keeping interest rates low so that the president would not leave office as another recession began.

“They worked all their lives to save and now what happens is they’re being forced into an inflated stock market and at some point they’ll get wiped out,” Mr. Trump told The Hill in October 2015 regarding American workers.

‘You heard it here first’

Before the Iowa caucuses, Mr. Trump decided to dispense some financial advice. The recent dip in stocks was a harbinger of worse things to come, he warned, and he hoped that the coming crash did not happen after Mr. Obama left office.

“Remember the word bubble? You heard it here first. I don’t want to sound rude, but I hope if it explodes, it’s going to be now, rather than two months into another administration,” Mr. Trump said in December 2015.

‘A financial bubble’

Although he was feeling confident about locking up the Republican nomination in April 2016, Mr. Trump was feeling increasingly bearish about stocks. He told The Washington Post that they were overvalued and that the strong data that showed a healthy economy were essentially phony.

“I think we’re sitting on an economic bubble. A financial bubble,” Mr. Trump said.

‘The artificial stock market’

By September, he was arguing that the Federal Reserve was propping up a “false economy” that is actually weak.

“The only thing that is strong is the artificial stock market,” Mr. Trump told Reuters.

‘A big, fat, ugly bubble’

Mr. Trump saved his most brutal assessment of the stock market, and the economy, for his first presidential debate with Hillary Clinton. In response to her criticism of his economic proposals, he said that the recovery was the worst since the Great Depression and that it would come crashing down the moment that interest rates rise.

“The only thing that looks good is the stock market, but if you raise interest rates even a little bit, that’s going to come crashing down,” Mr. Trump said. “We are in a big, fat, ugly bubble.”