Adding new metrics to the Python finance tracking dashboard and making it accessible via a Streamlit App

To provide some background and a recap, the idea behind the dashboard was to track financial indexes, economic indicators and COVID statistics on a consolidated platform. The goal was to help users/viewers/myself gauge market conditions using these analytics and look for areas of concern or opportunities for investment.

The first iteration of this dashboard was created back during the February/March timeframe when the market was going through a rather rough period following the euphoric highs of the previous months.

Fast forward to now and the market is going through yet another frothy period. The NASDAQ index currently sits at 16,067, roughly 3000 points higher than it’s value in March. There was a feeling that the market may stay flat over an extended period of time following the massive gains in 2020 but the last two months have indicated anything but. The tech sector in particular has seen impressive gains over the past few months.

Before we get into more details regarding the financial indicators that are pointing towards a potentially inflated market, let’s get the technicals of the dashboard out of the way.

There are now two methods for generating the dashboard:

  1. Using a Jupyter Notebook: The required code files are located in the home directory. This is the same location as before and the method for generating the dashboard is similar to the previous iteration of the code.
  2. Using the Streamlit App: The required code files are located in a nested directory called Dashboard_With_Streamlit_App within the home directory. This method uses a Python top-level file instead of a Jupyter Notebook. However, they can easily be modified/converted to the other format depending on the user’s preference.

Below is a snapshot of the latest iteration of the dashboard. Unfortunately, the code for the old version no longer exists due to certain web sources becoming obsolete.

Below are the new changes to the dashboard at a high-level:

  • Using an external Python file in addition to the main Jupyter Notebook in order to load in important functions
  • Created an App using Streamlit to view the dashboard on a browser using a link
  • Added three new metrics (these will be discussed later in the post):
    • Shiller PE Ratio
    • Buffet Indicator
    • FINRA Margin Debt
  • Reduced the amount of information for the VIX Volatility Index
  • Modified the interest rates chart to include values only for the current month while the rates are now being extracted from Treasury.gov instead of Ycharts. There were a couple of reasons for this:
    • Ycharts started prohibiting the retrieval of data using web-scraping
    • Treasury.gov is technically an official source for interest rates data making it more sustainable in the long term
  • Values for the major financial indexes such as NASDAQ and S&P500 are now being extracted using Python’s Yahoo Finance API, which has a small downside of greater computation time but provides a more reliable source
  • Added Bitcoin and Gold as new assets as part of the Major Indexes and Assets chart

Please refer to the aforementioned Github links for more details regarding the code and data sources. Now let’s dive into some of the key changes as well as the new metrics.

Streamlit App

One of my long-standing goals with regards to data analysis was to deploy an easy-to-use app which anyone could access using a link. This project provided me with the perfect opportunity to do so. The following link generates the aforementioned dashboard using Streamlit.

Another way to access the app is through the following Github directory. Simply click on the black ‘Open in Streamlit’ button in the description to view the app.

Here is an overview of the files used for the Streamlit app:

  • Finance_tracking_streamlit.py: Top-level Python script
  • helper_functions.py: Helper Python file containing essential functions
  • requirements.txt: Contains all the necessary libraries and corresponding versions required to run the app

For a quick tutorial on how to use the Streamlit framework using Python to deploy an app, see my article here which describes a simple example.

Shiller PE Ratio

We all know what the PE ratio of a stock means. It’s the stock price divided by the Earnings Per Share (EPS) and provides a reasonable way to value a company. Generally, a PE ratio of less than 30 is considered good while anything greater than 100, for example, would indicate an over-valued stock. It also depends on what the size of the company is as well as how fast the revenue is growing but that’s a topic for another time.

The Shiller PE Ratio is an alternate metric to the regular PE Ratio of the S&P500 companies. The regular PE takes into account the ratio of the companies’ earnings over the past 12 months. The Shiller PE, on the other hand, takes into account the earnings over the past 10 years whereby making it less susceptible to sudden fluctuations in earnings.

As importantly pointed out in this article by Gurufocus, the regular PE during the first quarter of 2009 was around 123 at a time when the entire stock market had crashed. This was largely caused by the significantly low earnings suffered by most companies. One would think that it would be a good time to buy stocks when the entire market has crashed but this high PE ratio would suggest otherwise.

At the same time, the Shiller PE was around 13 which provided a more accurate picture of the market conditions. Such a PE would indicate that the asset is grossly undervalued.

When we look at the Shiller PE ratio today, it is at it’s all time highest level at 41.3. It is substantially higher than what the value was during the euphoric times of fall 2008 as well as the pre-COVID months. This begs the question – are we in for a massive crash/correction in the near future?

Certain factors such as the low interest rates suggest not, but the next indicator on the list supports the notion of an over-extended market.

Buffet Indicator

The Buffet Indicator concept is much easier to grasp, at least from a mathematical perspective. It is the Total Market Cap divided by the U.S. GDP, then multiplied by 100.

Today, the total market cap is around $48 trillion, whereas the GDP is around $23 trillion putting the Buffet Indicator at an astounding 209.7%. Generally, anything greater than 119% is considered overvalued which makes the current market significantly frothy.

This further supports the notion that the market could potentially be overvalued at the moment. However, what we have seen over the past several months is that any sort of dip or correction is quickly swept up by willing investors. Whether it be the advent of new investors or investing making it’s way into the mainstream, this might well indicate a new normal for the market.

It also begs the question whether these historically reliable methods of predicting market downturns still hold in today’s world. Only time will tell, for now let’s look at the next new metric.

FINRA Margin Debt

This is yet another statistic aimed towards valuing the market but provides a more indirect view of the market conditions. It is the total debit balances in securities margin accounts.

Certain brokerages allow investors to borrow money from them in order to purchase more stocks. The amount of money borrowed is known as margin or leverage and the account needs to be authorized as a margin account by the brokerage before any transactions can take place.

Buying stocks on margin is potentially risky as one is essentially spending money they may or may not have, which is similar to spending money on one’s credit card. On many occasions, users buy stocks on margin without having that amount easily available in their checking account or other liquid assets.

The idea is that when the stock prices go up, the leverage amount could be duly paid back to the brokerage. However, if the stock price stays down over an extended period of time, one could be margin called by the brokerage in which case the individual might have to sell other stocks or assets in order to pay the money back if they can’t transfer enough cash to cover the loss, whereby making this a risky strategy.

Going back to the FINRA margin debt, the value today stands at around $935 billion which is the highest it has ever been. This causes a slight concern in the sense that if the market was to take a turn for the worse, a lot of people might be forced to quickly sell out of their investment holdings whereby further dragging the market down.

Furthermore, this high leverage value could also explain how so much money is currently in the market.

Why add Bitcoin and Gold as new assets?

We already know that gold is considered a great store of value. Over the years, the price of the precious metal has held up well while several top fund managers, including Ray Dalio, use the resource as a hedge against inflation.

Historically, the value of gold has been inversely related to the dollar. Therefore when inflation creeps in, the value of the dollar goes down which in turn increases the price of gold, making it the perfect alternative for an investment during this period.

Similar to gold, Bitcoin is considered to be a great hedge against inflation as many argue that the cryptocurrency is also a great store of value. The deflationary nature of the token further supports this notion as the amount of Bitcoin actively in circulation is limited, whereas something like the dollar (or Dogecoin) essentially has an unlimited supply and is therefore inflationary in nature.

For the same reason, a lot of people believe that Dogecoin might be a better alternative to Bitcoin as a possible currency in the future. Since both Bitcoin and gold are important assets in today’s financial world, they certainly deserved a place on the dashboard.

That brings us to the end of this article. Let me know in the comments what other financial metrics you would like to see on the dashboard or if there are any design changes that could potentially improve the visualizations. Also, let me know what you think about the current market conditions. Looking forward to the next iteration of the dashboard!