Shares of Apple (AAPL -1.76%) and International Business Machines (IBM 1.56%) have performed well over the past year, both up about 40% following periods of underperformance. Apple, after reporting three consecutive quarters of sales declines, finally broke out of its funk last month when it reported solid, albeit muddled, holiday quarter results. IBM, after years of earnings declines, expects to return to growth on a per-share basis this year.

Both stocks are cheap relative to earnings, but I think IBM is the better buy. Here's why.

Apple is cheap, but growth will be tough

Shares of Apple trade around their all-time high following the company's fiscal first-quarter report, but the stock is still cheap relative to earnings. Apple produced $45.2 billion of net income over the past 12 months, or $8.39 per share. With a stock price around $131, that puts Apple's PE ratio at roughly 15.6.

Multiple iPhone 7 Plus phones in various colors.

Image source: Apple.

But this calculation ignores the immense amount of cash on Apple's balance sheet. At the end of the first quarter, Apple had $246 billion of cash and investments and $77 billion of debt, leaving a net cash position of $169 billion. Valued fully and backed out, Apple's cash-adjusted PE ratio falls to just 11.5.

Apple stock isn't nearly as cheap as it was a year ago, but the market is still pricing in minimal future growth even at all-time highs. There are good reasons for this. Apple remains highly dependent on the iPhone, which accounted for nearly 70% of revenue during the first quarter. With the smartphone market no longer growing quickly, consumers taking longer to upgrade, and mid-range devices getting better and cheaper, consistent iPhone growth going forward is going to be tough to achieve.

And even though Apple managed to grow iPhone sales and EPS during the first quarter, net income declined due to a lower gross margin and higher operating expenses. Share buybacks were the sole source of per-share earnings growth.

Apple is going to need to come up with something big in order to grow earnings meaningfully in the coming years, but it's unclear whether Apple will be able to come up with the next big thing. Services revenue has been growing quickly for Apple, but the jury is still out on whether this will be enough to drive earnings higher.

IBM's transformation makes progress

IBM stock is also cheap, despite the rally over the past year. The company produced $13.59 in adjusted EPS during 2016, putting the P/E ratio at 13. IBM's earnings have been in decline for a few years, and its revenue has been slumping since 2012. But its multiyear transformation is making progress, and the company expects to produce at least $13.80 in adjusted EPS this year.

IBM's Global Center for Watson IoT in Munich, Germany.

Image source: IBM.

IBM has been divesting and shifting resources away from shrinking legacy businesses, pouring money into growth initiatives like cloud computing. This shift, while painful, is now starting to bear fruit. IBM's strategic imperatives -- what the company calls its various growth businesses -- now account for 41% of total revenue after growing by 13% in 2016.

The cloud-computing business is booming. Total cloud revenue reached $13.7 billion in 2016, up 35%. Cloud delivered as a service, which includes only infrastructure as a service, platform as a service, and software as a service, is at an annual revenue run rate of $8.6 billion, up 61% year over year. IBM's ongoing shift to subscription software has hurt overall software sales in the past couple of years, but the software business has now posted growth for three straight quarters.

IBM's earnings have room to grow simply because the bottom line has been beaten down so much over the past few years. As IBM continues to remake itself as a cloud and cognitive computing company, a return to consistent earnings growth is a real possibility.

IBM is the better bet

While I don't necessarily think that Apple is a bad investment, I find it difficult to believe that the company will be able to grow earnings from here. The iPhone is going to have to hold up in a world where good phones are getting cheaper, and the company is going to have to come up with something new and innovative that can move the needle.

IBM, on the other hand, has a much broader business, with a vast customer base dependent on its products and services. Earnings have room to grow substantially as the strategic imperatives, which are more software-heavy than the company as a whole, continue to expand. Given similar valuations, I'll take IBM any day.