If you've been feeling discouraged about the stock market over the past year, you're not alone.

We've experienced a roller coaster of ups and downs, and while prices have rebounded slightly in recent weeks, many experts are still warning about a potential recession later this year -- which could take a toll on the market.

However, if history shows us anything, it's that there's one great reason to be optimistic about the future of the stock market.

Bull silhouette against an orange sky.

Image source: Getty Images.

A bull market is coming

Nobody knows what will happen with the stock market over the coming weeks or months. There is still a chance we could face a recession, and if that happens, another bear market could be on the horizon.

The good news, though, is that every single bear market in history has eventually given way to a bull market. In fact, not only has the market recovered from every downturn, but it's gone on to earn positive total returns.

^SPX Chart

^SPX data by YCharts

Research and analytics firm Crestmont Research examined the rolling 20-year returns of the S&P 500 since 1900. It found that in all 103 years analyzed (from 1919 to 2022), the S&P 500 earned positive total returns.

In other words, if you had invested in an S&P 500 index fund at any point since 1900 and held it for 20 years, you would have made money -- and that's despite experiencing some of the worst economic downturns in history during that time.

Is it safe to invest right now?

It can be tough to stay optimistic when the market is shaky, but a long-term outlook can make periods of volatility easier to tolerate. And while it may not seem like it, now could be a fantastic time to invest.

When the market is in a slump, stock prices are lower. That makes right now a smart time to load up on quality stocks at a discount. Then, when the market inevitably bounces back, you stand to make a lot of money.

Even if stocks have further to fall, investing now is still a smart move. Timing the market effectively is next to impossible, and if you're waiting for the perfect time to buy, you could miss out on potentially lucrative returns.

For example, say you had invested in an S&P 500 index fund in January 2009, just before the market bottomed out during the Great Recession. That may have seemed like the worst possible time to buy, as your investments would have immediately lost value.

^SPX Chart

^SPX data by YCharts

But within five years, you would have earned returns of around 105%, more than doubling your money. If you had waited until, say, January 2010 to invest (when the market was already in recovery mode), you would have only earned returns of around 66% by 2014.

The future is bright

Again, the short-term performance of the market may be uncertain, and there is a chance that things could get worse before they get better.

However, the market has a perfect track record when it comes to recovering from downturns, and investing remains one of the easiest and most effective ways to build wealth. By investing during the slumps and sticking it out until the recovery period, you could make a lot of money.