The S&P 500 index has had a fabulous run in 2023. After falling 19.4% in 2022, the index is now up by nearly 15% in the first half of 2023. The index has also gained more 20% from its recent low in late 2022, which some investors take a sign that a new bull market is in the making.

Whether this market rally is sustainable is open to debate, especially since the Federal Reserve has highlighted the possibility of more interest rate hikes in late 2023. However, historically, sooner or later every bear market has been followed by a bull rally. Bull markets have also been more frequent and longer than bear markets. Bull markets have accounted for 78% of the trading days in the past 91 years and last an average of 2.7 years. With the probability of a bull market rally being quite high, the S&P 500 also has a solid chance of going even higher.

While past events are not a great predictor of the future, investors should start building positions in stocks that are poised to thrive in a bull market but are also resilient to the pressures of the bear market.

Here are two growth stocks that fit the bill.

1. Nvidia

Chipmaker Nvidia (NVDA -3.89%) has been flying high in 2023, with shares already up by nearly 185% so far. The company's revenue and earnings in its fiscal 2024 first quarter (ended April 30) crushed Wall Street estimates.

Once known primarily for its gaming chips, Nvidia is now recognized for its full-scale offerings --software, hardware, system, and frameworks -- for artificial intelligence (AI) workloads. The company's AI ecosystem includes AI chips, the Compute Unified Device Architecture (CUDA) software platform used to optimally program the chips, DGX Cloud services used to train generative AI applications, and the Omniverse platform to build metaverse applications. Together, these offerings have created a solid moat. With more than 4 million developers using the CUDA platform for developing graphic processing unit (GPU) applications, Nvidia also enjoys a significant network effect.

Thanks to its moat, Nvidia is well positioned to benefit dramatically from the simultaneous adoption of accelerated computing and generative AI in the data center industry. According to New Street Research, Nvidia already accounts for 95% of GPUs that are used in training machine-learning models (which is a part of AI). Soon, the company will also see solid demand from the increasing demand for accelerated computing in inference AI (real-time execution) workloads.

Recently, Nvidia entered into a partnership with cloud-based data platform Snowflake, giving it access to the latter's clients. This deal will enable Snowflake's customers to build customized large language models (LLMs), leveraging the power of huge data sets using Nvidia's advanced chips. ChatGPT, for example, is powered by an LLM.

Despite the many pros, Nvidia's very expensive valuation remains a concern. It currently has a price-to-earnings (P/E) ratio of 210, almost 10 times higher than the median semiconductor industry valuation of 24.3 times. However, considering the company's prowess and pricing power in AI hardware and software and the scale of the AI opportunity, the company can consistently surpass analysts' estimates in the coming quarters -- which will propel Nvidia's stock even higher.

2. Amazon

E-commerce and cloud computing giant Amazon's (AMZN 2.29%) shares have gained more than 50% so far this year. Although worries about reduced consumer and corporate spending amid rising inflation and potential recession are far from over, improving prospects for Amazon's cloud computing and advertising business is driving up share prices.

According to Fortune Business Insights, the global cloud computing market is projected to grow from $677.9 billion in 2023 to $2.4 trillion in 2030. Being a market leader accounting for a 32% share of the global cloud infrastructure services market at the end of 2022, Amazon Web Services (AWS) is set to benefit from this megatrend.

Further, increasing demand for computational power for generative AI applications is also a major tailwind for the company. Amazon has launched the Amazon Bedrock service, which provides developers with tools, infrastructure, and computing power to build, train, and run customized generative AI applications on AWS. Since cloud providers are expected to rake in 10% to 20% of all global generative AI revenue (estimated to be $422.3 billion in 2028), AWS stands to benefit dramatically from this opportunity. AWS is also investing $100 million in a generative AI center to connect AI and machine-learning experts with clients.

Amazon is also making its presence felt in the digital advertising market, thanks to its focus on sponsored products and brand offerings on its e-commerce platform. The company leverages its huge trove of first-party data to effectively target customers with high purchase intent at the point of purchase. Hence, despite difficult macroeconomic conditions, Amazon's advertising revenue was up by 23% year over year in the first quarter of 2023.

Finally, Amazon is trading at a price-to-sales ratio of 2.5 times, which is close to historically low levels in the past five years. The company is also trading nearly 30% below its all-time high in July 2021, which means there is still upside potential in the stock. Given the company's increasing strength in two high-growth markets and its robust AI capabilities, long-term investors can benefit by starting a small position in this stock.