Bond funds have done better than stocks, so far this year. They’re up 1.6 percent, in a period when Standard & Poor’s 500-stock index looks flat and Nasdaq is down 5 percent.

Over the 65 ten-year periods since 1926 (starting each January), bonds have beaten stocks only 12 times, reports Ibbotson Associates of Chicago. Half of those decades encompassed the 1929 crash and Great Depression. Five periods fell between 1964 and 1979 –years of war, stagflation and Jimmy Carter’s cardigan. And then there was 1980-90, when interest rates plummeted and bond prices soared.

But you don’t own bonds to outperform. Their primary function is security. They generate a predictable income, valued by retirees, and support your net worth when stocks go bad.

A heretic: Stocks haven’t gone bad in nearly 20 years, so modern investors barely give bonds a thought. We’ve all become long-term players now (or so we think). But here’s my personal heresy: in the long run, stocks are not always safe.

First –as I’ve written before in this space –the studies of long-term stock performance refer to the market as a whole, usually measured by the Wilshire index of 5,000 stocks. You get market performance from index mutual funds. But any of the individual stocks you own can do poorly over 20 years or even tip into bankruptcy.

Second, you don’t necessarily reduce your risk, even if you buy index funds. It depends on what you mean by risk, says Mark Kritzman of Windham Capital Management in New York. For example:

The longer you invest in “the market” (that is, an index fund), the smaller the chance that you’ll lose money when you sell. That bolsters the popular belief that, eventually, stocks are safe.

But the longer you hold, the greater the chance that –at some point –you’ll suffer a major loss. That’s because markets plunge from time to time, and may take years to struggle back to a rising track. Veterans of the one-year ‘87 crash imagine that rotten markets pass like a summer storm. But in the late ’60s and early ’70s, stocks went nowhere for 10 or 15 years.

And finally, the longer you hold stocks, the greater the chance that a loss, when it comes, will be of truly awful size.

To sum up –over time, your risk of losing money goes down while your risk of a heart-stopping loss goes up. That’s another way of saying that stocks are always risky, no matter how long you invest. You could invest, fear-free, for 20 years, then suffer a drop of 40 percent just when you’re ready to retire.

History shows no U.S. stock losses over 20-year periods. But that doesn’t mean it couldn’t happen. Anyway, how would you feel –at any time –if your nest egg dropped by 40 percent?

“Ultimately, it’s a question of pain, not gain,” says economist William Sharpe, Nobel Prize winner and professor emeritus at Stanford University’s Graduate School of Business. How bad would you feel if you fell into one of the market’s occasional black holes? How much would it change your life?

If you could truly shrug off the loss, by all means keep all your long-term money in well-diversified stocks. But if it would wreck your retirement, your kids’ college plans, your marriage or your mental health, it’s dumb to invest as if stocks were safe. You need a cushion, just in case.

A cushion?What should that cushion be? If inflation soars, Treasury bills or money-market funds would be the best defense, because their interest rates would keep going up. If inflation stays low, you’d do better with bonds because they yield more.

No one can know what’s best in advance. Right now, however, the pros are making a case for bonds. General bond mutual funds currently yield around 6.3 percent, according to Lipper, which tracks fund returns. Compared with inflation, that’s pretty high. The share prices of bond funds have fallen since interest rates began to rise (especially on high-yield funds). But they’ll recover when the rate squeeze ends.

Marilyn Cohen, president of Envision Capital Management in Los Angeles and author of the new book “Bond Bible,” thinks that baby boomers will soon discover bonds. “As they turn 55, they’re going to start looking at their exit strategy for retirement,” she predicts. “Stock-price volatility wears you out. As you get older, you want more predictable income from your investments.”

Investors in taxable accounts should be looking at tax-free municipals. You can get 5.3 percent on 10-year, AA-rated bonds. That’s almost as much as the taxable 6.12 percent paid by comparable Treasuries. For tax-deferred retirement accounts, 10-year AA-rated corporates yield a fat 8 percent. That would have beaten stocks over nearly one third of the 10-year periods since 1926.

When balancing safety and risk, you have one other asset to consider, says Zvi Bodie, finance professor at Boston University School of Management. That’s your “human capital,” or future earning power. It’s probably your biggest asset. Future income can be reasonably safe, like a bond (teacher, corporate manager). Or it can be uncertain, like a stock (freelancer, small-business owner). When your paycheck seems safe, and you have many working years ahead, you can take on the risk of keeping more money in stocks. But with uncertain earnings, or toward the end of your career, owning too much stock can endanger your future standard of living.

Historically, boom years for U.S. stocks have been followed by poorer years (flat from 1926 to 1940, rising until 1966, flat again until 1983, then another leap). But will this happen again? And if so, when? “The big problem in investment life is to know when to disregard history,” says Nobel economist Paul Samuelson. “There’s a time to remember and a time to forget.” You own different types of investments because nobody tells you when times have changed.