A whopping 81% of the stocks in the S&P 500 are in positive territory this year. The stocks of companies like Ford (NYSE:F), Goldman Sachs (NYSE:GS), and Apple (NASDAQ:AAPL) have all more than doubled this year. And it's not like these are some tiny micro caps -- these are all multibillion-dollar companies!

Which means it might be time to take some money off the table.

But knowing when -- and how -- to sell is one of the most difficult investing decisions you have to face. It's much more difficult than deciding whether to buy a particular stock.

But just ahead, I'll outline four key criteria you should use when determining whether you should sell a stock, and then spell out two different ways to do so. But first, let's look at why it's so tough to let go.

Breaking up is hard to do
Cognitive dissonance makes us uncomfortable. Really uncomfortable.

Cognitive dissonance is that feeling you get when you know you shouldn't do something, but you also know that it feels damn good. It's the feeling you get when deciding whether or not to order the 1,420-calorie Hardee's Monster Thickburger. It's also the feeling you get when you're up 100% on a stock that you were once down 50% on. You swore you'd sell when you broke even, but now you're thinking of holding on for another 100%, or maybe another 200% ... on second thought, maybe you'll just wait and see where you are six months from now.

If you've ever been in that last scenario (if you're like me, you're probably going through that process with your portfolio right now), it's a good idea to have hard-set rules for when to sell a stock. That way your easily swayed emotions don't get the best of you when it really is time to move on.

Here are four criteria that you should use when determining whether or not to sell.

1. Better opportunities
Whether you're up, down, or at break-even with a stock in your portfolio, if you come across a more attractive opportunity, you should seize it.

What qualifies as a more attractive opportunity? Two things: A stock that's more undervalued than a current holding, or a stock that's valued about the same, but has a lower level of risk.

For example, let's say you own a small-cap stock like Cell Therapeutics (NASDAQ:CTIC), and you're up nearly 200%. You think it still might be about 10% undervalued. But you also have been looking at ConocoPhillips (NYSE:COP), which you think could be as much as 25% undervalued. At this point, it would make sense to take your already-high gains on Cell Therapeutics and snap up shares of ConocoPhillips.

2. Valuation
It's a smart move to have some rules in place regarding a company's valuation. Amazon.com (NASDAQ:AMZN) might have seemed a reasonable investment at its recent 52-week low, when it was trading for 23 times earnings. But now that it's trading for almost 80 times earnings, it's not nearly as attractive, and might be overvalued. If you have an undervalued company you've been eyeing, it'd be best to sell Amazon and buy it instead.

3. The business changes
There's only so much you, as an outsider, can know about a company. Most day-to-day business is out of your control. Take the shake-up at Satyam Computer Services (NYSE:SAY) earlier this year. When it was announced that executives were engaged in accounting fraud, assumptions you had about past business cycles, the current state of business, and even expectations for the future were no longer trustworthy. In this scenario, it's usually best to take your losses or gains and move on.

4. Wrong investment thesis
When you're looking for companies, you want to find ones that are undervalued and that have a strong catalyst for growth. If your thesis for investing in a company was a potential growth opportunity in China, and then it comes to light that the company is scuttling plans to enter that international market, your thesis is invalid. It's tough to admit that you were wrong, but it's best to humbly admit your error and move on to better opportunities.

Just letting go
When you are ready to sell, you can either do so gradually, or do so completely. When it's a valuation issue, it's usually best to move out of the position gradually, in case the stock still has more near-term upside. But when the business radically changes, your investment thesis is wrong, or you see a clearly better opportunity, selling in one fell swoop is often the best move.

Even though this is the criteria I use when deciding whether or not to sell, the criteria I've outlined above is -- truth be told -- not something I've come up with myself. Rather, I've adopted it from the team at Motley Fool Million Dollar Portfolio.

The team members use these four reasons when deciding whether to sell a stock in their real-money newsletter service. Not only do they tell members exactly when to begin forming a position in a company they find attractive, but also they perform the more difficult task of telling members exactly when to sell, using the unemotional criteria I just shared.

If you're interested in monitoring their live, real-time, real-money advice, MDP is reopening its doors in just a few days for the first time in more than a year. To find out more information, or to be notified when it does open to the public, just enter your email address in the box below.