I've been writing for The Motley Fool since the '90s, and I have offered the following advice countless times: Don't keep money that you expect to need in the next five years (if not more years, to be more conservative) in the stock market, as it can be volatile in the short term.

That can sometimes be hard to do, especially if the market is in the midst of a bull run, but failing to heed the advice has the potential to burn you, severely. A recent story in the news drives this lesson home. As an amusing adage says, "If you can't be a good example, be a horrible warning."

Someone is grimacing in surprise at an open laptop.

Image source: Getty Images.

Setting the stage -- in Colorado

The University of Colorado is a big school with four campuses, the largest of which is in Boulder. Total enrollment was recently 66,266 students. As of last year, the university had roughly 9,000 faculty members and instructors. The university, known locally as "CU," is the third-largest employer in Colorado, employing about 36,500 people, and it boasts more than half a million alumni.

The operating budget for CU for the current academic year is $5.55 billion.

As you might know, colleges and universities have investment and endowment accounts, too. As of the end of fiscal 2021, for example, Harvard and Yale had the largest endowment funds, valued at $53.2 billion and $42.3 billion, respectively. Most schools have far less than that, and in recent years, the University of Colorado's portfolio has been valued between $2 billion and $3 billion.

What went wrong? Timing

For the fiscal year 2020-2021, the University of Colorado's investment returns were unusually strong -- with growth of 24.4%, some 3.4 times the school's historic average return. That was clearly excellent news, and the university announced that around $436 million would be made available for one-time strategic needs, such as investing in technology and infrastructure, making CU more affordable for Colorado students, and supporting and retaining faculty and staff. To its credit, the university noted that, "Because the funds will be spent over time, market volatility in FY 2021-22 and beyond will impact the amount available."

Well, 2022 turned out to be more volatile than expected. As of this writing, the S&P 500 was down nearly 20% from its 52-week high, and the Nasdaq was down nearly 33%. Market volatility in 2022 was much more than anticipated and impacted the windfall greatly -- resulting in a $120 million decrease in available funds at the University of Colorado.

University of Colorado President Todd Saliman explained in a Denver Post interview: "A year ago we saw this as a once-in-a-lifetime opportunity to put our market gains to use, and we did. But we didn't realize all the gains and now we're in a position where those gains have declined and we can't spend money we don't have."

Vice President and Chief Financial Officer Chad Marturano told the online publication CU Connections: "The substantial drop in market returns means we will have to slow down in some cases and reassess our plans in others. The bottom line is that we have less money to spend on accelerating the strategic plan than we were planning on a year ago."

As you might imagine, faculty, students, and others who were looking forward to all the impending improvements are very upset.

Lessons for us

Having a $120 million shortfall is a horrifying situation, and it's due to a mistake that we small investors can and do make, not infrequently -- leaving money that we'll need in the coming years in the stock market. Many people who'd been planning to buy a home in late 2022, for example, saw funding for their down payments shrivel up, and many who thought they'd amassed enough to retire in 2022 saw their nest eggs shrink by 20%, 30%, or more, putting their future financial security in jeopardy and likely requiring additional years of work.

Moving money you'll need within a few years out of stocks is clearly a sensible thing to do, but it can be a very hard thing to do, too, if your stocks have been soaring and you anticipate them continuing to do so. Removing your dollars from such growth requires discipline and an understanding that the stock market can be volatile, and can deliver unanticipated results at unexpected (and inconvenient) times.

The more you understand what to expect from stock investing, the better you'll likely do. One key thing to expect is volatility. Don't let it burn you.