Getting out of the stock market during periods of volatility may feel safer. But the math suggests investors often sacrifice big returns.