Algo Trading: when did markets start outperforming my algorithm?
Algo Trading: when did markets start outperforming my algorithm?
This is the fourth article of a series I’ve been writing. If interested you can start here.
My simple, unpolished and naive scalping algorithm outperforms the market in 2016 but not in 2019.

As I wrote in two previous articles my simple, unpolished, naive, intraday scalping algorithm outperforms the market while backtesting some symbols with data from 2016.
In my latest article I do a backtest for an intraday scalping algorithm for symbols AAPL, V and FTEC. The results were quite promising with 2016 data, and depressing for 2019 data:
These are some results for 2016, notice my algorith perform 3x over APPL:
AAPL - market change %: 1.099
AAPL - wallet change %: 1.302
AAPL - num_transactions: 454
...
V - market change %: 1.032
V - wallet change %: 1.049
V - num_transactions: 290
...
FTEC - market change %: 1.145
FTEC - wallet change %: 1.298
FTEC - num_transactions: 390
You can use the same download_data.py script we made in this article. But now we are going to add all symbols for the S&P 500.
Create a file named symbols_sp500.py with the following content (this list might be a little outdated, since I generated it on the last months of 2019, but for this test it will suffice.):
Then we can import this module into our download_data.py.
Yes, I’m greedy and I’m preparing to also study the evolution of the market during those 3 years.
I also added a new progress bar and nice descriptions of the symbol and date being downloaded ( tqdm is pretty great!).
If you want, stick to downloading only 2016 data by adjusting the time range.
Downloading 3 years (~1050 days) worth of data take a little while. As soon as a symbol finishes downloading I’ll start coding the next part.
Turns out that downloading the bigger batch of data had its complications. Polygon didn’t serve some of the data (probably it doesn’t exist for the dates I requested). I also ran into other timeout issues, and more. I might get into the workarounds in future articles.
All in all, I downloaded more have a million days worth of data — around 11Gb of data. 500 stocks x 252 days a year x 4… I downloaded S&P 500 symbols and then some other group of stocks that I happen to like.
The analysis of some of this data will take some time.
I did however run an improved version over the similar stocks, and produced this nice table:
symbol from to market_growth wallet_growth
AAPL 2016-01-04 2016-12-30 1.098928 1.302331
AAPL 2017-01-03 2018-01-02 1.482470 1.359844
AAPL 2018-01-03 2019-01-03 0.827907 0.746127
AAPL 2019-01-04 2019-12-31 1.980301 1.348624
FTEC 2016-01-04 2016-12-30 1.145206 1.298188
FTEC 2017-01-03 2018-01-02 1.363563 1.274163
FTEC 2018-01-03 2019-01-03 0.915089 0.905536
FTEC 2019-01-04 2019-12-31 1.480899 1.210752
V 2016-01-04 2016-12-30 1.031672 1.048853
V 2017-01-03 2018-01-02 1.440377 1.341969
V 2018-01-03 2019-01-03 1.108143 1.082954
V 2019-01-04 2019-12-31 1.405911 1.340098
MA 2016-01-04 2016-12-30 1.088065 1.248133
MA 2017-01-03 2018-01-02 1.448332 1.456326
MA 2018-01-03 2019-01-03 1.178715 1.226534
MA 2019-01-04 2019-12-31 1.573047 1.413504
Plotting those numbers one can see those 4 stocks moving in a similar fashion for the 4 years.
Taking the mean, one can see that the algorith outperformed the market from 2016 to 2018. Including 2019, though, makes the algorith underperform.
Stay tuned for updates!