The S&P 500 (SNPINDEX: ^GSPC) has rebounded sharply from its bear market lows as signs of economic resilience have revitalized investor sentiment. Indeed, after declining as much as 25% last year, the benchmark index is now 6% from a record high. In other words, the S&P 500 is on the brink of bull market territory.

That milestone is important because the rising tide of a bull market can be very lucrative for investors. The S&P 500 returned an average of 259% during the six bull markets that have taken place in the last five decades. But investors hoping to turn a profit in the next bull market need to know where to put their money, and Warren Buffett is a good source of inspiration.

Buffett once said, "All there is to investing is picking good stocks at good times and staying with them as long as they remain good companies." Here's what that means.

An origami bull ready to charge.

Image source: Getty Images.

The secret to picking "good stocks"

Warren Buffett believes a durable moat is the most important quality a company can possess. He wrote as much in his 2007 letter to Berkshire Hathaway (BRK.A -0.76%) (BRK.B -0.69%) shareholders: "[A] long-term competitive advantage in a stable industry is what we seek in a business. If it comes with rapid organic growth, great. But even without organic growth, such a business is rewarding."

A competitive advantage (or moat) is a quality that allows a company to outperform its competitors or at least maintain its market share. Identifying such advantages takes practice, but Buffett says it boils down to pricing power. Before buying a stock, investors should question whether the company can raise prices without ceding share to the competition. If the answer is yes, it's probably a good company.

Investors looking for examples should glance at the stocks in Berkshire's portfolio. For instance, Apple (NASDAQ: AAPL) and Amazon (NASDAQ: AMZN) both benefit from a durable competitive advantage. Apple draws its pricing power from intangible assets like a brand name that carries weight with consumers and valuable patents that protect intellectual property like the iPhone. Similarly, Amazon draws its pricing power from the unmatched scale of its marketplace and the unrivaled capabilities of its cloud computing platform.

Identifying competitive advantages is not an exact science, and even the most experienced investors make mistakes. In 1993, Buffett made what he calls the worst deal of his life, paying $433 million for the now-worthless shoe business Dexter. He later explained, "What I had assessed as a durable competitive advantage vanished within a few years."

The secret to finding "good times"

A good company is not the same thing as a good investment. Valuation matters. The best business in the world purchased at a premium to its intrinsic value can be a terrible investment. Finding a "good time" to buy a stock means finding a time when that stock trades at a discount to its intrinsic value.

In his 2013 letter to Berkshire shareholders, Buffett described the process by which he and Vice Chairman Charlie Munger evaluate a stock: "We first have to decide whether we can sensibly estimate an earnings range for five years out, or more. If the answer is yes, we will buy the stock (or business) if it sells for a reasonable price in relation to the bottom boundary of our estimate." He goes on to say that in situations where they lack the ability to estimate future earnings, they simply move on to other prospects.

Buffett is referring to a discounted cash flow (DCF) model, a technique that estimates the intrinsic value of a stock by discounting future earnings back to their present value. DCF models are based on the idea that $10,000 today is worth more than $10,000 in the future because money in hand is available for immediate investment. How much more depends on how far in the future and the discount rate (i.e., the minimum acceptable rate of return).

Investors often use the long-term return of the S&P 500 as their discount rate (i.e., 10%). The logic behind that decision is simple: It makes no sense to buy a stock that returns less than 10% per year when the S&P 500 has consistently grown at 10% annually throughout history.

As a final thought: While DCF models may be intimidating because they involve a lot of math, there are plenty of good DCF calculators available online.