In this Jupyter Notebook, I investigate how the various sectors of the US economy performed on the stock market in 2022 by creating a market cap-weighted index of each sector, and plotting its returns over the year.
The stocks are classified into sectors according to the Global Industry Classification Standard (GICS):
- Communication Services
- Consumer Discretionary
- Consumer Staples
- Energy
- Financials
- Healthcare
- Industrials
- Information Technology
- Materials
- Real Estate
- Utilities
The analysis was done in a Jupyter Notebook. This analysis can be viewed by opening the notebook, but to run it again, you'll need
- a dev environment that can run Jupyter Notebooks (e.g. through a VS Code extension, or by installing conda
- the following libraries:
yfinance
- a library that enables downloading of price data from Yahoo! Financenumpy
pandas
matplotlib
The sixth code block involves downloading the price data of about 5000 stocks, and may therefore take a while.
(the y-axis shows the return, and the x-axis shows the trading day in 2022 (there were 251 trading days in total))
The Energy sector gained a whooping 60%! This was largely the result of the war in Ukraine pushing up oil prices to record highs. The Information Technology sector, on the other hand, declined about 30%. Analysts attribute this to high interest rates, high inflation, and a generally uncertain business environment.