Over time, the markets tend to reflect the general movements of the economy and global trends. However, it isn’t always rational, and it can take time to catch up.

The S&P 500 (^GSPC +1.20%) plunged when the U.S. went to war with Iran, but even though the current ceasefire looks fragile, it’s back to hitting new highs. Let’s see why, whether it can continue, and what investors should do.

Ship on the ocean.

Image source: Getty Images.

Why the market is hitting highs

Investors tend to become fearful when there’s economic or geopolitical volatility, which makes a lot of sense. Even though these kinds of events don’t necessarily impact specific stocks immediately, people make decisions based on expectations, which also makes a lot of sense. A war involving the U.S. can be expected to affect business activity, even before oil prices are factored in. Defense stocks, for example, can soar on military action, even if the markets tumble.

Adding oil prices in is another level, and that’s what seems to have sent the markets down initially. Crude oil was trading at around $65 in February before the war was announced, and it hit a high of $113 before the ceasefire. Higher oil prices, pushed up by potentially lower supply, affect companies because they rely on oil in their operations. That trickles down to nearly every business, and it can lead to higher prices everywhere and, further down the line, higher inflation.

The news of a ceasefire, therefore, had a positive impact on the markets. And since the economy successfully managed through the initial stages of the war, that breeds confidence and boosts the markets, which is where we are today.

A long-term weighing machine

If the ceasefire holds, the market could keep rising. Over time, that’s what it tends to do. In the famous words of Benjamin Graham, who was Warren Buffett’s mentor, “In the short run, the market is a voting machine, but in the long run, it is a weighing machine.”

That usually refers to specific stocks, and it’s a mantra for long-term investing. Buying stocks based on hype without solid fundamentals can’t outperform stocks with real value over time. In this case, the point is that great companies will outlast short-term trends, even if the near-term consequences of global activity are real.

Should you invest in the market today?

The market has survived all kinds of wars and global disruptions and gone on to reach new highs, like it did this week. It has also crashed at various times and recovered. The S&P 500 lost about 8% of its value when the war started, and it’s already recovered all of those losses.

Could it fall again if the ceasefire doesn’t hold? Absolutely, and investors should be prepared for that situation. Some factors that will dictate what happens in the markets include:

Will the U.S. continue its blockade in the Strait of Hormuz?
Will the U.S. begin military action in Iran?
Will the Strait of Hormuz stay open despite military action?

It’s a complex and uncertain situation, which is what inspires fear. Retail investors who have money in the markets and panic, selling out for fear of further losses, will lose the opportunity to recoup their losses. Once the low-priced stock sale is done, there’s no going back.

Some investors try to time their trades to benefit from disruptions, which is risky, because you can’t know in advance how the market will react to news, and there are always black swan events that you can’t anticipate.

There are investors who have made millions from shorting investment markets, like famed investor Michael Burry, as chronicled in Michael Lewis’ book and subsequent movie, The Big Short. These are unusual and extraordinary moves, best left to professional money managers with hedging strategies.

How to prepare and succeed

Exchange-traded funds (ETFs) that track the broader market, like the Vanguard S&P 500 ETF (VOO +1.23%) and the State Street SPDR S&P 500 ETF Trust (SPY +1.22%) are excellent vehicles to benefit from market rises over time. In addition, having a diversified portfolio that includes stocks that do well in volatile markets can shield your portfolio and keep you calm.

A dividend-focused ETF can do some of that work for you, and the Schwab U.S. Dividend Equity ETF (SCHD +0.78%) is a popular choice that’s doing its hedging job and beating the market this year.

^SPX Chart

^SPX data by YCharts

Ultimately, the main thing is for investors to keep their money in the markets when they fall so that they can benefit from the recovery when they begin to rise and hit new highs.