It’s been a while since I’ve published anything, but given that this website is front and center on my resume, I figured it’d be a good idea to at least give people something to read that isn’t a year old.
One of the projects I had been working on this summer was to visualize a handful of investing trading strategies. Earlier this year, I finally was able to get back into the stock market after a few years off (read: unemployment). This has made me extraordinarily happy. I had done a little investing between 1999-2003 then hadn’t done any at all until early 2016 when I discovered the beauty of fractional shares. Of course in 2017, my life crashed around me, and I had to sell off everything I owned to survive. However, I jumped right back in as soon as I could the first trading day of 2020.
Around Memorial Day I started looking at different ways of visualizing stocks watching YouTube videos and reading Medium posts. I started off rather simply using basic line graphs, then looking at different moving averages and moving into incorporating a backtesting library to help show buy and sell signals using different trading strategies.
The first of these strategies is the Simple Moving Average Crossover (SMAC) Strategy. This is one of the simpler approaches to trading and incorporates two moving averages (MA) of a company’s stock price over time: one long-term and one short-term. Using this strategy a buy signal occurs when the shorter term MA crosses above the longer term. A sell signal occurs when the opposite happens: the shorter term MA crosses below the longer term MA. In my examples below I use the 20-day MA (one month or four weeks) as the short term and 50-day MA (ten weeks) as the long term. To illustrate this let’s look at one of my favorite companies, Advanced Micro Devices (AMD).
The above illustration is done using Matplotlib with YahooQuery and FastQuant in Python. It shows the buy and sell signals for AMD stock if you invested $10,000 starting in January of 2019. As you can see the 20-day MA crosses over the 50-day MA near the end of January 2019, January 28th to be exact at around $20 per share. Several months later, the 20-day MA crosses under the 50-day MA (June 3, 2019) creating a sell signal. This continues over time until you see a sell signal was just flashed on October 1, 2020. As you can see from Figure 1, had you invested $10,000 (with no fractional shares) on January 28, 2019, you would now have $27,520.68 using the SMAC trading approach. That is a profit of $17,520.68 through October 1, 2020!
Unfortunately not every stock has the same outcome using the SMAC Strategy as seen below.
One of the disadvantages of the SMAC strategy occurs when you see something like Textron’s run in the last 20 months. In 2019 the stock swung back and forth several times generating multiple buy and sell signals, most of which generated losses for our theoretical portfolio. Then there was the huge sell-off that affected the majority of stocks during the short-term bull market in March. If you had invested $10,000 in January of 2019, you would now be down nearly half of your original investment.
So is the SMAC strategy the best one to use? Probably not, but it’s certainly the easiest to understand. You can also play around with different values of your moving averages: 10 vs 50, 30 vs 90, and on and on. I picked 20 and 50 just as an easy example. You could also do moving averages based on weekly moving averages or longer.