There's a crisis on the U.S.-Mexico border, and Wall Street is betting that it will result in a boom for private prisons.

Geo Group (GEO)and Corrections Corporation of America (CXW) are two of America's largest for-profit prison operators. They have thousands of open beds, and they have deep relationships with the federal agencies charged with doling out contracts to house undocumented immigrants, including children.

"It's highly likely that the federal government will have to turn to the private sector for help with this crisis. Both companies are extremely well positioned," said Brian Ruttenbur, an analyst at CRT Capital Group who covers the stocks of Geo Group and Corrections Corporation of America (CCA).

Investors are clearly seeing dollar signs. Shares of both CCA and Geo Group have spiked since the border crisis landed on front pages this summer. CCA has climbed 8.5% since July 30, and Geo Group is up over 7%. That's a lot better than the S&P 500's 1.5% advance over that time span.

Related: Crisis on the border

The Obama administration has already shifted over $405 million in funds to address the crisis and is urging Congress to pass a $3.7 billion emergency supplemental bill.

"Investors see this as an opportunity. This is a potentially untapped market that will have very strong demand," said Alex Friedmann, an activist investor who owns shares of both CCA and Geo Group.

Positioned to profit: Some of the prisons CCA and Geo Group own are not filled and others are completely idle. That means they are in the unique position to offer their services to U.S. Immigration and Customs Enforcement (known as ICE).

Ruttenbur said CCA and Geo Group have both been talking to the federal government about how they can help.

"We are always in conversations with our government partners including ICE, but we don't have anything new to report," a CCA spokesman told CNNMoney. Geo Group did not respond to a request for comment.

The best outcome for these companies would be landing a contract with the government to help house some of the undocumented immigrants at existing facilities that are currently idle.

That's exactly what happened last month when the U.S. border control inked a contract with Geo Group to give its adult detention center in Karnes County, Texas a makeover. Now the facility is able to house hundreds of immigrant women and children.

Related: How far can President Obama go on immigration without Congress?

Bullish long-term trends: Of course, there's no guarantee CCA and Geo Group will end up benefiting from the border crisis. It's notoriously difficult to call the timing on any government contract.

"I've been doing this 20 years and I've never gotten that right," said Ruttenbur.

Still, analysts remain very bullish on the for-profit prison industry. Both companies reported better-than-expected earnings and raised their outlook for the rest of the year -- a double high-five that investors love to see.

Wall Street also applauded when CCA and Geo Group, which went public during the 1980s and 1990s, recently converted to real estate investment trusts, or REITs. That status, which is also used by hospitals and office building operators, gives them enormous tax advantages.

Related: Hot stocks: 10 companies trading at all-time highs

For-profit prisons are not without controversy. Some of these facilities have been criticized for poor conditions, including the CCA-run T. Don Hutto Residential Center in Texas. A 2007 lawsuit that alleged immigrant families at the center were kept under virtual 24-hour lockdown and denied adequate services. The U.S. government stopped housing families there in 2009.

But investors are attracted to prison stocks because they give generate lots of cash flow, have strong dividend yields and high occupancy rates compared to other real estate options.

"The long-term trends are very much in place right now because the federal, state and local governments aren't willing to put up the capital to build new facilities. The only group building new facilities is the private sector," said Ruttenbur.