After a year of spectacular gains, the stock market seems to be taking a breather to kick off the new year. Investors are justifiably cautious after the Nasdaq Composite (^IXIC 2.02%) notched gains of 43% last year. Given those stellar gains, investors are left to wonder if the current rally still has legs -- and history can help provide some guidance.

Going back to 1972 -- the first full year the tech-centric index traded -- in every year following a bear market rebound, the Nasdaq has rallied another 19%, on average. The results varied by year, of course, ranging from a 7% increase in 1986 to a 38% surge in 2013. That said, and given the ongoing economic recovery, chances are good that the current market rally will continue in 2024.

There's evidence that suggests it was the emergence of generative AI that fueled the market surge last year. These advanced algorithms were deployed to handle menial tasks, freeing the user for higher-level chores. While it's still early innings for AI, there are a couple of companies that stand out from the pack and are well-positioned to profit from the AI revolution.

The letters AI swirling in a tornado-like cloud above stock charts.

Image source: Getty Images.

AI stock No. 1: Microsoft

Microsoft (MSFT 1.82%) is arguably a household name, best known for its pervasive Windows PC operating system and Office suite of productivity tools.

Seeing the vast potential for generative AI, Microsoft dove in headfirst, taking a $13 billion stake in ChatGPT creator OpenAI. More importantly, the company quickly developed Copilot, an AI-powered assistant designed to make its software users more productive by streamlining repetitive, time-consuming tasks.

Even before it was released for general availability, the company experienced a surge in demand during its "pilot" project, with 40% of the Fortune 100 using Microsoft 365 Copilot during the company's early access program. Microsoft reported strong interest in the digital assistant, which was made generally available in November.

The increased demand is already having a halo effect on Azure Cloud, which swept past its rivals as the fastest-growing of the major cloud infrastructure providers in the calendar third quarter. Lest there was any doubt why, Microsoft said three percentage points of Azure's growth was for "AI services."

For its fiscal 2024 first quarter (ended Sept. 30), Microsoft's revenue grew 13% year over year, while EPS climbed 27%, even before the impact of Copilot. Add to that improving macroeconomic conditions, the ongoing adoption of cloud computing, and tailwinds from AI, and 2024 should be a very good year for Microsoft.

For all that opportunity, the stock is selling for 36 times forward earnings. While that's a slight premium to the overall market, given its track record, Microsoft is worth every penny.

AI stock No. 2: Nvidia

Nvidia (NVDA 6.18%) didn't start out to be the AI processor to the stars. The company made its bones by pioneering the graphics processing units (GPUs) that display lifelike images in video games. However, CEO Jensen Huang realized early on that its graphics cards could be adapted to a variety of uses that required a degree of computational horsepower, including data centers, cloud computing, and AI.

That strategy has been so successful that Nvidia's data center segment -- which includes processors used for AI -- has surpassed the revenue generated by gaming chips. During the company's fiscal 2024 third quarter (ended Oct. 29), data center revenue represented 80% of Nvidia's sales, up from 41% two years earlier. During that same period, revenue for the segment surged 350%, helping illustrate the soaring demand for AI processors.

To be fair, Nvidia is already the gold standard for processors used in data centers, with a 95% market share, according to CFRA analyst Angelo Zino. Furthermore, Nvidia controls 95% of the machine learning GPU market, according to New Street Research. With demand for AI processing kicking into high gear, data centers are scrambling to upgrade their systems to meet the rigorous demands of AI -- which spells more good news for Nvidia.

The available evidence seems to support that idea. In the third quarter, Nvidia delivered record revenue that soared 206% year over year to $18.1 billion, resulting in diluted earnings per share that surged 1,274% to $3.71. To be fair, easy comps related to the downturn skew the results, but the trajectory is clear.

Despite the company's impressive performance and the massive opportunity ahead, Nvidia still trades for a reasonable price/earnings-to-growth (PEG) ratio of less than 1 -- the standard for an undervalued stock.