A 1% weekly gain in the S&P 500 would typically be cause for celebration, so you can imagine how excited investors were last week when the broad-market index soared 5.9%.

A number of factors helped drive the index higher last week, including strong corporate earnings reports, signals from the Federal Reserve that it could be done raising interest rates, and an October unemployment report that showed job growth slowing, fitting the narrative of a soft landing.

The S&P 500 is made up of 500 U.S.-based large-cap stocks. The biggest companies have the greatest impact on the index, and none was bigger last week than Microsoft (MSFT 1.44%), which rose 7% on the week. That didn't make Microsoft the biggest gainer of any stock in the index, but because the tech giant has a market cap of nearly $3 trillion and the S&P 500 weights its components according to market cap, it had the greatest lift on the index.

Let's take a look at why Microsoft surged last week and continues to set record highs.

A series of stock charts overlaid on one another.

Image source: Getty Images.

Microsoft gets mightier

There was no single reason for Microsoft's gains last week. The tech giant benefited from many of the same macro trends that boosted the broad market. As primarily a software company, Microsoft is sensitive to many of the same economic trends as the rest of the tech sector, and it saw revenue slow to nearly flat growth earlier in the year as a wave of layoffs hit the sector, though its growth has since started to rebound. If the Fed is done raising interest rates, however, that should help raise business confidence and convince companies to hire more and invest more.

Microsoft stock jumped following the release of its fiscal first-quarter earnings report on Oct. 24 as it beat estimates on the top and bottom lines and posted strong growth in its Azure cloud infrastructure division, outperforming peers like Alphabet and Amazon in the key category.

Beyond the strong earnings results, there are a number of other reasons why Microsoft was moving higher. First, the general release of its Microsoft365 AI Copilot has been highly anticipated, with Piper Sandler calling it "an iPhone moment" for Microsoft. It forecast that Microsoft AI could scale to $100 billion or more in annual revenue over the long term.

Additionally, AI stocks seemed to benefit from the White House's executive order on AI last week, outlining rules and guidelines on the new technology, something AI leaders like Elon Musk and OpenAI's Sam Altman had been seeking.

The recent closure of its acquisition of Activision Blizzard also marks the end of an exhaustive regulatory process and will help Microsoft consolidate its leadership in the gaming industry.

Is Microsoft stock a buy?

After the recent rally in the stock and its reaching 52-week highs, Microsoft shares aren't cheap. The stock trades at a price-to-earnings ratio of 35, but Microsoft may be one of the best stocks to own right now.

Thanks in part to its partnership with OpenAI, the company is a clear leader in artificial intelligence, and it said in the recent earnings report that it now has more than 18,000 Azure OpenAI customers. It's diversified across a wide range of products, including enterprise software, Windows, Linkedin, news and search, gaming, and Azure cloud infrastructure in a way that none of its big tech rivals can match. Azure, its most important business, is gaining market, and the new AI copilot could be a game-changer.

Microsoft stock may trade at a premium, but it's earned that valuation. Expect the company to continue pushing the envelope in AI, finding new ways to improve its products, and bringing in even more revenue and profits. It still looks like a good bet to outperform over the long term.