One of the trickiest aspects of investing is knowing which companies to hold for the very long term. The ones that can generate the most wealth for us are the businesses that go from good to great, and from great to outstanding.

However, holding on to weak businesses over the long term not only prevents compounding, but it also represents an opportunity cost for the investor, as the money could have been deployed more efficiently elsewhere.

Investors who seek growth should look for companies with durable competitive moats, strong products and/or services, and management with the capability to deploy capital to generate high returns for investors. Granted, not many stocks fit this bill, because high growth has a tendency to lead to cash burnout for many companies if not managed properly. An organization that grows significantly larger over the years may also lose its focus and go astray, resulting in capital destruction rather than growth.

After filtering through a long list of companies, here are two stocks that, if held over the last 40 years, would have turned your $1,000 into a cool $500,000.

Growing Piles of Coins

Image Source: Getty Images.

Apple

At first glance, Apple (AAPL 1.27%) does not seem like an ideal candidate for massive compounding. After all, technology companies that manufacture hardware and produce computer software programs are a dime a dozen, and the industry itself is notoriously fickle and fast-changing, leading to quick obsolescence for many emerging technologies.

Apple went public back on Dec. 12, 1980, and traded at a price of around $0.51 (split-adjusted) back then. If you had held it all the way until today, you would have multiplied your money by around 520 times, and this is excluding any dividends that you would have collected in the last 40 years.

Apple was founded in 1976, and originally started off manufacturing computers known as Mcintoshes back in the 80s. It was also one of the first few companies to introduce a graphical user interface at a time when computers were mainly text-based. Over the years, it evolved its hardware from Mcintosh personal computers to the iMac, which boosted sales significantly.

It wasn't until 2007 that the iconic iPhone was launched to critical acclaim and financial success. The iPhone and accompanying iTunes Store have been massively successful to date, but it would not have been easy to hold Apple through thick and thin. The company also nearly went bankrupt in 1997, but was saved by arch-rival Microsoft (MSFT 0.37%) with a $150 million injection.

Today, Apple continues to break new records with a variety of innovative products (such as wearables) and services. The company has grown into a massive juggernaut and is still continuing to grow despite being valued at an eye-popping $1.3 trillion.

Nike

Nike (NKE 0.66%) should be more than a familiar name by now, with its "swoosh" logo emblazoned on the shoes worn by many top athletes around the world. The sports apparel and footwear giant had humble beginnings as a small shoe company founded by Philip Knight in 1964, but has now grown into a huge, $115 billion business.

Nike's IPO was just 10 days before Apple's -- on Dec. 2, 1980. On Dec. 5, 1980, the stock closed at a split-adjusted price of $0.17. Nike is now trading at around $92, and would have multiplied your wealth by around 540 times if you had held it since day one. That works out to a compound annual growth rate of around 17.5% per annum, excluding dividends.

If you think growth may have fizzled out or slowed down after 39 years, think again. Nike has continued to report steady, consistent growth in both revenue and net income. The company continues to innovate by introducing a new range of footwear for athletes competing in the upcoming Olympic Games in Tokyo, Japan.

It is Nike's innovation and its focus on continuous improvement that provides the company with a valuable and strong competitive moat. Investors who jump on now may still enjoy many more years of double-digit growth, with the company's best years yet to come.