"To me the trend still looks up, even though we've been chopping around," said Bill Stone, chief investment strategist at PNC Wealth Management Group. The economy "seems to be in the mode that you would expect corporate earnings to continue to grow."
The S&P 500 rose 11.11 points, or 0.6 percent, to 1,837.88, the biggest gain since Dec. 18. Nine of the 10 sectors that make up the index rose.
The Dow Jones industrial average climbed 105.84 points, or 0.6 percent, to 16,530.94 The Nasdaq composite gained 39.50 points, or 1 percent, to 4,153.18.
UnitedHealth group gained $2.27, or 3.1 percent, to $76.51 after analysts at Deutsche Bank said they expected the nation's largest health insurance company to charge customers more in premiums this year.
Johnson & Johnson climbed $1.96, or 2.1 percent, to $94.29 after analysts at RBC Capital raised their outlook on the stock to "outperform," in part due to optimism on sales of the diabetes drug Invokana.
Investors were also encouraged by the easy passage in a Senate vote late Monday of Janet Yellen's nomination to take the helm at the Federal Reserve. The vote puts an economist in the post who has backed the Fed's recent efforts to stimulate the economy with low interest rates and huge bond purchases.
The confirmation is a reminder that the Fed's policies of stimulating the economy will likely continue, said Kristina Hooper, U.S. Investment Strategist at Allianz Global Investors.
"It's just a nice little halo effect," said Hooper.
Investors will get more insight into the Fed's thinking when minutes from the Federal Open Market Committee are released on Wednesday. The Fed announced after its last meeting that it would begin winding down its monthly $85 billion bond-buying program. That stimulus was a major support for last year's rally in stocks.
Despite Tuesday's gains, stocks have started the year off on uncertain footing. Materials companies have declined 1.6 percent so far this year, led by Cliffs Natural Resources. The mining company, which was the second-biggest loser in the S&P 500 last year, is extending its slump. It's down 7 percent this year.
Manufacturers and vendors of consumer staples, such as grocers, tobacco companies and brewers, have also struggled in the first few days of this year. They're down 1.2 percent.
In government bond trading, the yield on the 10-year Treasury note fell to 2.94 percent from 2.96 percent Monday.
The most important piece of economic news to be released this week will come on Friday when the Labor Department releases its jobs report for December. The report will influence the Fed's decision on how quickly it will reduces its bond purchases in the coming months.
Among the biggest losers on Tuesday was Netflix.
The online video streaming company, the biggest gainer in the S&P 500 last year, fell $20.07, or 7.8 percent, to $339.50, after analysts at Morgan Stanley cut their outlook on the stock to "underweight." The brokerage says the online video service will face increasing competition from services such as Hulu Plus, Amazon Prime and HBO GO.
Mattel also dropped. The toy maker fell 58 cents, or 1.2 percent, to $46.04, after analysts at Goldman Sachs advised their clients to sell the stock. Goldman is predicting that the company's earnings will struggle to match expectations as sales stagnate.
In commodities trading, the price of oil rose 24 cents, or 0.3 percent, to $93.67 a barrel. Gold fell $8.40, or 0.7 percent, to $1,229.60 an ounce.