It was December 2016. My wife and I had finally decided to buy a house. In order to raise funds for the down payment, we were going to sell some stocks. Much of the money came from liquidating 80% of our holdings in a single company.

I chose that stock for one big reason: I didn't think there was much room left for growth. It was trading with a PEG ratio of 8.2 and had a trailing price-to-free-cash-flow (P/FCF) ratio of 39, and it had just enjoyed a run-up of 20% over the previous two months.

Stressed man with financial market graphic going down

Image source: Getty Images

The stock I sold was IPG Photonics (NASDAQ:IPGP), an industry leader in fiber-optic lasers. And after this week's run-up, here's what the company's stock has done since the date I sold.

IPGP Chart

IPGP data by YCharts

I recently calculated the upside potential that I lost, and it's in the tens of thousands of dollars.

Of course, we got a house in return -- a social and emotional investment that I wouldn't trade for anything. And it would have been far smarter for me to spread my stock selling around so that I didn't lose so much exposure to a single stock.

But that's not what this article is about. It's about a common mistake my story highlights -- one that I, and probably you, too, have committed several times.

My biggest investing mistake

Summed up in the simplest way possible, the fundamental investing rule I broke is this:

Selling based on valuation alone -- when a moat and optionality are present -- will cost more in lost gains than any potential losses.

This is demonstrably true in the case of IPG Photonics. The most I could lose was 100% of my holdings -- had the company gone bankrupt. But I missed out on nearly double that amount in gains.

What's a moat?

In order to put this rule into practice, it's important for us to define two of the italicized terms above: "moat" and "optionality."

"Moat" is another name for a sustainable competitive advantage. In short, it's the special something that keeps customers coming back and holds the competition at bay for years or decades.

In the investing world, I believe there are four types of moats:

  1. Network effects: Each additional customer adds value to a network and incentivizes others to join. Facebook is the clearest example, as each person that joins the network makes it more worthwhile for others to join. Who wants to be on a social network if no one else is on?
  2. High switching costs: Even if a customer sees a better provider, the costs of switching to that provider are onerous. For a long time, this was an advantage many wireless service providers maintained through extremely high cancellation fees.
  3. Low-cost production: If a company can consistently provide a good or service for less money (and of the same or superior quality) than its competitors, then it can offer a better deal for customers. This was the case with IPG Photonics (more on that below).
  4. Intangible assets: These "special somethings" include non-physical assets like patents, brand strength, and regulatory protection. For example, Apple's intangible assets include the patents that protect its technology and its globally recognized brand.

IPG Photonics' greatest moat was its low-cost production. It's the only vertically integrated fiber-optic laser manufacturer of its scale in the world. That means it produces every part of its lasers instead of relying on third-party vendors, which allows it to keep its manufacturing costs much lower than the competition's.

Why wouldn't other players do the same? Well, it comes with its own downside risk: During an economic contraction, rivals such as Coherent can simply stop ordering laser parts from outside vendors, while IPG will be forced to eat the requisite overhead costs and see profitability plunge.

That said, when demand is high, this low-cost production functions as a powerful moat.

What's optionality?

Next, we need to define a fuzzier concept that best-selling author and former trader Nassim Taleb calls "optionality." Motley Fool co-founder David Gardner calls it "multiple futures." The names might be different, but the meaning is the same: Companies that have multiple ways of fulfilling their missions -- and that use trial and error to find those paths -- will reap huge benefits over the long run.

Perhaps the best example of this is Amazon. The company's mission is to be "Earth's most customer-centric company." It started fulfilling its mission by simply offering books online. Then it came up with the e-reader. That was followed by a move into retail writ large. Then came its massive order fulfillment system, Amazon Prime, and original TV and movie content. Since then, Amazon Web Services has become a dominant provider of cloud computing solutions. It even owns a nationwide grocery store now.

White wooden signpost with four arrows - 'option 1', 'option 2', 'option 3', 'option 4'.

Image source: Getty Images

IPG doesn't have that kind of optionality -- it has no obvious intention to move beyond making fiber-optic lasers. However, the applications for these lasers have tons of optionality. For most of the company's history, fiber-optic lasers were used to cut large pieces of metal. But over the past two years, those uses have expanded dramatically to include telecom, medical, and military options, to name a few. As users tinker with the lasers, their utility has the chance to increase dramatically.

While I fortunately haven't made too many mistakes like selling IPG in my own real-life portfolio, my CAPS stock-picking profile is rife with such examples. Consider that in 2009 I "sold" shares of Apple at $33 (missing out on 430% upside), Starbucks at $11 (445%), and Netflix at $16 (1,200%).

The inverse is true as well

All that said, when I've sold shares based on valuation -- when either a moat or optionality is not present -- it has worked out quite well for me.

In November of 2016, I sold shares of Chipotle, Under Armour, and GoPro. The only moat any of them had came from their brands -- which I consider to be the weakest of all moats -- and I didn't see any evidence of potential optionality. At the time, they also traded for expensive ratios. Here's how they performed.

Company

Non-GAAP P/E When I Sold

Returns vs. S&P 500 Since I Sold

Chipotle

162

(46 percentage points)

Under Armour

53

(79 percentage points)

GoPro

N/A

(67 percentage points)

Data source: YCharts, E*Trade, Google Finance. N/A = not applicable due to negative earnings.

This isn't to say that I'm against buying companies that have yet to gain a meaningful moat or demonstrate optionality. Instead, if I'm investing in such companies, I will pay much closer attention to valuation.

Stocks I'll never sell because of valuation

Finally, I think it's important to point out where my own skin is in the game. I have five stocks that account for a whopping 61% of my real-life holdings. While I might one day sell shares of these five because they've grown too large, I won't do it based on valuation alone. Here's why, with links to my reasoning.

Company

Moat

Optionality

Amazon

  • Network effect (fulfillment by Amazon)
  • Brand value
  • Low-cost production (shipping)
  • Discussed above

Facebook

  • Network effect
  • Acquisitions (similar to Instagram, WhatsApp, Oculus)

Alphabet

  • Brand value
  • Low-cost production (data)
  • High switching costs (Google Drive)
  • Google X
  • "Other Bets"

Baidu

  • Brand value
  • Low-cost production (data)
  • AI initiatives

Mercadolibre

  • Network effect (auction platform)
  • High switching costs (MercadoPago)
  • Low-cost production (delivery)
  • MercadoPago
  • MercadoEnvios

While I hope these specific stocks may give you ideas to start your own due diligence, there's a broader lesson to be learned here: The future is unknowable. As such, it's important that we put our chips into stocks that stand to benefit from the unknowable. Moats and optionality do that, so we shouldn't worry as much about valuation -- which is predicated on trying to predict future value -- when those two are present.

Happy investing!

John Mackey, CEO of Whole Foods Market, an Amazon subsidiary, is a member of The Motley Fool's board of directors. Suzanne Frey, an executive at Alphabet, is a member of The Motley Fool's board of directors. Brian Stoffel owns shares of Alphabet (A shares), Alphabet (C shares), Amazon, Apple, Baidu, Facebook, IPG Photonics, MercadoLibre, Netflix, and Starbucks. The Motley Fool owns shares of and recommends Alphabet (A shares), Alphabet (C shares), Amazon, Apple, Baidu, Chipotle Mexican Grill, Facebook, GoPro, IPG Photonics, MercadoLibre, Netflix, Starbucks, Under Armour (A Shares), and Under Armour (C Shares). The Motley Fool owns shares of Coherent and has the following options: long January 2020 $150 calls on Apple and short January 2020 $155 calls on Apple. The Motley Fool has a disclosure policy.