Great illustration of history function and statistical library.
Yet... One has to be careful when it comes to claiming a win over buy and hold. Quantopian S&P 500 benchmark does not re-invest dividends, thus over time almost any algorithm that occasionally sets the holding to 100% of SPY etf will beat the benchmark. This is the reason I have nudged the development team on several occasions to include and option for S&P 500 with re-invested dividends as a benchmark option.
Say that all algorithm does is keep the investment at 100% SPY. That means every few months a few new etf stocks will be bought, while the benchmark will be 5%, 10%, ... 50% in cash in 10 years or so. Towards the end the higher exposure to the index and zero return on dividend cash will tilt the result in algorithm's favor. That is not to say the algorithm does not make money, but that the test confirming it is invalid.