War. What is it good for? The stock market, it turns out.

The big picture: Don't pay too much attention to short-term stock-market gyrations. When you take a step back, it looks like war tends to be good — not bad — for American stocks.

Driving the news: U.S. stocks sold off when faced with the specter of possible war with Iran. War kills hundreds of thousands of people every year, which is good for no one. Stocks understandably fell after Iraq invaded Kuwait in 1990, or when terrorists attacked the U.S. on September 11, 2001.

Yesterday, as war fears abated, stocks hit new record highs.

By the numbers:

The Dow rose 43% during World War I, despite the destruction of much of Europe, and it rose 50% during World War II, which was bloodier still.

43% during World War I, despite the destruction of much of Europe, and it rose 50% during World War II, which was bloodier still. Defense spending has accounted for more than 3% of U.S. economic activity in every year since World War II. Think of it as a consistent and predictable fiscal stimulus.

has accounted for more than 3% of U.S. economic activity in every year since World War II. Think of it as a consistent and predictable fiscal stimulus. The 2020 defense budget stands at $738 billion, or about 3.6% of GDP. That's roughly the same as the entire economy of Switzerland, or the $787 billion spent on the 2009 American Recovery and Reinvestment Act, aka the Obama economic stimulus bill.

Determining the effect of war on the stock market isn't easy, since the U.S. is almost always at war. Since the end of World War II, per Eurasia Group, the U.S. has been at war in every year bar 1949 and 1985.

But if you look at the wars that involved the most U.S. troops — the Korean War and Vietnam — the stock market rose 60% and 43%, respectively.

that involved the most U.S. troops — the Korean War and Vietnam — the stock market rose 60% and 43%, respectively. When the U.S. invaded Iraq in 2003, stocks rose 32% in the subsequent 10 months.

It's not just share prices, either. Mark Armbruster, president of Armbruster Capital Management, ran the numbers for the 1926-2013 time period and determined not only that large-cap and small-cap stocks outperform during wartime, but that they do so with lower volatility.

In other words: Risk goes down while returns go up.

How it works: If Iran were to bring down the internet in North America, or set off a nuclear device in Manhattan, there would certainly be immediate and significant negative repercussions for stocks. But it's hard to price in tail risks.

The base-case expectation with respect to any upcoming conflict with Iran is the same as with all other wars since 1945: That the war will not take place on U.S. soil.

The bottom line: Iran is not a significant part of global trade. The only way that U.S. companies can make money from Iran is by selling material for use in a war there. The bigger any war, the more money they can make.

Editor's note: This story has been updated to add context about the toll of war.