Creating a data strategy for sustainable investing via an interactive dashboard using Plotly and Dash

Sustainable investing is a fairly recent concept. With rising global temperatures, disappearing rainforests and an increase in carbon emissions, the past decade or so has seen several companies place greater emphasis on protecting the environment. The pressure to reach carbon neutrality has caused thousands of corporations to take extra steps in limiting practices that could potentially harm the environment.

At the same time, investors have also been scrutinizing companies for their practices using a criteria called environmental, social and governance (ESG). These represent a set of standards investors consider while buying financial assets such as mutual funds, ETFs (exchange traded funds) etc., whereby putting further pressure on businesses to act ethically in the way they operate.

ESG extends the notions of social and governance responsibility to the environment aspect. These three core components can be broken down as such:

  • Environmental: A focus on the fund’s or company’s awareness in relation to nature and the climate
  • Social: A focus on a company’s relation with it’s employees, customers, vendors, suppliers and demographics
  • Governance: A focus on how the company is run with an emphasis on leadership, audits, shareholder rights, and wages

No longer are returns and dividends the only goals of companies as the investing landscape turns towards more ethical considerations. In addition to climate, moral and social implications, investors are also concerned about possible financial risks posed by companies not adhering to ESG standards. For example, a company which adopts poor ESG practices would likely drive away potential investors driving it’s value down whereby posing further red flags for other investors.

In light of these considerations, several financial institutions such as Blackrock, Fidelity and Vanguard are now providing financial products such as ETFs which comply with ESG criteria. Furthermore, financial services companies such as Morningstar, Bloomberg, Marketwatch and Thomson Reuters analyze the practices of publicly traded companies and provide ratings based on their ESG practices. Analysts from these same companies are known to provide ratings for stocks. Hence, ESG ratings from these institutions would also hold great weight in terms of stock or fund analysis.

Below, a strategy for selecting sustainable funds using an interactive dashboard is discussed, taking into consideration crucial variables and metrics. We also dive into some of the technical details involved in creating the dashboard using Python and it’s deployment as a web app.

The problem statement

As discussed above, it is becoming increasingly important to judge companies based on the ethics of their practices in addition to their potential to generate the greatest profit for their investors. Keeping this in mind, the goal of this project was to find a balance between ESG metrics and annual return while selecting funds. Here are some of the key questions that helped in finding this balance:

  • How can we create a strategy for potential investors to pick lucrative funds while keeping ESG considerations in mind?
  • What is the relation between sustainability and annual returns?
  • What are the optimal responsible investment picks?
  • What are the key features that determine whether a fund is sustainable or not?

Data and solution

In order to answer these questions, we explored a dataset provided by Morningstar containing information regarding over 6000 funds from various financial institutions. The data contained 30 features such as equity style, credit rating, annualized returns, ESG ratings, fossil fuel usage, etc., and was made available on the RMDS website.

This data was analyzed in order to explore the relationships across some of the key variables which helped in formulating a strategy for selecting the most sustainable funds. Two of the main criteria used for determining the best funds were:

  • ESG criteria
  • Highest 1-year rate of return

Fund selection pipeline

Some of the key metrics and criteria used to perform some initial filtering were:

  • Sustainability rating of 5
  • Funds claimed as ‘Sustainable Investment – ESG Fund’
  • Credit rating of A/AA/AAA
  • No animal testing
  • Excluded Morningstar categories that had a greater than 6% association with fossil fuels

Next, the funds were further filtered using performance based metrics:

  • Selected equity styles with median 1-year return of greater than 30%
  • Excluded Morningstar categories with median 1-year return less than 30%

The filtering process as well as some exploratory analysis of the filtered funds is shown in the snapshot of the dashboard below. The actual interactive dashboard was deployed using a Dash app.

Key findings

Some of the key highlights of the dashboard, analytical findings of the selection process as well as the characteristics of the filtered funds are summarized below.

  • Equity styles and Morningstar categories
    • Most of the funds that meet the ESG criteria and have ‘A’ credit ratings are large cap equities
    • The most frequent Morningstar category out of the selected funds is the US Equity Large Cap Blend
    • Target Date funds had a 6.183% association with fossil fuels
    • Global Equity Large Cap funds had the greatest association with alcohol with an average value of 2.78%
    • Out of the selected optimal funds, Fidelity was the most prevalent financial institution
  • ESG and Sustainability Rating relation
    • The average Social and Environmental scores are slightly higher for the original set of funds than the selected ones
    • The average Governance score is higher for the selected funds
    • On average, the Environmental score for rating 5 is lower than rating 1. Average Governance score for rating 5 is higher than that of 1.
  • 1-Year return
    • Median return for the selected funds is higher than median return for the original set of funds

Python code using Plotly and Dash

Thanks to this project, I was able to learn two new data visualization tools in the form of Plotly and Dash.

Plotly is one of the most powerful Python libraries for creating interactive charts and dashboards. However, it’s real power is revealed when used along with the Dash library which is an open-source framework for adding greater functionality to interactive visualizations and providing the capability to be deployed as a web app.

Albeit having a steep learning curve, both these tools have plenty of guides and examples online which helped me put together the dashboard shown above from scratch in a short period of time.

The code for the dashboard as well as the documentation and outputs can be found in this repository, with the top-level Python file being ‘RMDS_Sustainable_Investing_App.py’. Some dependencies are contained in the file ‘supporting_functions.py’.

Most of the interactive plots were created using the graph_objects and subplots modules of Plotly. Below is a snippet of code for one of the subplots. The make_subplots function allows the creation of a grid-like template for charts, in this case having one row and four columns. It also sets the theme for each plot in the template, using the variable ‘specs’, as well as legend, via the variable ‘subplot_titles’.

Another key function used as part of the aforementioned subplot was ‘add_trace’, which in this case specified a pie chart and it’s contents. Finally, the ‘update_trace’ function was used to add the percentage value to the sustainability rating for each piece of the pie.

Deploying the dashboard using the Dash library was rather simple. However, there are much more complex and involved examples of Dash apps. Below is a snippet of the code used for incorporating Dash functionality.

The first line creates an instance of a Dash app while the next few lines incorporate the various subplots into the app. On the last line, there is code to run the dashboard on a browser.

App deployment using pythonanywhere.com

One of the best ways to view a dashboard is via a web app which can be easily accessed using a link, as opposed to having to run a piece of code which requires pre-installed software and other dependencies. Having a user-friendly web app allows it to be shared with a larger audience.

Fortunately, there are several options available for deploying Dash apps on a web server. A great tutorial for getting started with the deployment of Dash apps be found in this article using pythonanywhere which is not only a web hosting service but also an integrated development environment.

Pythonanywhere is easy to use and allows the deployment of a limited number of web apps for free. One obstacle I did encounter during the deployment was a conflict regarding module version numbers. The version for the dash library in the web development environment had to be updated to the latest one in order to get the app to work properly.

Libraries can be installed or updated using the Ipython or Bash interpreters available on the platform. A snapshot of the Console section with an active Ipython session is shown below.

Another important file used for web deployment is the WSGI configuration file with the contents shown below. A few important edits had to be made in this file in order to successfully deploy the app:

  • Comment out the original app import statement on line 16
  • Add a line that imports the Dash app from the main app file (RMDS_Sustainable_Investing_App.py) on line 17
  • Run the imported Dash app on the server on line 18

These were some of the key things to keep in mind while deploying the Dash app on pythonanywhere. Other than these, the instructions I have linked above should contain most of the required steps.

That brings us to the end of this post. The dashboard can definitely be improved in several ways such as exploring more open-source data or adding drop-down options to the dashboard. However, the goal for this project was to create something simple, user-friendly and understandable.

Hope you enjoyed this post. Let me know in the comments if you have used Plotly or Dash before and what some of the most complex or beautiful charts you created are.