Warren Buffett bought only three stocks in the fourth quarter of 2023 for Berkshire Hathaway's portfolio. He sold seven stocks, including fully exiting four positions.

Most of Buffett's transactions made sense. However, not all of them did. One of the legendary investor's decisions was downright baffling.

Buffett's baffling decision

Let me address one thing right off the bat. Buffett's most baffling decision in Q4 had nothing to do with the trimming of Berkshire's huge stake in Apple. It's possible that Buffett didn't want Apple to become even more heavily weighted in Berkshire's portfolio than it already was. Another likely scenario is that one of Berkshire's other two investment managers (Todd Combs and Ted Weschler) sold some of their Apple shares in the part of the portfolio that they manage.

Instead, I think that the biggest head-scratcher with Buffett's Q4 transactions was the sale of all of Berkshire's shares of D.R. Horton (DHI 0.78%). Granted, D.R. Horton was only a small holding for Berkshire -- a little under 6 million shares worth close to $642 million at the end of the third quarter. However, the complete exit of the position is still puzzling to me.

Berkshire didn't sell any shares of the other two homebuilders in its portfolio -- Lennar and NVR. Exiting the D.R. Horton position without selling any shares of these other two stocks might make sense if D.R. Horton's valuation was much higher. However, that's not the case. D.R. Horton is the least expensive of the three stocks based on forward earnings multiples.

The long-term prospects for D.R. Horton and the market in which it competes haven't diminished since the stock was first added to Berkshire's portfolio in the second quarter of 2023. Even if they had, Lennar and NVR would have likely been negatively impacted as well.

The one change for D.R. Horton in Q4

There was one change made by D.R. Horton in Q4 that perhaps could explain why Buffett or his team sold the stock. The homebuilder appointed a new CEO on Oct. 1, 2023.

However, I'm not convinced this was the reason for the sale. D.R. Horton's new CEO is Paul Romanowski. He previously served as the company's executive vice president and co-chief operating officer. Romanowski has been a member of D.R. Horton's management team for more than 20 years. He knows the business well.

Importantly, former CEO David Auld isn't leaving D.R. Horton. He moved into the role of executive vice chair of the company's board of directors.

Why buying D.R. Horton stock could be a brilliant move

I think that buying D.R. Horton stock could be a brilliant move for investors even though Buffett (or his lieutenants) sold the stock. Why? For the same reasons that made Berkshire's exit from the position so perplexing.

The U.S. continues to face a serious housing shortage. Moody's Analytics recently estimated the country still needs as many as 2 million homes. The company acknowledged that its number is near the lower end of the range of estimates made by others.

There's only one practical solution to this shortage: Build more homes. D.R. Horton ranks as the largest homebuilder in the U.S., a position it's held for more than 20 years. The laws of supply and demand are working in the company's favor.

Sure, high interest rates have been a barrier for some Americans who would like to buy a house. However, the Federal Reserve has hinted that rate cuts are on the way this year. Mortgage rates are also impacted by inflation. Even with inflation remaining higher than hoped, though, National Association of Realtors chief economist Lawrence Yun told CBS News earlier in February that he expects mortgage rates will decrease to around 6% later this year. It should bode well for D.R. Horton if he's right.

As for valuation, D.R. Horton's shares trade at only 10.3 times forward earnings. That's a lower multiple, by the way, than any of the three stocks that Buffett bought in Q4. When growth prospects are factored in, D.R. Horton stock looks like a steal with a price/earnings-to-growth (PEG) ratio of 0.57.

All in all, D.R. Horton looks like a great stock to buy right now -- and definitely not one to sell.