#data #_2023 #pe_utils
Professor Aswath Damodaran is a renowned finance professor at the Stern School of Business, New York University (NYU), where he teaches courses in corporate finance and valuation. Widely recognized as an authority in these fields, he is often referred to as the "Dean of Valuation" due to his expertise in valuing companies, securities, and other financial assets.
I use Professor Damodaran's data for diligence and business analysis.
Link:
Requirements:
```txt
certifi==2023.11.17
charset-normalizer==3.3.2
idna==3.6
lxml==5.0.0
numpy==1.26.3
pandas==2.1.4
python-dateutil==2.8.2
pytz==2023.3.post1
requests==2.31.0
six==1.16.0
tzdata==2023.4
urllib3==2.1.0
```
Script:
```py
# py_bls.py
import ssl
import time
import json
import pandas
import sqlite3
import requests
from functools import reduce
# -------------------------------- #
# constants
# -------------------------------- #
# config ssl to avoid ssl verification error
ssl._create_default_https_context = ssl._create_unverified_context
# dict of page links with simple structures
damadoran_url_dict_simple = {
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/variable.htm':'variable_descriptions',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/inshold.html':'insider_and_institutional_holdings_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/histimpl.html':'historical_implied_equity_risk_premiums',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/ctryprem.html':'country_default_spreads_and_risk_premiums',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/Betas.html':'betas_by_sector',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/countrytaxrates.html':'corporate_marginal_tax_rates_by_country',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/totalbeta.html':'total_betas_by_sector_for_computing_private_company_costs_of_equity_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/mktcaprisk.html':'risk_measures_by_market_cap_class_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/wacc.html':'cost_of_equity_and_capital_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/DollarUS.html':'aggregate_values_in_us_millions_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/EVA.html':'economic_value_added_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/debtdetails.html':'debt_details_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/dbtfund.html':'debt_fundamentals_by_sector',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/ratings.html':'ratings_interest_coverage_ratios_and_default_spread',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/leaseeffect.html':'lease_effect_on_debt_and_profitability_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/macro.html':'macro_economic_data_annual',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/divfcfe.html':'dividends_and_fcfe_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/divfund.html':'divident_fundamentals_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/capex.html':'capital_expenditures_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/R&D.html':'r_and_d_statistics_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/goodwill.html':'goodwill_statistics_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/margin.html':'margins_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/finflows.html':'financing_flows_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/wcdata.html':'working_capital_ratios_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/roe.html':'return_on_equity_by_sector',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/fundgr.html':'fundamental_growth_in_eps_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/histgr.html':'historical_compounded_annual_growth_rates_by_sector',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/fundgrEB.html':'fundamental_growth_in_ebit_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/pedata.html':'pe_ratio_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/pbvdata.html':'price_and_value_to_book_ratio_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/psdata.html':'revenue_multiples_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/countrystats.html':'country_averages',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/optvar.html':'standard_deviations_by_sector_us',
}
# dict of page links with complex structures
damadoran_url_dict_complex = {
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/histretSP.html':'historical_returns_on_stocks_bonds_and_bills_1928_2022',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/taxrate.html':'tax_rates_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/MktCap.html':'market_capitalization_changes_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/Employee.html':'employee_metrics_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/dbtreg.htm':'debt_ratio_regression', # screenshot
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/divreg.htm':'dividend_regressions', # screenshot
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/vebitda.html':'enterprise_value_multiples_by_sector_us',
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/mktcapmult.html':'multiples_by_market_cap_class_us', # screenshot
'https://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/MReg23.html':'regressios_of_multiples_on_fundamentals_market_wide', # numerous tables
}
# -------------------------------- #
# functions
# -------------------------------- #
def clean_df_headers(bad_header_df):
'''
Gets rid of unwanted characters in dataframe headers
'''
# characters to replace
replace_dict = {
' ': '_',
'-': '_',
',': '',
'.': '',
'/': '_',
'(': '',
')': '',
'#': '_no',
'