* TSX ends down 0.21 percent at 10,370.07
* Up 3.8 percent on the week
* Records steepest monthly rise since December 1999
* RBC reports quarterly loss; shares drop 4 pct (Adds details, quotes)
By Jennifer Kwan
TORONTO, May 29 (Reuters) - Toronto's main stock index ended lower on Friday, weighed down by energy issues and a quarterly loss reported by Royal Bank of Canada (RY.TO).
But on the week the index gained 3.8 percent and for May it logged its steepest monthly climb in nearly 10 years, driven by investor optimism that the global economy is starting to climb out of recession.
In volatile action on Friday, the TSX shot up nearly 1 percent shortly after the open, but then dropped into negative territory to end lower on a late day selloff in energy shares, which fell 0.44 percent.
Also weighing on the market was Royal Bank's first quarterly loss since 1993. The country's biggest bank wrote down the value of its U.S. assets and set aside nearly C$1 billion to cover bad loans, sending its shares down 4 percent to C$43.70. [ID:nN25399893]
RBC's results topped analysts' expectations, as did those of Canada's other big banks. But analysts said its provisions for bad loans signaled deteriorating credit.
"That was enough to cool down the strong rally we've seen this week," said Francis Campeau, a broker at MF Global Canada, in Montreal.
As a whole, the index's financial group, which was in the red for most of the day, eked out a 0.05 percent gain. Toronto-Dominion Bank (TD.TO) was up 3.6 percent at C$55.60, while Bank of Nova Scotia (BNS.TO) rose 0.74 percent to C$38.18.
On the upside, materials rose 0.23 percent, boosted by firmer metals prices. Inmet Mining IMN.TO climbed 4.3 percent to C$43.48, while Agnico Eagle (AEM.TO) rose 2.5 percent to C$67.49.
The broader S&P/TSX composite index .GSPTSE closed down 22.30 points, or 0.21 percent, at 10,370.07, with three of its main sectors lower.
For May, the index was up 11.2 percent, its strongest monthly climb since December 1999, according to Reuters data.
It has risen 39 percent from its March lows.
Investors will be watching over the next several weeks for clues on whether the market's recent rally can be sustained, said Jennifer Radman, vice-president at Caldwell Investment Ltd.
"A single day of weakness -- I don't know that it necessarily means anything," she said.
"The big question out there is whether we've started a long-term bull market or whether we're being tricked by a bear market rally."
$1=$1.09 Canadian Reporting by Jennifer Kwan; editing by Rob Wilson