To be a successful long-term investor, you need to make sure your portfolio won't implode on the first sign of a rainy day. What seems like a great idea during the best of times will only reveal its true nature during the worst of times.

Sticking with companies that can perform well regardless of economic conditions is an effective way to harden your portfolio. Here's why three of our Foolish investors think Wal-Mart (NYSE:WMT), Facebook (NASDAQ:FB), and Microsoft (NASDAQ:MSFT) are some of the best rainy-day stocks.

Water flowing off the roof of a building while it's raining.

Image source: Getty Images.

Dark and stormy days for investors

Danny Vena (Wal-Mart): Investors planning for a rainy day should fortify their portfolio with companies that can perform well during periods of economic instability, which is when consumers tend to spend carefully, forgoing their usual shopping habits and opting for lower prices. During the depths of the Great Recession, many shoppers turned to Wal-Mart's "Always low prices" to help make ends meet.

As the largest retailer in the world, Wal-Mart has unmatched economies of scale. For its fiscal year ended January 2017, it produced revenue of $485.9 billion and operating income of $22.8 billion. Its operating cash flow totaled $31.5 billion, and it returned $8.3 billion to shareholders via share repurchases. 

Wal-Mart is also a Dividend Aristocrat, having paid a dividend every year since 1974 and boasting 44 years of consecutive increases. It has a dividend that currently yields 2.5% and a healthy payout ratio of 48%, leaving room for future increases.

While the company was initially slow to embrace e-commerce, it corrected that last year with its $3.3 billion purchase of, as well as a number of other smaller specialty clothiers. As a result, in its most recent quarter the company posted impressive increases in e-commerce sales, which grew 60% over the prior-year quarter, with gross merchandise volume increasing 67% year over year.

If you're looking for a stock for a rainy day, consider this: During the bear market that began Oct. 9, 2007, and ended March 9, 2009, while the broader S&P 500 (SNPINDEX:^GSPC) fell 56%, Wal-Mart stock gained 10%.

WMT Chart

Data by YCharts.

Check out social media

Keith Speights (Facebook): What do people do on a rainy day? They stay inside. While inside, there's a pretty good chance that they'll look at social media. And the undisputed king of social media is Facebook. I suspect that the executives at Facebook like it when people stay inside on rainy days, because it increases the amount of time they spend catching up on friends' posts -- and looking at ads.

Ads generate 98% of Facebook's revenue. And that revenue is growing, with the company reporting a 47% year-over-year jump in advertising revenue in the second quarter of 2017. This growth stems from two factors. First, Facebook charged 24% more per ad in the last quarter. It can get away with that kind of price boost because it reaches more than 2 billion monthly active users. Second, the company is also increasing the number of ads displayed. More volume at higher prices is a surefire way to make more money.

But can buying Facebook stock make you plenty of money? I think so. Wall Street projects that Facebook will achieve average annual earnings growth over the next five years of nearly 27%. That's a drop from the heady growth of past years, but it's still an impressive level. That growth makes Facebook's valuation look pretty reasonable as well.

Facebook isn't just a leader in social media. It's also a leader in artificial intelligence and augmented reality, two of the hottest trends in technology today. Buying Facebook stock is a way of investing in these two trends. That's a pretty smart way, in my view, to use time on a rainy day so that your financial future isn't stormy.

A tech giant for all seasons

Tim Green (Microsoft): Software giant Microsoft has changed quite a bit over the past few years. It's embraced cloud computing, building its Azure cloud platform into a strong No. 2 player. It's dropped its Windows-centric position, building first-class apps for Android and iOS. And it's building an increasing amount of hardware, from its Surface tablets and laptop to its HoloLens augmented reality headset.

But what hasn't changed about Microsoft is its dominant position in the productivity software market. Businesses depend on Office, Outlook, and other Microsoft products, and that's likely to remain true regardless of the state of the economy. Office is still the company's cash cow, despite serious competition from Alphabet's Google.

While Microsoft is heavily investing in growth businesses like cloud computing, the company is still producing impressive profits. During fiscal 2017, Microsoft generated $21.2 billion of net income on $90.0 billion of revenue. Meanwhile, Azure revenue is doubling year over year, and Office 365 commercial, the subscription version of Office, is growing by more than 40% annually.

Microsoft is in an enviable position, with dominant businesses like Office throwing off cash, allowing the company to invest in newer businesses that will act as its growth engine for years to come. Through the good times and the bad, Microsoft should continue to produce exceptional results.

Suzanne Frey, an executive at Alphabet, is a member of The Motley Fool's board of directors. Teresa Kersten is an employee of LinkedIn and is a member of The Motley Fool's board of directors. LinkedIn is owned by Microsoft. Danny Vena owns shares of Alphabet (A shares) and Facebook and has the following options: short December 2017 $75 calls on Wal-Mart Stores, long January 2018 $57.50 calls on Wal-Mart Stores, long January 2018 $640 calls on Alphabet (C shares), short January 2018 $650 calls on Alphabet (C shares), long January 2018 $55 calls on Wal-Mart Stores, and short December 2017 $75 calls on Wal-Mart Stores. Keith Speights owns shares of Alphabet (A shares) and Facebook. Timothy Green has no position in any of the stocks mentioned. The Motley Fool owns shares of and recommends Alphabet (A shares), Alphabet (C shares), and Facebook. The Motley Fool has a disclosure policy.