For a time, Pakistani stocks were undervalued by as much as 50 percent to account for risk, compared with a regional discount of about 20 percent, said Taha Javed, a financial analyst in Karachi. Now, as foreign investors pile in, he said, “we are catching up.”

Still, there is much to overlook. With painful power shortages, a sliding national currency and dwindling foreign reserves, Pakistan’s economy has been on life support in recent years. In August, the International Monetary Fund approved a $6.6 billion emergency loan, on top of $5 billion that Pakistan already owes the fund.

Business safety is a problem. Paramilitary security forces combed Karachi last week as part of a fresh effort to combat criminal gangs that have terrorized the city. Kidnapping for ransom is common. In a “livability” survey of 140 world cities, published by the Economist Intelligence Unit in August, Karachi shared the fourth-to-last rank with the Algerian capital, Algiers. And that is only part of Pakistan’s broader security problem, with militant groups and frequent violence against religious and ethnic minorities.

And for all its impressive growth, the stock market can be worryingly unstable, as a sudden dive of about 5 percent last week demonstrated. That slump has now stabilized — it was more of a correction than a crash, it seems — but the market has a history of volatility.

The Karachi exchange closed for four months in late 2008 after an abrupt drop in prices; more recently, it has faced allegations by the news media of insider trading and cronyism. A former chairman of the Securities and Exchange Commission of Pakistan, which regulates the market, is being prosecuted for corruption and tax evasion.

The juxtaposition of a booming stock market with bombs and economic austerity suggests sides to Pakistan, both positive and negative, that are little appreciated outside the country. It shows resilience and business acumen, certainly, but also worrisome fragmentation in a society where rich and poor live ever further apart.

In Karachi, where most big companies and banks have their headquarters, about 2,500 people died violently last year. But the bloodshed is concentrated in the city’s working-class areas, allowing the wealthy to continue with life as normal — with some adjustments like layers of security barriers and heavily armed private security forces.