Creating a dashboard using Python to track critical financial and economic indicators

If you like to dabble in stocks (like me), you are likely conscious about events of high volatility in the market which could lead to massive red days which could extend to even weeks or months. I call this FOMC – Fear of market crash.

Yes, I just invented this term. But the concern is real and many in the past have tried to predict such events with low success rates. One individual who accurately predicted the biggest crash of our lifetime, the 2008 housing market crash, was Dr. Michael Burry.

At the time, he was a hedge fund manager for Scion Capital, a company that he founded back in 2000. His customers made over $700 million after the former physician shorted mortgage-backed securities whereby essentially betting against the U.S. economy.

Two crucial trends that he spotted earlier than anyone else where:

  1. The massive amount of sub-prime mortgages during a time when the rate of housing purchases was on the rise.
  2. Rising adjustable housing interest rates.

The factors mentioned above are just a couple of the considerations when judging swings in the market. Also, simply a deterioration in economic factors doesn’t necessarily cause a crash. Generally, it acts as a fuel to a much bigger problem, such as a rise in sub-prime mortgages, trade war with China or a COVID pandemic.

Since I have a decent amount of investments in stocks, I thought it would be good to track some of the major economic and financial indicators on a user-friendly, quick and consolidated platform. So I tried my hand at creating a dashboard to track these different metrics.

You can find the Python code used to create the dashboard in the following Jupyter Notebook. Most of these metrics were scraped from various finance websites that update the values on a daily basis (some provide real-time values).

The scraping was done using the BeautifulSoup and requests Python libraries, following which the XML data had to be parsed and cleaned before performing any analysis. A good amount of text mining needed to be performed, mainly using regular expressions, in order to parse some of the XML data.

Only the VIX Volatility indicator was extracted using the yfinance Python library. The visualizations on the dashboard were mostly created using the matplotlib and seaborn libraries with a fair amount of timeseries analysis using the pandas and datetime libraries.

Now that we have covered some of the technical aspects of the code, let’s dive straight in and analyze each of the metrics on the dashboard.

Unemployment Rate

It is unlikely that a rise in the unemployment rate would be the primary factor in causing a market crash. Most of the time, it is the result of a deeper market phenomenon. However, it could serve as one of the early indicators that a more severe crash such as the last year’s COVID crash could be on the horizon.

The plot below shows the unemployment rates during the first few months of 2020 where it appeared to be at a steady 3.5% during Jan and Feb. However, as the COVID pandemic swept across the country in March, lockdowns were enforced, people were laid off, hiring freezes took effect and salary cuts occurred.

As a result, the unemployment rate started to rise in March reaching 4.4% and eventually peaking at 14.8% in April as the situation grew more severe. This rise during March could have served as an early indicator.

Inflation Rate

The inflation rate is a measure of the average increase in the prices of everyday consumer goods and services, and is based on the Consumer Price Index (CPI). These goods include, but are not limited to, utilities, food items and gas.

So any increase in this metric would mean consumer items becoming more expensive across the board, whereby decreasing people’s purchasing power. This in turn makes everyone cautious when it comes to spending and also prevents them from putting more money into the stock market. In fact, it propels people to take money out of the market as a precautionary measure.

This is exactly what occurred over the past two weeks. The massive surge in the prices of tech stocks, mostly in 2020, had caused uncertainty in the minds of investors who believed that the Federal Reserve may raise interest rates which could lead to high inflation rates, sending stocks crashing down from their all-time highs on Feb 12.

Since that date, the Dow Jones, S&P 500 and the tech-heavy Nasdaq indexes have dropped by 3.17%, 14.3% and 6.7% respectively.

U.S. Gross Domestic Product (GDP)

Contrary to the first two metrics, the GDP doesn’t affect the stock market. In fact, it’s the other way around. The GDP reflects the state of the economy, out of which the market is one of the indicators of consumer sentiment.

The GDP generally sees a certain amount of percentage growth from quarter to quarter. However, a declining market or other economic factors could bring the GDP down. A decrease over more than one quarter could also lead to a recession, which is the opposite of inflation.

U.S. Treasury Bond Yield Rates

This is where things get interesting. The Treasury Bond Yields are a bit more complex to understand but the stock market is often affected by movements in these rates.

To understand treasury rates, we need to first understand the Federal Fund rate. This rate is set by the Federal Reserve and they modify it in order to control inflation. When the inflation rate approaches a relatively high value, consumer as well as institutional spending is less leading to a slow economy. This also affects the stock market as people have less money to invest.

As a result, the Fed reduces the interest rates so that more money can flow into the economy and the market. On the other hand, when they raise rates, spending along with borrowing power goes down.

Modifying the Federal Fund rate only affects the short-term Treasury Bond Yields such as the 3-month treasury bond. The longer term yields such as the 10-year or 30-year treasuries generally have higher rates. This leads to a rising curve as shown on the dashboard.

Near-term rates differ from the long-term rates in the sense that they mature over a shorter period of time. In that case, a higher near-term rate becomes undesirable whereas a long-term rate could be readjusted over time.

However, an unnatural increase in near-term rates could be a cause for concern as it could invert the yield curve.

Historically, whenever the yield curve inverted, a market disruption followed. Therefore, most people recommend the yield curve as the best indicator of market stability.

Major Financial Indexes

We now get back to some less complicated factors. Stock market indexes are essentially collections of a large number of stocks. The S&P500, for example, consists of the 500 biggest publicly traded companies in the U.S. such as American Express, Chipotle and Home Depot while the Nasdaq mostly consists of technology stocks such as Roku, AMD and Tesla.

As the stock prices of these individual companies go up, the indexes also move up. Hence, the performance of these indexes provides a good general overview of the market conditions.

So it’s important to keep track of these indexes and look out for volatile activity based on some of the key factors discussed above.

VIX Volatility Index

This is one of the most important indicators of stock market volatility. The VIX trends up during times of highly volatile buying or selling. However, it’s a great indicator of an impending market crash since selloffs are generally more rapid and steep than upward trends.

Throughout history, the VIX has proven to be a good indicator of market crashes and has reflected downturns in all the major indexes. It showed spikes during the selloff events of 2001, 2008 and 2020.

During stable market activity, the VIX typically stays below a value of 20 whereas values of >30 could indicate tumultuous markets. During the 2008 crash, the VIX reached an unprecedented value of 79 while it touched 66 during the COVID crash last year.

Since the VIX is an after-effect of market volatility, it’s difficult to predict the lowest point of a crash using this metric. However, a rising VIX value could help in determining what action to take before the market hits the bottom.

COVID Cases

This factor is fairly self-explanatory. COVID directly affected the U.S. economy in 2020 causing a crash in March. The pandemic lead to a sharp increase in unemployment, reduced spending and several companies reporting massive losses or going out of business completely. All these factors played a major role in driving the stock market down.

Occurrences such as these are once-in-a-lifetime events and in most cases would have a severe impact on the economy. However, due to the global nature of these events and the widespread information available today, one could possibly anticipate upcoming volatility in the market and take action.

COVID Vaccinations

Finally, we get to the factor that would possibly bring the market and economy back to it’s feet. Vaccination rollouts have been expedited with over 2million doses being provided each day at the moment.

As of March 2, over 102million vaccine doses were distributed with 78million shots given to people. This rate is only going to increase in the next few months with the likes of Johnson&Johnson now able to start distribution after being approved by the FDA. They will join Pfizer and Moderna as the third company to start producing vaccinations in the U.S.

That’s a wrap on some of the critical economic indicators to look out for when judging volatility in the stock market. A few of these factors such as the COVID cases and vaccinations may no longer be meaningful metrics after 2021 but they will continue to be a crucial factor at least a few more months.

I hope you found this useful. The dashboard can be generated by running the Jupyter Notebook, providing the latest values for all the above metrics. Let me know in the comments what other factors you would like to see in there!