August wasn't a kind month for many oil stocks, but it was downright brutal to my No. 1 oil stock right now, Apache Corporation (APA 0.42%). The month started out with the stock market hammering Apache shares over a disappointing earnings report and ended with Apache's Houston headquarters being closed due to Hurricane Harvey. Apache finished the month down more than 20%, far worse than ConocoPhillips (COP 1.00%), which closed down just 2.4%.

But in spite of all that, I still think Apache stock is a buy. In fact, it may be a better buy than ever. Here's why.

Oil wells in silhouette at night in a wet landscape.

The stock market has beaten up shares of oil and gas industry player Apache over the past year. Image source: Getty Images.

Behind the earnings

The story that Apache's Q2 earnings told seemed pretty straightforward: The company saw a drop in production compared to Q1. It lowered its production guidance through 2018. It reported negative adjusted earnings. Sounds like a company that's in trouble. 

But that's not the whole story. Apache had been predicting lower Q2 earnings for months, as a result of scheduled maintenance in its North Sea rigs while a subsea tieback was installed, and the time it would take to install necessary infrastructure in its Alpine High play in West Texas. In fact, Q2 production came in higher than originally expected.

As for the lowered production guidance through the end of 2018, that's just a reflection of one of the company's most brilliant moves this year: selling off all of its Canadian assets. Apache isn't alone in this: Conoco and others have made similar moves recently. Like many of its peers, Apache's Canadian assets had much lower margins than its overseas assets or even its Permian Basin assets. Selling them may result in lower production in the short term, but will improve the company's margins almost immediately. 

So, that's a very different picture than the numbers paint. In fact, it's a picture of a company that is making smart asset sales and delivering on its plans. But the company's big opportunities lie ahead of it.

Alpine High, stock low

Apache has finally begun to ramp up production at its massive new Alpine High play in the current third quarter, after having first announced it to the public a year ago. Thanks to industry misconceptions about the amount of hydrocarbon potential in the West Texas Delaware Basin where Alpine High is located, Apache was able to pick up the 300,000 net acres of land on the cheap, for an average cost of about $1,300 per acre.

Alpine High is indeed a rich find: Initial testing by the company showed at least 3 billion barrels of oil and 75 trillion cubic feet of natural gas beneath the land the company had purchased. Subsequent tests have shown that there may be significantly more. In April, an analyst at Stifel estimated that Alpine High alone was worth an estimated $18 per share in value for the company. For its part, Apache's management has placed the per-share value at a minimum of approximately $21.

Currently, Apache's stock is hovering around just $40 per share:

BNO Chart

BNO data by YCharts.

The chart above shows Apache's performance (red line) from Sept. 6, 2016, the day before it announced Alpine High to the public. At the time, it was worth about $55 per share, but as the market digested the Alpine High news, it cruised to above $60 per share. Then, in 2017, as the company built out the Alpine High infrastructure, the stock price fell farther and farther, despite a rally in oil prices and gains by competitors like Conoco.

Adding it all up

If Stifel and the company's management are correct, and Alpine High alone is worth somewhere in the neighborhood of $20 per share, that currently represents about half the company's stock price. It also means that the market is valuing the entire rest of the company -- including its very profitable Egypt and North Sea operations -- at about $20 per share. That means that either the market was way off a year ago (off by an unbelievable 175% or so) when it was valuing Apache at $55 per share without Alpine High or it's way off now. I'm inclined to believe the latter.

Of course, it's possible the company's initial test results and all of its subsequent tests are overpromising what Alpine High has to offer. But even if Alpine High is only worth something like $10 per share, Apache is still in pretty good shape. Remember, it didn't pay all that much for the land, and it has immensely profitable operations in the North Sea, where its subsea tieback was successfully installed and will generate a full quarter's worth of production in Q3. Its Egypt operations are likewise very profitable, and it has jettisoned some of its least profitable assets in Canada, which has improved its balance sheet.

The company is also one of the few oil companies not to have cut its dividend, which currently yields a best-in-class 2.4%, better than ConocoPhillips' 2.2%. And its Houston headquarters was luckily undamaged by Hurricane Harvey. 

To me, that adds up to a buy.

Investor takeaway

I thought Apache was cheap when its price dropped below $50 per share, which is why I bought in at $48. So, naturally, the stock kept dropping. I thought it was an absolute steal at $44 per share, so I bought more. And when it dropped below $40, it looked absolutely dirt cheap, and I still think it's an incredible buy at these prices.

However, the company is in a risky sector, and if oil prices fall from their current levels, Apache's stock will probably follow suit. And if the company is still seeing production drops in Q3 unrelated to Hurricane Harvey, that would be a sign that something has gone seriously wrong. But even in spite of those risks, for me, Apache is a clear buy.