Image copyright AP Image caption Interest rates are high across the whole of Brazil

Making money through lending should not be a problem for banks operating in Brazil.

The country's interest rates are currently at an eye-watering 13.75% and expected to rise even higher this year.

So it comes as something of a surprise that HSBC has announced this week it will practically end its operation in Latin America's largest economy - retaining only a few large corporate clients.

Banks in Brazil are one of the few sectors that have been immune to the country's slowdown.

As Brazil heads for recession now, financial institutions are still posting record profits.

Last year, the country's economy grew 0.1% - yet Brazil's top five banks managed to increase their profits by 20%.

The sixth largest - HSBC - lost $247m (£160m).

How did HSBC start off in Brazil?

Image copyright EPA Image caption A branch of HSBC in Rio de Janeiro

Brazil might seem like a paradise for bankers now, but that was not the case in 1997, when HSBC first arrived.

The government had just revamped most of the nation's outdated financial structure as part of Plano Real - the economic plan that ended decades of hyperinflation.

Brazil's banks were not used to making money in an economy with stable prices. Under new rules, seven banks nearly went bankrupt.

Under much criticism, the government offered a $10bn (£6.5bn) lifeline to those in trouble, to avoid a general collapse of the system - similar to what was later done by Western governments during the 2008 financial crisis.

Among the rescued banks was Bamerindus, a very popular retail institution with more than 1,000 agencies across Brazil. They were bought by HSBC.

How did banking succeed in Brazil?

Over the following years, bankers had a great run.

As Brazil became an economic emerging star, millions were lifted from poverty and finally had enough money to be included in the financial system, through bank accounts.

Competition and efficiency flourished, with foreign groups such as Spain's Santander and Netherland's ABN Amro investing heavily in Latin America.

But one single factor remained vital for bankers - Brazil's growth model depended on high interest rates.

For decades, under different governments, inflation was kept in check with a monetary policy that favoured money-lending institutions.

High rates hurt business people who wanted to borrow money to open up shops or factories that could potentially create more jobs.

But it was crucial to keep general prices low with higher borrowing costs.

What about the change in government?

Image copyright AFP Image caption Dilma Rousseff took office on 1 January 2011

That remained the case until 2011, when President Dilma Rousseff came to power.

Her government believed Brazil had reached a point where it could abandon its high-interest-rate growth model and start a policy that would favour investments, with cheaper credit in the markets.

Interest rates in Brazil:

June 2015: 13.75%

2014: 11.75%

2013: 10.00%

2012: 7.25%

2011: 11.00%

2010: 10.75%

2009: 8.75%

2008: 13.75%

2007: 11.25%

2006: 13.25%

2005: 18.00%

2004: 17.75%

The Central Bank lowered rates from double digits to its lowest point in a decade, 7.25%.

President Rousseff was also intent on fighting bankers' profits, which were considered obscene by many in her left-leaning coalition.

Under her orders, big public banks - such as Banco do Brasil and Caixa Economica Federal - offered low interest rates to customers, making private banks follow suit and lower their "spreads" (bankers' returns).

But President Rousseff's war on private banks and spreads came to an end in 2013, when it became clear that inflation was creeping up again.

Despite all efforts, Brazil's economy still depended on high interest rates.

Brazil has since embarked on a new cycle of increasing rates. Just last month, the Central Bank raised its rate yet again.

What next for banking in Brazil?

Media playback is unsupported on your device Media caption The restructuring plan is HSBC's attempt to turn things around after one of the toughest years in its 150-year history

High interest rates mean Brazil remains a very attractive country for banks - they make more money on their lending. But competition has also increased massively - and the market is not big enough for every player.

HSBC had a few years of good profits, but it never gained the scale necessary to compete with other better established rivals. It has a network of 853 agencies and 21,000 workers, which is now up for sale.

Bradesco has more than 4,600 agencies and 83,000 employees.

Also, it did not help that HSBC became embroiled in the global Swiss leaks scandal, an investigation into alleged money-laundering.

Interest rates around the world:

Brazil: 13.75%

India: 7.25%

China: 5.1%

UK: 0.5%

US: 0.25%

Euro Zone: 0.05%

Japan: 0%

Source: Trading Economics

Brazilian authorities launched a special congress inquiry into the bank, as more than 8,000 people with connections to the Brazilian economy have Swiss HSBC accounts.

Three banks have already announced this week their interest in buying HSBC's assets in Brazil.

One of them - Itau Unibanco - has posted a profit of $1.8bn (£1.2bn) for the first quarter of 2015, when Brazil's economy contracted 0.2%. It is the highest in Brazilian history for a first quarter.

Brazil's interest rates show no sign of abating, as inflation is expected to balloon to 8% - well above the government's target.

Making money through lending, it seems, will remain a very resilient businesses in Brazil for quite some time.