* 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, quote)
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 up 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 the day down on a late day selloff in energy shares, which fell 0.44 percent.
Weighing on the market was Royal Bank of Canada (RY.TO), which notched its first quarterly loss since 1993 as it wrote down the value of its U.S. assets and set aside nearly C$1 billion to cover bad loans, sending shares 4 percent lower 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, 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.
The 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 steepest monthly climb since December 1999, according to Reuters data.
It has risen 39 percent from its March lows.
$1=$1.09 Canadian Reporting by Jennifer Kwan; editing by Peter Galloway