By ALEX VEIGAIt was perhaps the most surprising trade in a record-setting week on Wall Street: How quickly investors swapped presidential pre-election jitters for enthusiasm at Donald Trump's victory over Hillary Clinton. That enthusiasm — call it the Trump rally — ultimately propelled the Dow Jones industrial average to consecutive all-time highs this week and gave the Standard and Poor's 500 index its biggest weekly gain in two years. The rally lost some steam Friday, pulling the S&P 500 slightly lower. The Dow rose 39.78 points, or 0.2 percent, to 18,847.66. The S&P 500 index fell 3.03 points, or 0.1 percent, to 2,164.45. The Nasdaq composite index gained 28.32 points, or 0.5 percent, to 5,237.11. For months, investors viewed Trump and his proposed agenda as a more risky bet for the economy and the markets than his rival, who had been widely perceived as the candidate most likely to keep the status quo in place. But then the billionaire won. And, more importantly, Republicans retained majorities in the House and Senate, ensuring that the president-elect's party will be in control when he takes office on January 20. "I don't think people planned on a straight Republican sweep," said J.J. Kinahan, TD Ameritrade's chief strategist. "All of a sudden you realize some of the things that the markets have been wishing for have a chance to be done. That's why we've rallied so much. This scenario was such a low probability, nobody was planning for it." Investors are now betting that Trump and a Republican-controlled Congress will have a clear pathway to boost infrastructure spending, cut taxes and relax regulations that affect energy, finance and other businesses. That agenda flipped investors' priorities this week away from defensive assets like bonds, utilities and phone companies, which traders had favored for much of this year, to health care, industrial and financial stocks, which notched their best week since 2009.