South Africa's rand weakened more than 1.7 percent to near six-month lows against the greenback on Thursday, pushing through its long-term moving average as offshore hedge funds drained dollars off the market.

Stocks rose to their highest level in 31 months, notching their third straight day of gains as the rand's decline lifted export-oriented shares.

Johannesburg's Top-40 blue-chip index added 1.15 percent to 29,609.47 points, a level last seen on June 17, 2008. The broader All-share index gained 0.95 percent to 32,794.84.

At 1616 GMT the rand traded at 7.29 against the U.S. currency after falling to 7.3001 earlier -- its weakest level since September 2 last year -- compared with Wednesday's close of 7.1620.

Traders said the move also reflected broader dollar gains after positive U.S. economic data.

We have seen a lot of dollar demand from hedge funds offshore and also because of the fact that the dollar has strengthened basically against everything else, there has been a little bit of buying in dollar/rand, a Johannesburg trader said.

The rand breached the key 7.21 level and broke through its 200-day moving average, pointing to a weakening trend for the currency in the longer term.

On the bourse, coal miner Optimum Coal was up 2.73 percent at 33.90 rand, buoyed by a surge in half-year profits, while platinum producer Lonmin gained 2.61 percent to 209.50 rand.

Petrochemicals group Sasol added 2.35 percent to 360.95.

We have a nice combination of higher commodity prices (and) a weaker rand ... which was more than enough to offset weak sentiment overseas, a Johannesburg-based trader said.

In earnings news, Investec was up 0.68 percent to 56.45 rand after the Anglo-South African investment bank said profit rose slightly in the first nine months of its fiscal year.

Government bonds weakened alongside the rand on Thursday, and yields rallied in turn.

The yield on the benchmark 2015 bond was up 9.5 basis points to 7.92 percent while that for the 2026 note jumped 11 basis points to 8.765 percent.