Last week, a city well known for its annual Carnival festival had its biggest celebration yet. The big question, though, is whether investors should keep the party going. Will an amazing run end soon, giving latecomers to the festivities the ultimate hangover?

Olympic efforts
Friday, the International Olympic Committee announced that the 2016 Summer Olympic Games would take place in the Brazilian city of Rio de Janeiro. On a day on which most of the world's stock markets suffered substantial losses, Brazil's main stock index gained more than 1%, and followed that performance with a substantial gain yesterday as well.

Rio will host the first Olympic Games ever held in South America. Yet while some view the news as confirmation that Brazil has finally arrived among the international community, the momentum that led to the IOC's decision has been building for years.

Staying on track
A combination of hard work and good fortune has put Brazil in an incredibly strong position. For decades, Brazil suffered from the same economic problems that still plague other Latin American countries: lingering inflation, trade imbalances, and difficulties with corruption. As part of the solution, Brazil pegged its currency to the U.S. dollar in 1994, before letting it float again about 10 years ago. Although the country has been plagued by occasional crises, the Brazilian real has more than doubled in value versus the U.S. dollar since 2002.

Meanwhile, Brazil has developed its plentiful natural resources at a time when those commodities have seen their prices skyrocket. Petroleo Brasileiro (NYSE:PBR) has benefited not just from rising oil prices generally, but also from discoveries of huge oil fields off the Brazilian coast. Brazilian mining company Vale (NYSE:VALE) is the second-largest in the world, with huge production of iron ore and a host of other metals.

Brazil has certainly seen its economy affected by the global slowdown. Unlike other emerging markets such as China and India, Brazil will likely see its GDP contract slightly during 2009. But growth is expected to return next year, and consumer prices have stayed under control with inflation running in the 4.5% range.

Anything but cheap
Amid the rosy picture that Brazil presents, though, one sobering thought is clear: Brazilian stocks have already been on a tear. Even taking into account a loss of more than 55% last year, the iShares MSCI Brazilian ETF (EWZ) has gained an average of 32% per year since 2004. That means that even after losing more than half its value in 2008, Brazilian stocks have still quadrupled in just the past five years, and have nearly doubled this year alone in U.S. dollar terms. Moreover, those results don't even take the year 2003 into account, when the Brazilian ETF jumped more than 116%.

With such lofty gains, it's quite possible that Brazil is getting ahead of itself. Vale's 36% annual gains since 2004 dwarf the 27% that BHP Billiton (NYSE:BHP) has posted, and they leave Freeport-McMoRan Copper & Gold's (NYSE:FCX) 14% five-year average annualized return in the dust. Similarly, oil companies around the world have seen nice gains lately, but at 39% per year, Petrobras stands head and shoulders above ExxonMobil (NYSE:XOM) at 8.3%, Total SA (NYSE:TOT) with its 6.5% return, and even Chinese powerhouse PetroChina's (NYSE:PTR) 20.5% annualized gains.

Cautious optimism
Yet when things go badly for Brazil, big gains can reverse themselves in a hurry. For example, from March 2000 to October 2002, the Bovespa index lost 57% in local currency terms, while the Brazilian real lost half its value against the dollar, compounding the damage.

Nevertheless, Brazil's Olympic victory is definitely cause for the emerging-market nation to celebrate. If you're thinking about investing in Brazilian stocks, however, keep in mind that a whole bunch of investors already started the party without you. While there's still money to be made in Brazil, don't expect to see the amazing returns that ground-floor investors have enjoyed in recent years.