It was as recently as August that analysts were making doomsday predictions about Brazil’s economy, pointing to recent consecutive quarters of contractions, soaring unemployment and a plunging currency. So it was a surprise, at least to some, when it turned out that in the first 20 days of October foreign investors had spent $4.2 billion in the country’s stock market, as Bloomberg reported Friday, even as some have predicted that lower prices offered in Brazil’s lagging economy were precisely what could lure investors.

“Anyone buying a selective portfolio at current levels will make money,” Guilherme Ache, a partner at Squadra Investimentos, an investment firm based in Rio de Janeiro, told Bloomberg, even as he warned that investors would need to be savvy in selections. “There’s no bell that rings when you reach a turning point in a bear market,” he added.

Just five years ago, Brazil had been one of the darlings of the developing world, an emerging economy extolled for the rapid growth of its middle class and robust employment rates. But in 2013, hints began to emerge that Petrobras, Brazil’s state oil company, was struggling, as it reported mounting losses and debt. In 2014, reports that corrupt practices might have been taking place began to emerge. By January, the country and Petrobras were embroiled in a full-fledged scandal – Petrobras admitted to losing $2 billion in bribes – that implicated Brazilian President Dilma Rousseff.

By August, Brazil’s economy had posted two successive quarters of contraction. A recession was officially under way, not only fueled by the political crisis but also suffering from fallout from China’s recent economic downturn and the dropping prices of commodities that are vital to Brazil’s economy, including oil, sugar and coffee. The economy appeared headed into its longest recession in some 80 years.

But as some analysts have pointed out, if Brazil’s economy could not sink much lower, investors might have incentive to buy in now, while prices are low.

“Get ready for a stock market rally in Brazil,” predicted the headline for an article published on MarketWatch in mid-September. “Bear market rallies can be a great way to make money,” the author of the article, Michael Brush, wrote, suggesting that investors “identify stocks or asset classes where sentiment has sunk to such an extreme low, things can’t get much worse.”

Many still are wary of entering Brazil’s markets, especially given the political instability – Rousseff faces more than two dozen petitions calling for her impeachment, for instance. But for those who see potential payoffs, now is a golden opportunity. “This is the best time to buy in years,” James Gulbrandsen, a partner at NCH Capital in Rio de Janeiro, told Bloomberg.