Analyzing Tech Layoffs and Stock Market Responses with ChatGPT and Amazon SageMaker Studio Lab

Disclaimer: I am a software person and not a finance or investment expert. This post is for informational purposes only and should not be relied upon as investment advice.
In this short post, we will explore the relationship/impact of tech layoffs and the stock prices of the respective companies. We will look at each company’s stock price 90, 60, 30, and 5 day-moving average before and after the layoffs were announced.
TechCrunch published a comprehensive list of tech layoffs a couple of days ago. Moments before reading the article, I was tuned to Bloomberg TV where I get latest on macro economic trends. Inspired by stock and quarterly earnings announcements, I got the idea to check the stock prices of the companies in the article from TechCrunch.
Before ChatGPT, I would have needed to write a web scraper in Python to extract the information required for the analyses. This would have taken a number of days, if I had to build this on my own. Thanks to ChatGPT, I simply pasted the article to ChatGPT and added the prompt:
extract the company name, date layoff was announced and add the stock symbol as a markdown table from the post below. add to the table layoff percentage and the number of employees laid off: <TechCrunch Article>
ChatGPT returned tabular data in markdown containing the information needed:
| Company | Date Announced | Stock Symbol | Layoff % | # of Employees Laid Off |
|------------------|----------------|--------------|----------|-------------------------|
| Neato Robotics | May 1, 2023 | N/A | N/A | 100 |
| Clubhouse | Apr 27, 2023 | N/A | 50% | N/A |
| Dropbox | Apr 27, 2023 | DBX | 16% | 500 |
| ... | ... | ... | ... | ... |
Next, I asked ChatGPT to write Python code to get the 90, 60, 30, and 5 day-moving average before and after the layoffs were announced and enrich with the table with this information. ChatGPT returned the Python code snippet:
import yfinance as yf
import pandas as pd
# create a DataFrame of companies with stock symbol and layoff information
companies = pd.DataFrame({
'Company': ['Company A', 'Company B', 'Company C'],
'Stock Symbol': ['A', 'B', ''],
'Layoff Date': ['2022-03-15', '2022-04-01', '2022-05-01'],
'Layoff Percentage': [10, 5, 20],
'Number of Employees Laid Off': [100, 50, 200]
})
# define a function to retrieve stock price data and calculate moving averages
def get_stock_data(symbol, start_date, end_date, layoff_date):
stock_data = yf.download(symbol, start_date, end_date)
stock_data['90 Day MA'] = stock_data['Close'].rolling(window=90).mean()
stock_data['60 Day MA'] = stock_data['Close'].rolling(window=60).mean()
stock_data['30 Day MA'] = stock_data['Close'].rolling(window=30).mean()
stock_data['5 Day MA'] = stock_data['Close'].rolling(window=5).mean()
before_layoff = stock_data.loc[:layoff_date]
after_layoff = stock_data.loc[layoff_date:]
return before_layoff, after_layoff
# retrieve stock price data and moving averages for companies with stock symbol
for i, row in companies.iterrows():
if row['Stock Symbol'] != '':
symbol = row['Stock Symbol']
start_date = row['Layoff Date'] - pd.Timedelta(days=365)
end_date = row['Layoff Date'] + pd.Timedelta(days=365)
layoff_date = row['Layoff Date']
before_layoff, after_layoff = get_stock_data(symbol, start_date, end_date, layoff_date)
companies.at[i, '90 Day MA Before Layoff'] = before_layoff['90 Day MA'].iloc[-1]
companies.at[i, '60 Day MA Before Layoff'] = before_layoff['60 Day MA'].iloc[-1]
companies.at[i, '30 Day MA Before Layoff'] = before_layoff['30 Day MA'].iloc[-1]
companies.at[i, '5 Day MA Before Layoff'] = before_layoff['5 Day MA'].iloc[-1]
companies.at[i, '90 Day MA After Layoff'] = after_layoff['90 Day MA'].iloc[-1]
companies.at[i, '60 Day MA After Layoff'] = after_layoff['60 Day MA'].iloc[-1]
companies.at[i, '30 Day MA After Layoff'] = after_layoff['30 Day MA'].iloc[-1]
companies.at[i, '5 Day MA After Layoff'] = after_layoff['5 Day MA'].iloc[-1]
# print the enriched table
print(companies)
Now, with the code snippet in place, all I had to do was to put everything together for my analyses. Enter Amazon SageMaker Studio Lab.
My raw data is now enriched with 5, 30, 60 and 90 day moving averages before and after the layoffs were announced using the yFinance
API, we can go ahead to explore and visualize our data.
Data Visualization

In the visualizations above, I compared the 5-day moving average stock price for the companies before the layoffs were announced to 5-day moving average after the layoffs were announced were announced and repeated the same for 30, 60 and 90 day moving averages. In the 5-day MA comparison, 6 out of the 13 companies analyzed gained at least 2% in their share price, with Microsoft leading the pack with ~10% increase in share price. This gain begins to even out when we looked at the 30, 60, and 90 day moving average comparisons.

Over the 30-day moving average, we see the number of companies with increased stock prices go from 6 to 9 and Salesforce jumping from around 4% to ~10.1% to overtake Microsoft.

Furthermore, the 90-day moving average shows a similar picture to the 30-day moving average with few adjustments. We can see almost a percentage drop in the price of Accenture. On the other hand, we see Disney having a slight gain.
All this is good but what does the data look like? Below is a table showing the changes in real values.

Conclusion
This is not a technical analyses, and you would NEED to speak with your financial advisor to make investment decisions. But data easily tells us that there is relationship between layoffs and short to mid-term gains on the stock market. This quick analysis was made possible with the power of LLMs, i.e. ChatGPT as my coding assistant, and Amazon SageMaker Studio Lab, a free machine learning development environment.