Bank of America has reported quarterly profit up 5% as gains from investments helped offset soaring credit losses and lower profits in its main business of retail banking.

Second-quarter profit for the second largest bank in the US increased to $5.76 billion compared to $5.48 billion a year earlier.

Revenue rose 7% percent to $19.56 billion. Analysts on average were expecting $18.49 billion.

Profit increased 'despite challenging headwinds' CEO Kenneth Lewis said in a statement.

'Investments in a number of businesses (and equity investment gains) are generating results that more than offset spread compression impacting virtually all of our businesses and trend toward more normalized credit costs.'

Bank of America set aside $1.81 billion overall for credit losses, up 80% from a year earlier.