Global Terrorism and its Effect on the U.S. Stock Market
The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.
The Shadow of Terrorism
It's hard to overstate the impact terrorism, in its many iterations, has had on American geopolitics and the world in recent decades. If you look, you can find some sort of attack happening almost every day, all over the world, and a quick check of terrorism threat levels shows that the world is on constant alert for attacks. Furthermore, on a more personal level, my parents live in the south of France, a target of multiple high-profile terrorist attacks in the past few years, and I was in fact only a handful of blocks away from the July 14, 2016 attack in Nice orchestrated by ISIS.
Due to the above, it's difficult not to be at the very least peripherally aware of terrorism and its affects on the world. However, when terrorism is discussed, most often the ramifications tend to be cast in sociopolitical terms. Recently, I began to wonder whether terrorism had effects that reached beyond that scope and into the economy -- more specifically, I began to wonder how any given individual terrorism event might affect the U.S. stock market. I knew that the attacks on 9/11 closed the New York Stock Exchange for nearly a week, so I knew that attacks of a large enough magnitude would have an effect on financial markets. The question, however, was whether an average terrorist attack impacted the stock market, and if so, whether that movement was affected by type of attack and/or the region in which the attack took place.
The Data
To answer the above question, I used the most comprehensive dataset on terrorism events around the world that I could find, sourced from the Global Terrorism Database (GTD). The GTD is maintained by the University of Maryland with support from the U.S. Department of State and the U.S. Department of Homeland Security, and covers the years 1970 to 2017, with the exception of 1993. It contains a multitude of information about any given event, including exact location, target type, perpetrator, and casualty numbers. The dataset can be found here.
The GTD data was reduced to cover the period between 1990 and 2017, in order to line up with the VIX Volatility Index data (data from which begins in 1990), which acts as a measure of uncertainty and fear in the U.S. stock market. Finally, the dataset was combined with S&P 500 Index data, which I used as a representative of the overall stock market. Both sets of financial data were sourced from Yahoo Finance.
The App and Analysis
After cleaning my data in R, I used the Shiny package to visualize my data along a number of metrics and provide a visual answer to my question fo whether terrorist attacks affect the stock market. The app itself contains many features, and I encourage those interested to take a look at it here and poke around a bit. However, the the app can be broken down into three major sections: a map of events, a sanity check analysis of whether the VIX Volatility Index actually affects the S&P 500, and an analysis of how individual terrorist attacks affect the S&P 500.
The Map
Because the data contained almost 133,000 attacks from around the globe, I felt it was important for the user to gain a visual appreciation for the sheer scope of terrorism. Therefore, I used the Leaflet package to plot all the attacks on a world map. Because each individual attack marker had a somewhat low opacity, locations with a higher frequency of attack showed up darker than those with a lower attack frequency. I also enabled the user to select for the type of attack on the map as well as the year range, allowing for greater granularity in the map visualization. As can be seen below, the Middle East is (unsurprisingly) a hotbed of terrorist activity in recent years; however, I was taken aback by the quantity of attacks in Southeast Asia, given the relative lack of media coverage of attacks in that area.
I also believed some exploratory data analysis would be beneficial for the user, so I included column charts to indicate the total number of attacks, as well as the same by region and by target type. I provided a similar visualization for casualties (split by the number of wounded and the number of killed). Furthermore, I provided similar metrics in a year-over-year format, allowing the user to see changes in attack patterns over the past thirty years. Unsurprisingly, the post 9/11 years saw a surge in terrorism, particularly in the Middle East. An analysis of the distribution of attacks by type show that the surge in Middle Eastern terrorism coincides with a marked uptick in bombings and explosions, which in turn is reflected by an increase in the number of casualties (both killed and wounded).
VIX and the S&P 500
I also wanted to show that my initial hunch wasn't totally off base -- if volatility and fear did not adversely affect the stock market, I would be haring off down the wrong path and wouldn't arrive at any meaningful conclusions about how terrorism affected the stock market. Therefore, I plotted a time series of the VIX and S&P indices, as well as created a scatterplot of each index's daily change. The conclusion is both visually and mathematically inescapable - there is a clear negative association between the two indices. In other words, when VIX goes up, there is a tendency of the S&P to decrease, and vice versa.
Terrorism and the S&P 500
After visualizing the terrorist attacks and looking at how the VIX Volatility Index related to the S&P 500, I figured I'd take a look into how terrorist attacks affected the VIX index. This is where I hit the major surprise of my project. No matter which way I looked at the data, no matter what metric I used to restrict the attacks, it appeared that terrorism did not meaningfully affect the VIX on the day on which the attack occurred. In fact, VIX had a tendency to go down (indicated a lower level of fear and uncertainty), on average, on days where there was an attack.
That didn't seem right to me, on an intuitive level, so I went back into my code and included a visual representation of the S&P 500's average movement on days where there was an attack. Consistent with the above relationship between VIX and the S&P, the S&P actually exhibited a tendency (albeit a very small one) to increase on days when a terrorist attack happened. As can be seen from the below screenshots, this pattern holds true on average no matter what metric you look at. I was forced to conclude that terrorist attacks are simply not correlated with market decreases, despite what my intuition told me.
Conclusions
All was not lost, however. Finding a non-existent correlation can be just as helpful as finding a correlation itself. The short, pithy takeaway from my analysis is that you shouldn't panic about moving your money if there's a terrorist attack, regardless of where the attack took place or what type of attack it was. On average, any given attack is unlikely to move the market, and moving one's position early in response to a likely non-issue is both a waste of resources and potentially financially damaging.
However, it is important to note that my analysis only holds true for days in which there was a terrorist attack and the market remained open to register a response. Sufficiently large attacks, such as the September 11th attacks, can close the market, and in such a case it is possible, even likely, that the market will open significantly lower than when it was forced to close. That is, in fact, where I'd like to take this project in the future -- I'd like to restrict my dataset to attacks that resulted in the market closing for an extended period of time, and seeing how that affects the conclusion.
Thank You!
Thank you for taking the time to read about my app and analysis! I really enjoyed practicing my coding skills as well as the new insights I gained into the robustness of the U.S. stock market. Additionally, I always welcome feedback or questions on the app, so please feel free to reach out to me on my LinkedIn or to check out my code hosted on my GitHub.