Home to the ninth-lowest beta in the S&P 500 index, snacking juggernaut The Hershey Company (HSY 2.80%) dispels the notion that "safe" stocks can't generate life-changing returns. While its 0.34 beta -- which measures the company's share price movements compared to the broader market -- signifies extremely stable operations, Hershey has tripled the total returns of the S&P 500 since 2000.

However, a rare amalgamation of challenges over the last year has sent Hershey's shares down 30% from their 52-week highs.

Despite these difficulties, the company's kid-friendly operations and simple business model make it a great starter stock to learn from, which is why I have happily been buying Hershey's shares for my daughter's portfolio over the last few months.

Here's why I still think Hershey is poised to create lasting generational wealth for any kid's portfolio as it overcomes these obstacles.

Why Hershey will move past its current headwinds

Currently, there are two short-term and two longer-term issues facing Hershey's operations:

Short-term pain

Due to heavy rains in West Africa, cocoa prices have doubled in the last year alone.

Cocoa Price Chart

Cocoa and Sugar Price data by YCharts

Meanwhile, sugar prices have outpaced the rate of inflation. Combined, the price increases among these two ingredients impact Hershey's confectionary operations, which account for more than 80% of the company's sales.

Further weighing on the company's outlook were massive capital expenditures tied to integrating a new enterprise resource planning system and boosting production capacity by 25%.

HSY CAPEX To Revenue (TTM) Chart

HSY CAPEX To Revenue (TTM) data by YCharts

With its capital expenditures at the highest levels of this century and its key ingredient prices ballooning, it would be reasonable to expect Hershey's profitability to plummet. However, its net profit margin and free-cash-flow margin have proven resilient, at 17% over the last year.

Although management expects earnings per share (EPS) to remain flat in the upcoming year, these prices and capital expenditures should trend lower over the long term, providing an excellent rebound catalyst for patient investors.

Long-term, existential threats?

In addition to these short-term complications, the growing popularity of Mr. Beast's Feastables and the rise of GLP-1 weight loss drugs continue to cause the market to fret over Hershey's long-term success.

With YouTuber Jimmy Donaldson (Mr. Beast) expecting his Feastables chocolates to generate more than $500 million in sales in 2024, there is no doubt that his 200 million subscribers could pose a significant threat to Hershey. However, even if Feastables were to reach this mark, it would still equate to less than 5% of Hershey's sales last year.

Furthermore, a recent Segmanta survey on the snacking habits of Gen Z -- Mr. Beast's target audience -- listed KitKat, Hershey's, and Reese's (all Hershey's labels) as their favorite chocolate brands.

As for the booming demand for GLP-1 drugs, it is still far too early to tell what the impact of these weight-loss medications could be. However, there's a contrarian argument that these drugs could encourage shrinkflation, benefiting Hershey's margins as customers seek smaller portions.

In spite of these headwinds, Hershey's grew its sales and EPS by 7% and 13% in 2023 while increasing its dividend payment by 15%, highlighting the pricing power in the company's business. Best yet for prospective investors, despite its stable results amid these trying times, the company now trades at its most attractive valuation in over five years.

Person takes a bite of a candy bar while standing in front of a white wall.

Image source: Getty Images.

Hershey's above-market dividend yield and below-market valuation

With its share price down 22% over the last year, Hershey now trades with a price-to-earnings (P/E) ratio of 21, slightly below the S&P 500's average of 23. Meanwhile, its 2.5% dividend yield is well above the index's average of 1.5%. When combined, these two data points make a compelling case for the company's shares being reasonably priced, if not undervalued -- especially when compared to Hershey's five-year averages.

HSY PE Ratio Chart

HSY PE Ratio data by YCharts

Despite this higher-than-normal yield, the company's dividend payments only use 48% of its net income, leaving ample room to extend its 14-year dividend increase streak far into the future. Locking in this 2.5% yield at a below-market valuation, I'll happily keep buying shares of Hershey for my daughter while waiting for the company's capital expenditures to decline to normal levels alongside an eventual drop in cocoa and sugar prices.

While Hershey won't be the next stock in the S&P 500 to become a multibagger, I'm confident it will create generational wealth for my daughter over the next few decades, just as it has done so far this century.