What happened

Shares of U.S. oil companies Occidental Petroleum (OXY 0.98%), Devon Energy (DVN 0.63%), and Phillips 66 (PSX 1.05%) each rallied above the level of the market in October, increasing 18.1%, 28.6%, and 29.2%, respectively, according to data from S&P Global Market Intelligence.

It was a good month for the markets, but oil and gas stocks had an even better month after the Oct. 5 OPEC+ meeting, during which the cartel decided to slash production by 2 million barrels per day. In addition, company-specific factors also helped along the way.

So what

On Oct. 5, OPEC+, the powerful cartel of oil-producing states comprising countries in the Middle East, Africa, and South America as well as Russia, decided on a 2 million-barrel-per-day output cut, to support oil prices, which had fallen from more than $120 per barrel to below $80 by the end of September.

The move drew criticism from the Biden administration, which sees rising gas prices as political liability, and since most oil and gas companies are still quite profitable at $80 oil. Nevertheless, OPEC+ leader Saudi Arabia declared the move necessary, given rapidly rising interest rates and the potential of a global economic slowdown.

In any case, since oil is a global market, lower production from overseas producers would benefit U.S. producers like Occidental and Devon. Shale oil producers such as these two aren't part of a cartel, but U.S. producers are acting like a cartel these days, with virtually all shale oil managements putting out low production increase targets, then using the bigger cash flows to pay out dividends to shareholders. This is in contrast to the unconstrained drilling growth that drove prices down when the shale revolution first took hold roughly 10 years ago.

With OPEC+ now holding back barrels and U.S. producers all more measured in their growth, it's no wonder oil prices are somewhat resilient at higher levels than last year, and it's also no wonder the Biden administration is critical of U.S. oil companies and OPEC+ alike. Given still-hot jobs figures and a low unemployment rate, oil demand appears to be weathering interest rate increases just fine for now.

The OPEC+ production cut was probably the overwhelming factor moving these oil and gas producers last month, but there were also some company-specific developments. In addition to its oil and gas business, Occidental also has a low-carbon-ventures arm. In that part of the business, Occidental began construction on what will be the world's largest carbon sequestration, or "carbon capture," plant, in conjunction with Carbon Engineering Ltd. in the Permain Basin. CEO Vicki Hollub has big ambitions to have Occidental's carbon capture revenues one day equal its oil and gas revenues, which could help the oil and gas giant transition to a low-carbon economy.

Meanwhile, even though oil prices rose and demand for refined products stayed strong, refinery and midstream company Phillips 66 announced it would still look to cut costs at some of its refineries as part of a new restructuring program. A spokesman told Reuters later in the month, "Phillips 66 is undergoing a companywide effort to optimize its cost structure and reimagine its operating model to enable sustainable savings."

Strong demand combined with cost cuts were music to investors' ears, which perhaps explains why Phillips rose even more than the other oil companies in October.

Now what

Since the end of the month, both Devon and Phillips 66 have reported earnings. Phillips posted a nice beat on both revenue and earnings per share, and its stock rose again the following day, building on last month's gains.

Meanwhile, Devon Energy also beat on revenue and earnings for the third quarter but fell in response, as management declared a lower variable dividend than in the prior quarter. Of course, that shouldn't be a surprise, as oil prices were lower in the third quarter than in the second. In addition, Devon announced it was ramping up capital expenditures higher than anticipated in light of some recent acquisitions.

Meanwhile Occidental reports earnings on Tuesday, Nov. 8.

Overall, oil and gas companies are still gushing cash and paying out lots of dividends to shareholders. They are good portfolio diversifiers as well, in case oil prices surge in response to decreased OPEC+ production and the cessation of the U.S. Strategic Petroleum Reserve releases, which are supposed to end the six-month program this month.