Investors devote a lot of attention to what stocks to buy and when. But how do you know when it’s time to sell? The answer is as difficult as deciding when to buy, but it’s rarely discussed.

The one constant variable when deciding to buy or sell is how the stock price compares to intrinsic value. Don’t think of stocks as pieces of paper to trade, but as a piece of the business you own. With this attitude in mind, investors should seek a quality business they fully understand, with superior economics and a first-rate management team.

And they should purchase shares only when they’re undervalued. In an ideal world, the stock price would grow, the company would continue to increase its intrinsic worth, and investors could hang on to their shares for years to come.

But it’s not always that easy. If it were, then “the best time to sell a stock [would be] never,” says Warren Buffett.

The problem is that, over the short or medium term, the stock market is often influenced more by crowd psychology, which fluctuates between extreme euphoria and depression, than by fundamentals. As a result, stocks don’t go from undervalued to fairly valued. Instead, euphoric momentum can carry them into overvalued territory.

And when the share price is unjustifiably higher than what the business is worth, it’s a great time to sell. After you’ve sold, don’t be surprised if the stock price continues to rise. Although it’s painful to forgo some of these speculative gains, we all know that what goes up eventually comes down.

A market correction brings stocks back to reasonable levels and even presents opportunities to purchase more shares, or buy other great businesses at bargain prices.

Read: Go global for dividend growth

Often, the wisest decision to sell is based on a change in business fundamentals. Although this seems simple, in practice selling is not that straightforward. The following factors must be considered.

01 The costs of selling. Beyond the transaction costs associated with brokerage fees and commissions, for every sale you must also consider other frictional costs, such as foreign exchange rates and capital gains taxes. For example, if an investment returns 15% per year and it was left to compound for the next 30 years, your client would only be required to pay taxes when the investment is sold. Given a 35% tax rate, she would achieve 13% annual returns after tax. On the other hand, if she were continuously trading and still managed to earn a 15% return, she would constantly trigger taxes, thereby reducing the annual return to below 10%.

With every trade, there is also the opportunity cost related to determining what to do with the proceeds of the sale. In each investment we make, we forgo the benefits we may or may not have in an alternative investment. With every sale, you will need to find another equally good or better investment to make with the proceeds. Needless to say, this is not an easy feat.

02 The business characteristics that have changed to prompt a sale. Determine if these changes are likely to be permanent. Selling a company because of changes in its economic characteristics, whether subtle or severe, can be risky.

For instance, if the company’s weakened economic state is only temporary, sellers could overreact, causing the share price to suffer. This situation can actually present an opportunity to buy; selling would be both foolish and costly.

Temporary losses in the portfolio are nothing to fret about, as long as the decrease in price is not caused by erosion in a company’s intrinsic value. In order to make this important distinction, investors must find out if the company’s business model will continue to be viable. To do so, ask the following questions:

  • Have the long-term economics of the business or its industry deteriorated or changed?
  • Has the risk profile of the business changed?
  • Is the business no longer insulated from competition?
  • Has the capital allocation strategy changed?
  • Does it earn a high return on capital, and can it continue to do so?
  • Does the management team consist of capable operators?

Read: Looking for low volatility

These are essential questions that should not be answered in haste. In order to do so, it is essential to have a full understanding of the business, and that opinions not be based on short-term business results. Examine the evolution of the business over several years, and maintain a long-term perspective. When it comes to selling, there is no magic formula. Whether it be to cash in on an overvalued stock, pursue better investment opportunities or because the company no longer possesses the characteristics it originally had, trades should only occur when there are advantages of doing so that are obvious for investors.

Do clients have worthless stock?

When a client dies, any property he owned is automatically deemed sold at fair market value. But what if that property includes stock certificates from companies that no longer exist?

It’s up to the trustee to deal with these worthless securities. If the shares are valued at $0, upon death they’re deemed to have been disposed for $0. Usually that gets the estate a capital loss. That loss can offset any income in the year of death, or 50% of any capital gains in the previous year’s return—and sometimes both. Suddenly, the worthless shares have become valuable, especially if the adjusted cost base was high.

Assume your client bought $50,000 worth of stock, but the company went out of business five years ago and the stock certificates are worth $0. The capital loss is $50,000, of which $25,000 can be applied to offset income or gain. Say his income the year he died was $15,000, and capital gains income the previous year was $10,000. The capital loss of $25,000 offsets the $15,000 income and $5,000 of last year’s capital gains. (The remaining $5,000 loss can’t be used.)

–Tim Brisibe, wills and estate planner

Susy Abbondi is a portfolio manager at Duncan Ross Associates.