VOOZH about

URL: https://towardsdatascience.com/python-comparables-financial-data-package-ee8863fe7bb1/

⇱ Python Comparables Financial Data Package | Towards Data Science


Skip to content

Python Comparables Financial Data Package

Leveraging comprehensive comparables data provided by Aswath Damodaran

3 min read
👁 Image

Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details.


In his book on special situations investing, famous value investor Joel Greenblatt uses a great anecdote for stressing the merits of using comparables data to identify mispriced assets selling at bargain prices.

"[…] [T]he in-laws follow a very simple strategy. Whether they find a beautiful specimen of antique furniture […] or an impressionist painting, they ask themselves only one question before buying. Are there comparable pieces of furniture or paintings that have recently sold at auction […] at prices far above the potential purchase price?" – Joel Greenblatt [1]

As Greenblatt goes on to explain, this approach is also applicable in the stock markets, where benchmarking a company against its peers is of central importance. Only by looking at a company’s performance relative to that of similar firms can investors ascertain whether they are looking at a truly well-managed firm or simply a beneficiary of favorable overall market conditions (as Buffett said: "A rising tide floats all boats […]").

Thus, any investment decision should be informed by an analysis of comparable company data. An outstanding source of such comparable data is the website of NYU-professor Aswath Damodaran [2], the "Dean of Valuation". On his website, Damodaran provides detailed datasets on a large variety of metrics serving as important inputs to company valuation models. While these datasets can be looked up for free and downloaded in the form of CSV files, the only way to integrate these datasets into Python valuation models is via web-scraping the data.

To simplify this task of retrieving data from Damodaran’s website, I created a simple Python package. This library returns Damodaran’s datasets in the form of accessible pandas DataFrames and Series, making it easier to implement the data in custom Python scripts.

Installation and Import

The compdata package can be installed using a simple pip install command:

$ pip install compdata

Subsequently, investors can import the comp_data module to access the Market and Industry classes:

from compdata import comp_data

Market Class

To access general market data like historical returns or tax rates, the package allows investors to create an instance of the Market class. Subsequently, various class methods can be used to retrieve DataFrames containing the data.

market = comp_data.Market()
macro_df = market.get_macro()
print(macro_df)

The above code yields the following DataFrame:

👁 Output DataFrame
Output DataFrame

Industry Class

For more specific comparables data, investors can create an instance of the Industry class, passing the name of the respective industry as an argument. To identify the adequate data, the industry name must match one of the terms used by Damodaran, which are provided in industry_name_list. Much like with with the Market class, various methods can be employed to retrieve data.

print(comp_data.industry_name_list)
>> ['Aerospace/Defense', ..., 'Utility (Water)', 'Total Market', 'Total Market (without financials)]
aerospace = comp_data.Industry('Aerospace/Defense')
holdings = aerospace.get_holdings()
print(holdings)

The above script returns the following pandas Series:

👁 Output Series
Output Series

Concluding Remarks

I would like to point out that the compdata package is simply a minor contribution and addition to Damodaran’s work. All the credit for actually collecting and integrating the data clearly goes to Aswath Damodaran. The data provided by him should only be used in ways that he allows to do so.

The following is the link to the compdata GitHub repository:

julianmarx/compdata

Disclaimer

The code provided above is simply an exercise in applying Python programming to the field of finance. The information included in this article and the compdata package code should not be used to make investment decisions.


[1] Greenblatt, J. (2010). You Can Be a Stock Market Genius. Touchstone. [2] http://pages.stern.nyu.edu/~adamodar/


Written By

Julian Marx

Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.

Write for TDS

Related Articles