Share prices of Nvidia (NVDA -1.99%) are up 140% year to date, and that's on top of a staggering 750% gain over the last three years. The graphics specialist has transformed from being a GPU provider for PC gamers to more of a systems provider for high-performance computing and artificial intelligence services.

Buying hot tech stocks like Nvidia can be tricky. On one hand, Nvidia has clear opportunities to grow revenue and expand margins over the long term. But you don't want to buy at the top only to see the stock collapse if the company's performance doesn't live up to the high expectations embedded in the stock's valuation.

Here are the most important factors to consider before deciding to buy Nvidia at these highs.

A business person studying something on a computer.

Image source: Getty Images.

Consider why the stock is up

Nvidia's price-to-earnings (P/E) ratio was less than 25 in January 2019. Its P/E is now 96, which is part of the reason the stock has risen so much over the last few years. It's a combination of strong business growth and investors paying a higher premium to buy shares.

Nvidia is a leading provider of GPUs and systems that power the world's leading cloud providers, self-driving cars, and gaming PCs. Most of the company's growth has come from its two largest segments -- gaming and data center -- over the last three years. Revenue from these two segments in the most recent quarter was roughly triple the level three years ago. 

Segment Fiscal Q3 2022 Fiscal Q3 2019
Gaming $3.221 billion $0.954 billion
Data center $2.936 billion $0.679 billion
Professional visualization $0.577 billion $0.293 billion
Auto $0.135 billion $0.163 billion
OEM and other $0.234 billion $0.116 billion
Total $7.103 billion $2.205 billion

Data source: Nvidia.

Another factor driving the stock higher is expanding margins. Nvidia's gross margin has steadily improved over the last 10 years, driven by a sales shift to more powerful graphics processors that command higher prices across gaming and data center segments. 

Margins can climb higher. Nvidia's push into software, such as the license fees from Nvidia AI Enterprise and Omniverse, should keep gross margins moving up over the next several years.  

NVDA Gross Profit Margin Chart

NVDA Gross Profit Margin data by YCharts

Nvidia is at the very beginning of its push into AI software, which could push its gross margin above 70% by 2030. The consensus analyst estimate has Nvidia's gross margin reaching near 68% in the next two years.

We can make a case that Nvidia's profits should grow faster than revenue as margins expand. So, what about revenue growth?

Industry growth projections

Spending on AI services and data centers should continue to grow. For example, Facebook parent Meta Platforms plans to increase capital investment in data centers and infrastructure to around $30 billion, up from $19 billion, in 2022. Nvidia has previously estimated its long-term addressable market in data centers at $100 billion. 

Software is another huge opportunity. Gartner estimates AI software spending to reach $62 billion next year, an increase of 21% over 2021. Companies from transportation, education, finance, healthcare, and other industries are already using Nvidia AI Enterprise, which essentially makes AI more accessible for many organizations worldwide.

Elsewhere, Nvidia said 700 companies are evaluating the use of Nvidia Omniverse, which could be a huge growth opportunity as the metaverse takes off.

Beware of these pitfalls

Nvidia is becoming the most important technology provider in the world (if it isn't already). Artificial intelligence is becoming critically important for every industry. It automates tasks for working professionals, and it powers recommendation systems that consumers use every day. 

However, growth could slow. Investors should remember in 2018 when Nvidia's data center segment posted a sequential revenue decline of 15% in the fourth quarter that year. At the time, management blamed a slowdown in spending across all customers over near-term economic uncertainty. The stock price fell 52% during the fourth quarter of calendar 2018.

Demand for GPUs has fluctuated in the past and can do so again. This is why I wouldn't buy a large position in Nvidia right now. The stock would likely get crushed if spending on Nvidia's GPUs suddenly decelerated as it did before.

Looking out several years, Nvidia's business can grow much further, but I would either start a small position in the stock or wait for a dip.