Algorithmic Trading at First Glance
What is algorithmic trading? Is it practical? How significant is algorithmic trading? What if we told you around 65% of trades in the stock market are made under the influence of algorithmic trading? This statistic alone piqued the interest of our team as we took on an internship at Virginia Tech’s Qualcomm Thinkabit Lab. We formulated a plan to research the effectiveness of algorithmic trading in the stock market using simple moving averages to predict different trends of certain stocks. Using Google CoLab, we wrote a script in Python to get the 50-day moving averages as well as the 200-day moving averages of the inputted stock. When a short-term (50-day) SMA crosses above a long-term (200-day) SMA, it is identifying a bullish signal indicating a trader to buy. Conversely, when a short-term SMA crosses below the long-term SMA, it is identifying a bearish signal indicating a trader to sell. We then would backtest our method with the previous five years of the selected stock.
Figure 1. Intersection of 50 and 200-day SMA
As we continued to conduct more research we realized our algorithm was not as optimal as it could be. Perhaps a 49-day SMA with a 201-day SMA will work better than the original, so we started to experiment with the numbers and found that some SMA days are better than others, but it is still
highly ambiguous. A moving average that performs very well for one stock might not perform very well for another. We decided that it is best to allow the user to input the moving averages of their choice, and to not have one preset for both the short and long-term moving averages.Inputs and outputs of our program
The user first must call the “calc” method which will perform all of the calculations. Then, the user inputs an amount of money to invest, followed by a stock ticker. Finally, the user enters their desired strategy with the period for a short-term and long-term moving average. In the example in Figure 2, you would be testing $100 of Google stock with a 50 day short-term moving average and a 200 day long-term moving average.
Figure 2. Input of Code
The output displays your profit, based on the amount of money inputted earlier, annual percent returns, and your 5-year percent returns. The output in Figure 3 under “Via algorithm” displays these statistics from the algorithm with the moving averages you chose. “Via regular” displays the same statistics if you had just bought stock at the beginning of the period and sold it at the end. The difference is useful to see if we are beating the market and if so, by how much.
Figure 3. Output of Code
Challenges we faced
While going through the process of researching and writing code, we encountered numerous challenges. The most prominent among them stemmed from our novice proficiency in Python, which necessitated learning as we progressed. We found ourselves simultaneously researching the code we were writing and the topic it pertained to. However, we quickly grasped coding concepts, and this hurdle dissipated as we got deeper into the project.
Finding suitable algorithms was a trial-and-error process. Among the algorithms we explored were those based on mean reversion and exponential moving averages. We discovered that mean reversion does not align well with the modern market dynamics, as many stocks primarily show bullish or bearish tendencies, leading to inconsistent data and overlooking potential opportunities. While exponential moving averages seemed promising as an algorithmic approach, we deemed it unrealistic to synthesize an effective system due to its complex formula, our limited coding experience, and time constraints.
Conclusion
Although we ran into many restraints, we found equal success, if not more. Perhaps one of our greatest feats was learning a substantial amount of Python in only two weeks. We started from a novice level of Python to write a script that successfully ran a program that accomplished its purpose. This led us to our trial and error testing.
After testing on over 500 stocks, we found that an algorithm solely based on simple moving averages will underperform a bullish market. However, it will outperform a bearish market. As a result, our program could be used as a form of risk management on stocks that are highly volatile. Although the potential reward is lowered, so is the risk.
In the future, we hope to improve our program’s shortcomings. This could include the incorporation of AI to enhance the modern capabilities of our program, allowing for a more sophisticated model. We could also alter our strategies for high-frequency trading or further explore different algorithms.
If you’ve gotten this far in our blog, we invite you to experiment with our algorithmic trading program through our Github link here!
Who Are We?
We are John Voight, Christian Haddad, and Roman Steis, 2024 graduates of Yorktown High School in Arlington, VA. We have been interning at Virginia Tech’s Qualcomm Thinkabit Lab. With our future pursuits within engineering, finance, and mathematical economics, we sought out a project that would combine these topics.
With the help of the Thinkabit Lab, we were able to efficiently brainstorm, plan, and execute our project. With the resources provided, we had more than enough information to delve into the basics of Python and swiftly execute our plan. We hope that our program can serve as a baseline of innovation for someone who may be more experienced in Python and finance. We wanted our project to bring interest to algorithmic trading, as its modern uses have unlimited potential.
Connect with us
We would love to see improvements and feedback on our program, so feel free to reach out to us. Thank you for reading!
John Voight
LinkedIn johntvoight@icloud.com - johnvoight@vt.edu
Christian Hadad
LinkedIn christianwhaddad@gmail.com - chaddad8682@sdsu.edu
Roman Steis
LinkedIn romansteis21@gmail.com - rsteis@colgate.edu