If you're like many investors, you might think the stock market is a little overheated right now, and you're probably right. Valuations are high, and there are fewer and fewer bargains to be found.

However, don't go shifting your money into bonds or other "safer" options quite yet. The bond market could be just as overheated as the stock market, and there is one key difference to note: Investors who buy into the stock market at peaks still tend to win over the long run, but the same cannot be said of bond investors.

Why is it better from a long-term standpoint to buy into expensive stocks than expensive bonds?

Bonds lose value as interest rates rise
For the most part, bond prices depend on interest rates. Many other factors can move the price of bonds, such as a downgrade in the underlying company's credit rating, but all else being equal, interest rates are the primary factor.

Let's look at an example. As of this writing, the 30-year Treasury rate is 3.28%. In other words, if I buy $10,000 in 30-year Treasuries, I'll receive interest payments of $328 per year. But let's say the Federal Reserve begins to raise interest rates, and by next year 30-year Treasuries are paying 4.5%.

Now a $10,000 investment would return $450 per year -- about 37% more than the current rate. However, the Treasuries I bought still pay just 3.28%. Because investors now expect a higher return of 4.5%, the intrinsic value of my Treasuries will drop in order to produce a market-rate return. In this case, my $10,000 investment would be worth only about $7,300 on the open market. At that price, the $328 annual payments would produce the "expected" 4.5% return.

And this could just be a starting point if rates really start to rise. Thirty-year Treasuries paid rates as much as 5.25% in the past decade and much more in the years before.

30 Year Treasury Rate Chart

In a nutshell, buying bonds when interest rates are historically low (like they are now) is not likely to work out well for the value of your portfolio.

Stocks still outperform over the long run
Because the nature of stocks is to grow in value over time, it is still possible (and likely) to make money over the long run, even if you buy at a terrible time.

For example, let's say you bought $10,000 worth of an S&P 500 index fund at one of the worst possible times in the past 30 years: Friday, Oct. 16, 1987. That's the trading day before "Black Monday" wiped out more than 22% of the value of the Dow Jones Industrial Average on the single worst one-day drop in history.

Over the nearly 27 years since then, you would still have earned a total return of more than 1,200% on your investment. In other words, your original $10,000 investment would be worth more than $130,000 today.

^SPXTR Chart

In a more recent context, if you had bought in at the 2007 peak, right before the financial crisis hit. In the seven years since then, you would be sitting on a total return of more than 50% on your investment, even though those years included one of the worst recessions in U.S. history.

Keep investing most of your money in stocks and time your bond buying well
The point here is that when the market gets expensive and interest rates are low, stocks are by far the best long-term investment you can make.

As you go along, time your bond buying as interest rates increase. For example, if 30-year rates rise to 6%, it might be a good idea to lock in some high-paying Treasuries or corporate bonds. While there is no guarantee that rates won't continue to shoot up from that point, investing is all about creating a good risk-reward ratio.

At current interest rates, the chances of rates falling further and pushing your bond prices up are slim. Simply put, there really isn't much room for them to fall. However, when rates are high from a historical standpoint, the risk you take is better justified by the high, guaranteed rate of return and the smaller chancse that rates will go much higher.

Try any of our Foolish newsletter services free for 30 days. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.