By Caroline Valetkevitch

(Reuters) - U.S. stocks ended little changed on Friday, losing ground late after Federal Reserve Chair Janet Yellen's comments on the economy unnerved investors.

Financial shares finished up, giving the S&P 500 its biggest boost after stronger-than-expected bank results, but gave up most of their early gains. Healthcare shares led declines.

Yellen, in a speech at a conference of policymakers and academics, laid out the deepening concern at the Fed that U.S. economic potential is slipping - and may need aggressive steps to rebuild it.

"In looking at the market, I think, yes, (Yellen's speech) had a dovish tilt to it if you took it literally," said Quincy Krosby, market strategist at Prudential Financial in Newark, New Jersey.

Jeffrey Gundlach, chief executive of DoubleLine Capital, said Yellen's speech could suggest the U.S. central bank will stay accommodative for longer.

Yellen did not address interest rates or immediate policy concerns directly. Traders have currently priced in a 67-percent chance of a rate hike in December.

The S&P 500 financial index <.SPSY> was up 0.5 percent. JPMorgan Chase <JPM.N> and Citigroup <C.N> trounced third-quarter estimates. Wells Fargo & Co <WFC.N> barely beat expectations as a sales scandal engulfed the bank.

Shares of JPMorgan ended down 0.3 percent, however, while Citigroup <C.N> ended up 0.3 percent and Wells Fargo <WFC.N> was down 0.1 percent.

Wells Fargo has been under pressure following recent revelations that branch staff had opened as many as 2 million accounts without customers' knowledge.

The bank earnings somewhat helped shore up Wall Street's confidence on the outlook for third-quarter earnings after some disappointing results from industrial and healthcare companies. S&P 500 earnings for the quarter are still expected to have declined 0.4 percent from a year ago, Thomson Reuters data showed.

The Dow Jones industrial average <.DJI> closed up 39.44 points, or 0.22 percent, to 18,138.38, the S&P 500 <.SPX> gained 0.43 points, or 0.02 percent, to 2,132.98 and the Nasdaq Composite <.IXIC> added 0.83 points, or 0.02 percent, to 5,214.16.

For the week, the Dow was down 0.6 percent, the S&P 500 was down 1 percent and the Nasdaq fell 1.5 percent.

Shares of Twitter <TWTR.N> fell 5.1 percent to $16.88 after Salesforce.com's <CRM.N> chief executive ruled out bidding for Twitter. Salesforce.com shares jumped 5.2 percent to $74.27.

HP Inc <HPQ.N> fell 4.4 percent to $14.48 after the company said it would cut about 3,000 to 4,000 jobs over the next three years.

About 6.0 billion shares changed hands on U.S. exchanges, below the 6.6 billion daily average for the past 20 trading days, according to Thomson Reuters data.

Advancing issues outnumbered declining ones on the NYSE by a 1.03-to-1 ratio; on Nasdaq, a 1.07-to-1 ratio favored decliners.

The S&P 500 posted 3 new 52-week highs and 3 new lows; the Nasdaq Composite recorded 27 new highs and 80 new lows.

(Editing by Nick Zieminski)