"The trend of the economy appears to be in a positive direction," said Michael Sheldon, chief market strategist at RDM Financial Group. "Unless this really gets ugly, we think the markets should start to look ahead to what we believe should be better economic data over the next six to 12 months."
In the latest encouraging news on the economy, a private industry group reported Tuesday that U.S. manufacturing expanded at the fastest pace since April 2011 last month on stronger production and hiring.
The Dow Jones industrial average rose 62.03 points, or 0.4 percent, to 15,191.70. The Standard & Poor's 500 index gained 13.45 points, or 0.8 percent, to 1,695.00. The Nasdaq composite rose 46.50 points, or 1.2 percent, to 3,817.98.
All ten sectors of the S&P 500 rose, led by gains in health care and technology.
Merck helped lift the health care sector. The drugmaker's stock rose $1.13, or 2.4 percent, to $48.74 after it announced plans to cut another 8,500 jobs as part of a plan to reduce its annual costs by about $2.5 billion by the end of 2015.
The technology sector was given a boost by Apple, which gained $11.21, or 2.4 percent, to $487.90, after billionaire investor Carl Icahn tweeted about his dinner meeting with Apple's CEO Tim Cook. Icahn, who said he has invested $2 billion in Apple, is pushing for the company to spend $150 billion buying its own stock.
"I feel very strongly that this should be done," Icahn told CNBC in an interview. "It's a no-brainer."
The Apple board pledged in April to spend $60 billion buying back its stock through the end of 2015. About $18 billion of that commitment had been exhausted through June.
The S&P 500 index has fallen 2 percent since climbing to a record on Sept. 18, when the Federal Reserve surprised investors by saying it would continue with its economic stimulus. The index has fallen seven out of eight days leading up to the partial government shutdown.
"We're not jumping in with both feet but we're selectively putting money to work," said Joseph Quinlan, chief market strategist for U.S. Trust Bank of America Private Wealth Management. "On the other side of the government shutdown, you've got continued support from the Fed and a global economy that's rebounding."
Many investors still predict that the budget fight will be resolved before it spills over into a dispute about raising the nation's borrowing limit. Treasury Secretary Jack Lew said last week that the government would run out of borrowing authority by roughly Oct. 17.
The last time the borrowing limit, or debt ceiling, issue came up in August 2011, it led to a downgrade of the United States' credit rating by Standard & Poor's. The Dow went through nearly three weeks of triple-digits moves almost daily shortly thereafter.
"To some extent investors are conditioned to a certain amount of drama and if we can get the drama behind us quickly it won't be a big deal," said Dean Junkans, Chief Investment Officer for Wells Fargo Private Bank. "If this goes beyond the middle of next week, the market will get increasingly more worried about the debt ceiling."
In other stock trading, the Russell 2000, an index of small-company stocks, rose to a record level, a sign that investors are still willing to buy riskier assets despite the government slowdown.
The Russell rose 13.64 points, or 1.3 percent, to 1,087.43.