Investing in stocks is one of the greatest ways to build long-term wealth available to ordinary Americans. Despite the long-term benefits, stock investing carries with it several risks that make it a bad idea to keep 100% of your money invested in stocks throughout your entire life. Even Warren Buffett -- arguably the greatest stock investor of our time -- has left guidance for his wife for after he dies that indicates that she should own some bonds in her portfolio.

Indeed, to borrow percentages from that guidance, investing in stocks for the long haul is around 90% of what it takes to wind up comfortable. The other, equally important 10% comes from having a smart asset allocation strategy. With that in mind, here are three asset allocation rules you should know by heart.

A bag of money sits on one end of a fulcrum, with wooden blocks representing various asset classes on the other.

Image source: Getty Images.

No. 1: Money you need to spend within five years does not belong in stocks

While it may be difficult to remember this deep into the incredible bull market we've been living through, stocks don't always go up. You can't predict when the market will fall, but one thing that's certain is that when it does fall, your bills won't wait for your portfolio to recover.

When those bills come due during a bear market, if the only asset you have is stocks, then you'll be forced to sell more shares at a lower price to cover your costs. That can be a recipe for running out of money far earlier than you otherwise might expect97彩票代理. That's the primary reason you need money in assets other than stocks, even though you'll probably get a lower return on that money over time.

Typical guidance is to keep at least five years' worth of money you need to spend from your portfolio in cash and/or an investment-grade bond ladder. In good years in the stock market, you sell some of your stocks to replenish the cash and/or maturing bonds. In bad years, you spend down your cash and/or bonds. With a five-year buffer, you can ride through a lot of market turmoil and still wind up OK.

Of course, too much safety can also be a problem. If you hold all your assets in low-volatility, low-return assets, then you're putting yourself at risk of not being able to keep up with inflation over time. So balance the need for long-term growth against the need for near-term spending cash when it comes time to turn to your portfolio to help cover your costs.

No. 2: You need around 20 stocks to get the benefits of diversification

Four hands pulling apart a dollar bill

97彩票代理Image source: Getty Images.

Diversification is the closest thing to a free lunch available to ordinary investors. While it won't increase your expected rate of return, it will reduce the impact of a catastrophic failure in any one of your investments, better allowing the rest of your portfolio to hold up. According to a study reported in Investment Analysis and Portfolio Management97彩票代理, around 90% of the value of diversification comes from holding around 12 to 18 stocks, preferably held across different industries.

Taking that range and rounding it up to 20 also helps from a kitchen-table logic perspective. Over time, the market's long run average return rate has been somewhere in the neighborhood of 10%. If that trend holds, in an equally weighted portfolio of 20 stocks, the complete loss of any one company would mean the loss of around half a year's expected return. While you'd still feel that loss, it wouldn't be completely devastating to your portfolio and would be something you should be able to recover from.

Contrast that with a concentrated portfolio, such as where most of your net worth is tied up in your employer's stock97彩票代理. If that single company runs into trouble, then you will find yourself in a world of financial hurt.

No. 3: You should aim for a retirement portfolio 25 times your annual needs

An upward trending arrow appears with the word inflation above it, percent signs below, and stock price data in the background.

Image source: Getty Images.

According to a retirement planning guideline known as the 4% rule97彩票代理, if you follow these straightforward rules, your portfolio will have a very good chance of lasting as long as a 30-year retirement does:

  • Have a well-diversified portfolio across stocks and bonds.
  • Maintain that diversification throughout your retirement.
  • Withdraw 4% of the starting value of your portfolio in your first year of retirement.
  • Adjust your withdrawals for inflation each year.

Flip that 4% number on its head, and it means you'll need your portfolio to be around 25 times the size of the money you need to withdraw from it in your first year of retirement. That doesn't mean 25 times your total spending -- just the money that you need to come from that portfolio. Most retired Americans get Social Security, which provides them an inflation-adjusted income stream.

97彩票代理So if in total, you expect to need $50,000 in income per year in retirement and expect Social Security to cover $20,000 of it, your portfolio would need to cover $30,000 per year. That would indicate a portfolio around $750,000. If that number seems totally out of reach given the time you have left before you retire, it's better to recognize it before you retire than after you do.

If you recognize it before you retire, you still have time to make adjustments, such as delaying Social Security to closer to age 70 to increase your monthly benefit. Remember, too, that the 4% rule is based on the assumption of a 30-year retirement. Work longer, and your portfolio won't need to last as long, which means you can spend more of it each year.

A solid foundation for a lifetime financial plan

97彩票代理Those three asset allocation rules provide a pretty decent foundation for a financial plan that can get you to and through retirement. Indeed, they are so core and fundamental to your lifelong financial well-being that they're worth knowing by heart. Keep them front and center as you build and execute your plan, and you'll be better able to see whether you're on track for a comfortable future.

That should help you judge your progress over time make any needed course corrections sooner, which is a great way to improve your chances of having the retirement you're working for.