This analysis is only looking at the price of the S&P 500, not the total return. An investor that sits out half of the year will miss out on about half of the dividends paid, which are always positive.
Another consideration is taxes. The short-term gains produced by selling after 6 months are taxed at normal income rates (or slightly higher), as is the interest from the "risk free" interest-paying investment held the other 6 months. Long-term capital gains and dividends are taxed at favorable rates.
EDIT: Here is a graph highlighting how important including dividends is: https://i.imgur.com/YZSq6K3.png
Another consideration is taxes. The short-term gains produced by selling after 6 months are taxed at normal income rates (or slightly higher), as is the interest from the "risk free" interest-paying investment held the other 6 months. Long-term capital gains and dividends are taxed at favorable rates.