U.S. stocks closed higher Tuesday, led by gains in tech stocks, after Fed Chair Janet Yellen said it is appropriate for policymakers to proceed 'cautiously.' (Tweet This)
The S&P 500 and Dow Jones industrial average recovered from a lower open to close at their highest levels of the year so far and in positive territory for 2016. Both indexes are within 4 percent of their 52-week intraday highs.
"I think it's kind of a perfect storm for stocks to move higher at the moment," said John Caruso, senior market strategist at RJO Futures. "You got a dovish Fed, coupled with an end-of-quarter. You got some window dressing going on."
The Dow Jones industrial average closed just below session highs. Earlier, the index briefly added 107 points, after dipping 101 points in morning trade.
Apple closed about 2.4 percent higher to contribute the most to gains in the Dow, while 3M was the greatest contributor to declines. The Nasdaq composite outperformed with gains of 1.67 percent, its best day in more than two weeks.
The Nasdaq extended gains and the Dow and S&P turned higher in midday trade after Yellen said in prepared remarks that economic readings are mixed and it is appropriate to proceed cautiously in adjusting policy.
Art Hogan, chief market strategist at Wunderlich Securities, said the text "sounds more like two weeks ago."
"Some of the trades that were unwinding are winding back up," he said.
Read MoreYellen pushes back at hawks
The S&P 500 climbed back into positive territory for the year so far with information technology leading advancers. Bank stocks underperformed.
"The market is happy. It's good news for equity prices on a dovish Fed, but a dovish Fed also indicates there are problems out there, which is concerning as well," said Douglas Cote, chief market strategist at Voya Investment Management.
In a question-and-answer session following her speech, Yellen said there are risks, but "not all to the downside."
Treasury yields edged lower, with the below 0.80 percent, its lowest since March 1, and the 10-year yield near 1.81 percent, the lowest since March 8.
"To me, Yellen is changing her reaction function, certainly making the threshold for hiking a little higher and the threshold for staying put lower," said Eric Stein, co-director of global fixed income at Eaton Vance Management.
"Given the change in the Fed's reaction function, maybe there's a bias towards the curve steepening further," he said.
The Treasury Department auctioned $34 billion in five-year notes at a high yield of 1.335 percent.The bid-to-cover ratio, an indicator of demand, was 2.38.
The U.S. dollar index extended earlier losses with a decline of more than 0.8 percent, for its worst day since March 17. The euro held near $1.13 and the yen was at 112.68 yen against the greenback.
The iShares MSCI Emerging Markets ETF (EEM) jumped to close nearly 1.4 percent higher.
Gold spiked to session highs, briefly up $20 to $1,240 an ounce before settling up $15.70 at $1,235.80 for its first positive day in four.
Yellen gave her speech, titled "The Outlook, Uncertainty, and Monetary Policy," at the Economic Club of New York.
"One of the most important things she said is there's a recognition in the Fed that there were very turbulent times in January," said Alan Rechtschaffen, financial advisor and senior vice president at UBS Wealth Management Americas.
"I think she's uncertain," he said. "I think the fact they say they're uncertain means they're uncertain."
Recent policymaker comments have leaned more hawkish than what came out of the March 15-16 meeting, which was more dovish than many expected.
"No doubt Yellen is the clear leader of the Fed and her opinion weighs heavily," said Mike Arone, chief investment strategist for the U.S. intermediary business at State Street Global Advisors.
U.S. stocks opened lower as declines in oil prices weighed. U.S. crude oil futures settled down $1.11 at $38.28 a barrel.
The major averages pared losses and the Nasdaq composite turned higher after consumer confidence showed a rise in March to 96.2 from 94.0 in February.
"That's a good sign," said Peter Cardillo, chief market economist at First Standard Financial.
With Tuesday's gains, Apple came within 20 percent of its 52-week intraday high, out of bear market territory.
Late Monday, the Justice Department said it no longer needs Apple's help after accessing data on the iPhone used by a shooter in last year's San Bernardino, California, attacks.
"We believe the resolution is a net positive for Apple. ... It alleviates a potential risk for Apple," said Angelo Zino of S&P Capital IQ, which maintained its "strong buy" recommendation on Apple stock in an early Tuesday note.
In other central bank news, Dallas Federal Reserve President Robert Kaplan said in a Reuters report he expects the U.S. economy to prove resilient this year but that the nation's central bank should proceed gradually and cautiously in raising rates.
In comments to reporters Kaplan declined to rule out a rate increase at the Fed's April meeting, Reuters said.
He was scheduled to speak again at 4 p.m. ET.
Earlier, in a speech at the National University of Singapore, San Francisco Fed President John Williams said the U.S. economy remains on track for a gradual path of interest rate hikes and fears over the impact of a slowing global economy and bouts of financial volatility are overdone.
Williams is a non-voting member of the Federal Open Market Committee this year, while Kaplan is an alternate member.
Separately, the S&P/Case-Shiller 20-City Composite Index for January showed a 5.7 percent rise from the previous year. The March jobs report is due Friday.
Lennar beat estimates by 11 cents with earnings of 63 cents a share, on revenue that also topped expectations. The home builder reported a nearly 10 percent increase in new orders and a 12 percent rise in deliveries.
The stock closed up 3.17 percent, helping the SPDR S&P Homebuilders ETF (XHB) gain nearly 1.7 percent for its best day since March 11.
Overseas, major European indexes closed mostly higher. Asian equities closed mostly lower, with the Shanghai composite off more than 1 percent and the Nikkei 225 about 0.2 percent lower. The Hang Seng closed up 0.1 percent.
The Dow Jones industrial average gained 97.72 points, or 0.56 percent, to 17,633.11, with Apple leading advancers and 3M the greatest decliner.
The closed up 17.96 points, or 0.88 percent, at 2,055.01, with information technology leading all 10 sectors higher.
The Nasdaq composite closed up 79.84 points, or 1.67 percent, at 4,846.62.
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, fell below 14.
About four stocks advanced for every decliner on the New York Stock Exchange, with an exchange volume of 968 million and a composite volume of 3.8 billion.
Trade volume on Monday was the lowest of the year so far, following the holiday-shortened week that saw three of the lowest trade volume days of the year so far.
—Reuters contributed to this report.
On tap this week:
8:15 a.m.: ADP employment
1 p.m.: $28 billion 7-year note auction
8:30 a.m.: Jobless claims
9:30 a.m.: Chicago Fed President Charles Evans
9:45 a.m.: Chicago PMI
5 p.m.: New York Fed President William Dudley
March vehicle sales
8:30 a.m.: Employment report
9:45 a.m.: Manufacturing PMI
10 a.m.: ISM manufacturing
10 a.m.: Construction spending
10 a.m.: Consumer sentiment
1 p.m.: Cleveland Fed President Loretta Mester
*Planner subject to change.
More From CNBC.com: