The S&P 500 is the most popular barometer for the U.S. stock market. The index entered bull market territory on Oct. 12, 2022, and it has surged 53% during the 20 months since then. But history says the stock market is headed higher.

The S&P 500 returned an average of 184% during past bull markets, and it realized those returns over roughly 64 months. If the current bull market aligns with the historical average, the index will advance 131% over the next 44 months. But even if those gains fail to materialize, investors have good reason to believe the stock market will soar in the long run.

The S&P 500 returned 2,010% over the last 30 years, compounding at 10.7% annually. That period encompasses a broad enough range of economic conditions that similar returns are likely in the coming decades. Armed with that information, patient investors should be putting money into the stock market today.

Here's why Shopify (SHOP 0.81%) and Paycom Software (PAYC 1.35%) are worth buying.

Shopify: A leader in retail e-commerce software that is gaining momentum in wholesale

Shopify offers a turnkey solution for commerce. Its platform supports merchants across physical and digital sales channels, including online marketplaces, social media, and direct-to-consumer websites. The company also offers adjacent solutions for marketing, payments, and logistics. Additionally, its enterprise-grade platform, Shopify Plus, features more functionality for larger businesses, including business-to-business (B2B) commerce tools, also known as wholesale commerce.

Last year, research company Gartner recognized Shopify as a leading provider of digital commerce software, awarding the company the highest score for its ability to execute. This year, Forrester Research recognized Shopify Plus as a leading B2B commerce platform. Both reports mentioned rapid innovation as a key advantage. As an example, Shopify recently debuted a generative artificial intelligence assistant called Shopify Magic that can write product descriptions, forecast sales, edit images, and redesign storefronts.

Shopify reported solid financial results in the first quarter, beating expectations on the top and bottom lines. Revenue increased 23% to $1.9 billion on strong growth in subscription software and merchant services. Non-GAAP (adjusted) net income was $0.20 per diluted share, up from $0.01 per diluted share in the prior year.

Notably, management said B2B gross merchandise volume rose 130% in the first quarter after doubling in 2023. That is encouraging because the B2B e-commerce market is much larger and expanding much faster than the retail e-commerce market. Straits Research estimates that B2B e-commerce sales will increase 19% annually to $31 trillion by 2031, while retail e-commerce sales will increase 8% annually to $8 trillion by 2030.

Wall Street expects Shopify to grow sales at 21% annually through 2026. That consensus estimate makes its current valuation of 11.4 times sales look reasonable. Patient investors should feel confident buying a small position in this growth stock today.

Paycom Software: An HCM software vendor trading near its cheapest valuation in history

Paycom provides payroll and human capital management (HCM) software. Its platform helps businesses manage the full employee lifecycle, from hiring through retirement, by integrating applications for recruitment, training, scheduling, and human resources (HR) functions like benefits administration.

The breadth of the Paycom platform is attractive because most enterprises rely on multiple vendors to meet their HCM needs. Consolidating through a single vendor simplifies the user experience and eliminates costs associated with integrating and maintaining disparate products. For instance, standardizing on a single platform relieves HR administrators from the burden of entering data into multiple systems.

Paycom has differentiated itself through innovation surrounding workflow automation. In 2021, the company introduced Beti (Better Employee Transaction Interface), the industry's first self-service payroll solution. Beti automates payroll by requiring workers to review and approve their paychecks before processing. In 2023, the company introduced Gone, a feature that lets businesses automate decisions regarding employee time-off requests.

Paycom reported reasonably good financial results that beat expectations in the first quarter. Revenue increased 11% to $500 million, while non-GAAP net income increased 5% to $2.59 per diluted share. Growth was slower on the bottom line due to investments in product development. On that topic, CEO Chad Richison said Paycom's payroll software is now available in Ireland, its fourth international market alongside Canada, Mexico, and the U.K.

Wall Street expects Paycom to grow earnings per share at 10.4% annually. That consensus estimate makes its current valuation of 17.7 times earnings look quite reasonable. In fact, Paycom currently trades near its cheapest price-to-earnings multiple in history. I think the stock stands a good chance of beating the market over the next three to five years.