{"id":3787,"date":"2023-11-21T12:05:06","date_gmt":"2023-11-21T12:05:06","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=3787"},"modified":"2025-02-05T14:25:40","modified_gmt":"2025-02-05T14:25:40","slug":"automate-your-discounted-cash-flow-model-in-python","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python","title":{"rendered":"Automate your Discounted Cash Flow model in Python"},"content":{"rendered":"\n<p>The Discounted Cash Flow (DCF) model stands as one of the most widely employed financial models for investment evaluation. This model plays a crucial role in estimating the intrinsic value of a public company&#8217;s stock. The intrinsic share price is determined through an analysis of the company&#8217;s current and anticipated future cash flows.<\/p>\n\n\n\n<p>In essence, the intrinsic value reflects the perceived worth of a company&#8217;s stock based on its fundamental financials. Comparing this intrinsic value with the current market valuation of a company provides valuable insights into the investment potential. This comparison aids in gauging whether a particular firm is a sound investment by indicating if its stock is currently undervalued or overvalued.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/strong><\/p>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-a-real-case-study-tesla\">A real case-study: Tesla<\/h2>\n\n\n\n<p>For this case study, we will employ the <a href=\"https:\/\/eodhd.com\/financial-apis\/python-financial-libraries-and-code-samples\" target=\"_blank\" rel=\"noreferrer noopener\">EODHD Python Library<\/a> to seamlessly download financial statement data directly into our Jupyter notebook via the API service. In our illustrative example, we focus our analysis on Tesla stock (ticker = &#8220;TSLA.US&#8221;), a subject that sparks considerable debate on Wall Street due to its intriguing valuation. Our analysis kicks off by retrieving the most recent company data using the <em>client.get_fundamental_equity<\/em> function. This function can be used to obtain the three main documents that constitute an annual company report: the Balance Sheet, Income Statement, and Cash Flow Statement. Collectively, these documents offer a comprehensive overview of the company&#8217;s financial health and performance, forming the cornerstone of our analytical process.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">import eod\nclient = EodHistoricalData(api_key)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<p class=\"bordered_paragraph\">1. Use the \u201c<strong>demo<\/strong>\u201d API key to test our data from a limited set of tickers without registering: <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/AAPL.US\" target=\"_blank\" rel=\"noreferrer noopener\">AAPL.US<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/TSLA.US\" target=\"_blank\" rel=\"noreferrer noopener\">TSLA.US <\/a>| <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/VTI.US\" target=\"_blank\" rel=\"noreferrer noopener\">VTI.US<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/AMZN.US\" target=\"_blank\" rel=\"noreferrer noopener\">AMZN.US<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/BTC-USD.CC\" target=\"_blank\" rel=\"noreferrer noopener\">BTC-USD<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/EURUSD.FOREX\" target=\"_blank\" rel=\"noreferrer noopener\">EUR-USD<\/a><br><a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/AAPL.US\" target=\"_blank\" rel=\"noreferrer noopener\">Real-Time Data<\/a> and all of the APIs (except Bulk) are included without API calls limitations with these tickers and the demo key.<br>2. Register to get your free API key (limited to 20 API calls per day) with access to: <a href=\"https:\/\/eodhistoricaldata.com\/financial-apis\/api-for-historical-data-and-volumes\/\" target=\"_blank\" rel=\"noreferrer noopener\">End-Of-Day Historical Data<\/a> with only the past year for any ticker, and the <a href=\"https:\/\/eodhistoricaldata.com\/financial-apis\/api-for-historical-data-and-volumes\/\" target=\"_blank\" rel=\"noreferrer noopener\">List of tickers per Exchange<\/a>.<br>3. To unlock your API key, we recommend to choose the subscription plan which covers your needs.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">stock_ticker = \"TSLA.US\"\n\n#download BS, IS, CFS from EOD historical data\nBalanceSheet = client.get_fundamental_equity(stock_ticker, filter_='Financials::Balance_Sheet::yearly')\nIncomeStat = client.get_fundamental_equity(stock_ticker, filter_='Financials::Income_Statement::yearly')\nCashFlowStat = client.get_fundamental_equity(stock_ticker, filter_='Financials::Cash_Flow::yearly')\nOutShares = client.get_fundamental_equity(stock_ticker, filter_='SharesStats::SharesOutstanding')\n\n# transpose and concatenate\ndf_bal = pd.DataFrame(BalanceSheet).T\ndf_inc = pd.DataFrame(IncomeStat).T\ndf_cfs = pd.DataFrame(CashFlowStat).T\ndf_all = pd.concat([df_bal, df_inc, df_cfs], axis=1).sort_index()\ndf_all = df_all.loc[:, ~df_all.columns.duplicated()] #remove duplicated columns<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>We begin by executing some preprocessing steps to present our data in a more suitable format. This involves tasks such as converting data to float type and replacing datetime entries with the corresponding year. Given the large size of the table, we filter it taking a few sample columns and show the result below: <\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">#convert all None values to np.NaN datatypes\ndf = df_all.iloc[-10 :, 3:,].applymap(lambda x: float(x) if x is not None else np.NaN)\ndf.index = pd.to_datetime(df.index)\ndf.index = df.index.year\ndf = df.applymap(format_value)\ndf.head(10)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"295\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/image.png\" alt=\"\" class=\"wp-image-3788\"\/><\/figure>\n<\/div>\n\n\n<p>The table serves as a snapshot for the entire dataframe, offering a glimpse into its structure ensuring that the content is displayed accurately. To facilitate visualization, the values have been converted to <em>floating-point <\/em>numbers and are expressed in millions of dollars ($).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-preparing-the-dcf-ingredients\">Preparing the DCF ingredients<\/h2>\n\n\n\n<p>After retrieving the financial company data, we can now compute the value of all the variables required in a Discounted Cash Flow model:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>% Revenue Growth<\/li>\n\n\n\n<li>% Ebit\/Sales<\/li>\n\n\n\n<li>% D&amp;A\/Sales<\/li>\n\n\n\n<li>% Capex\/Sales<\/li>\n\n\n\n<li>% <strong>\u0394<\/strong> Net Working Capital\/ Sales<\/li>\n\n\n\n<li>% Tax\/Ebit<\/li>\n\n\n\n<li>Ebiat = Earning before interests after taxes<\/li>\n<\/ul>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># compute % of sales and % of ebit variables\ndf[\"rev_growth\"] = df[\"totalRevenue\"].pct_change()\ndf[\"delta_nwc\"] = df[\"netWorkingCapital\"].diff()\ndf[\"ebit_of_sales\"] = df[\"ebit\"]\/df[\"totalRevenue\"]\ndf[\"dna_of_sales\"] = df[\"depreciationAndAmortization\"]\/df[\"totalRevenue\"]\ndf[\"capex_of_sales\"] = df[\"capitalExpenditures\"]\/df[\"totalRevenue\"]\ndf[\"nwc_of_sales\"] = df[\"delta_nwc\"]\/df[\"totalRevenue\"]\ndf[\"tax_of_ebit\"] = df[\"taxProvision\"]\/df[\"ebit\"]\ndf[\"ebiat\"] = df[\"ebit\"] - df[\"taxProvision\"]\nlast_year = df.iloc[-1, :]<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>Also, we store data from the most recent financial statement in the variable <em>last_year<\/em>. This will be helpful to calculate our projections through linear interpolation. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1225\" height=\"1968\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/subplots.png\" alt=\"\" class=\"wp-image-3875\" style=\"aspect-ratio:0.6224593495934959;width:839px;height:auto\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-assumptions\">Assumptions<\/h2>\n\n\n\n<p>The assumptions in a Discounted Cash Flow (DCF) analysis are foundational elements that significantly influence the accuracy and reliability of the valuation. The DCF method relies on projecting future cash flows and discounting them back to their present value. Assumptions about growth rates, discount rates, terminal values, and other factors shape these projections. An example of how the sensitivity to changes in these assumptions impact the final valuation will be shown in the last chapter.<\/p>\n\n\n\n<p>In this case study, we develop a 10-year DCF, implying that our projections extend until the year 2032. The other variables are assumed as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>N = years of projections = 10<\/li>\n\n\n\n<li>% Revenue Growth = 7%<\/li>\n\n\n\n<li>% Ebit\/Sales = 23%<\/li>\n\n\n\n<li>% D&amp;A\/Sales = 3%<\/li>\n\n\n\n<li>% Capex\/Sales = 5%<\/li>\n\n\n\n<li>% <strong>\u0394<\/strong> Net Working Capital\/ Sales = 5%<\/li>\n\n\n\n<li>% Tax\/Ebit = 21%<\/li>\n\n\n\n<li>TGR = 2.5%<\/li>\n<\/ul>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">n = 10\nrevenue_growth_T = 0.07\nebit_perc_T = 0.23\ntax_perc_T = 0.21\ndna_perc_T = 0.03\ncapex_perc_T = 0.05\nnwc_perc_T = 0.05\nTGR = 0.025<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<h2 class=\"wp-block-heading\" id=\"h-creating-the-dcf-projections\">Creating the DCF projections<\/h2>\n\n\n\n<p>Now that our model components are in place, it is opportune to delve into considerations regarding the company&#8217;s future values. In this scenario, the goal is to model the trajectories of the variables in accordance with our expectations of the company and the industry future developments. For the sake of simplicity, we make the assumption of a linear trend for values from time t+1 to T. Thus we assume a constant rate of change of our model variables. Despite being a stringent assumption, linear interpolation is often use to model the value at intermediate dates between the starting value and the last projection.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">def interpolate(initial_value, terminal_value, nyears):\n    return np.linspace(initial_value, terminal_value, nyears)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">years = range(df.index[-1]+1, df.index[-1] + n + 1)\ndf_proj = pd.DataFrame(index=years, columns=df.columns)\n# linear interpolation\ndf_proj[\"rev_growth\"] = interpolate(last_year[\"rev_growth\"], revenue_growth_T, n) \ndf_proj[\"ebit_of_sales\"] = interpolate(last_year[\"ebit_of_sales\"], ebit_perc_T, n) \ndf_proj[\"dna_of_sales\"] = interpolate(last_year[\"dna_of_sales\"], dna_perc_T, n) \ndf_proj[\"capex_of_sales\"] = interpolate(last_year[\"capex_of_sales\"], capex_perc_T, n) \ndf_proj[\"tax_of_ebit\"] = interpolate(last_year[\"tax_of_ebit\"], tax_perc_T, n) \ndf_proj[\"nwc_of_sales\"] = interpolate(last_year[\"nwc_of_sales\"], nwc_perc_T, n) \n# cumulative values\ndf_proj[\"totalRevenue\"] = last_year[\"totalRevenue\"] *(1+df_proj[\"rev_growth\"]).cumprod() \ndf_proj[\"ebit\"] = last_year[\"ebit\"] *(1+df_proj[\"ebit_of_sales\"]).cumprod() \ndf_proj[\"capitalExpenditures\"] = last_year[\"capitalExpenditures\"] *(1+df_proj[\"capex_of_sales\"]).cumprod() \ndf_proj[\"depreciationAndAmortization\"] = last_year[\"depreciationAndAmortization\"] *(1+df_proj[\"dna_of_sales\"]).cumprod() \ndf_proj[\"delta_nwc\"] = last_year[\"delta_nwc\"] *(1+df_proj[\"nwc_of_sales\"]).cumprod() \ndf_proj[\"taxProvision\"] = last_year[\"taxProvision\"] *(1+df_proj[\"tax_of_ebit\"]).cumprod() \ndf_proj[\"ebiat\"] = df_proj[\"ebit\"] - df_proj[\"taxProvision\"]<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>The last step before moving to the WACC estimation is to calculate the FCF by using the equation below:<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=FCF+%3D+EBIAT+%2B+D%5C%26A+-+CAPEX+-+%5CDelta+NWC+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"FCF = EBIAT + D&#92;&amp;A - CAPEX - &#92;Delta NWC \" class=\"latex\" \/><\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">df_proj[\"freeCashFlow\"] = df_proj[\"ebiat\"] + df_proj[\"depreciationAndAmortization\"] - df_proj[\"capitalExpenditures\"] - df_proj[\"delta_nwc\"]<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<h2 class=\"wp-block-heading\" id=\"h-weighted-average-cost-of-capital-wacc\">Weighted Average Cost of Capital (WACC)<\/h2>\n\n\n\n<p>For the calculation of the WACC, we will need to retrieve more data from the <a href=\"https:\/\/eodhd.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">EOD database<\/a>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Company&#8217;s Beta<\/li>\n\n\n\n<li>Company&#8217;s Market Capitalization<\/li>\n\n\n\n<li>10-year US Treasury Rate, as proxy for the risk-free rate<\/li>\n\n\n\n<li>Yield-to-Maturity of Tesla&#8217;s bonds<\/li>\n\n\n\n<li>Equity Risk Premium, from <a href=\"https:\/\/pages.stern.nyu.edu\/~adamodar\/New_Home_Page\/\" target=\"_blank\" rel=\"noreferrer noopener\">Damodaran website<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cost-of-equity\">Cost of Equity<\/h3>\n\n\n\n<p>According to the Capital Asset Pricing Model (CAPM), the cost of equity is often calculated as the expected rate of return on the company&#8217;s equity, and it is represented by the formula<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=CostOfEquity+%3D+R_%7Bf%7D+%2B+%5Cbeta+%5Ccdot+%28R_%7Bm%7D+-+R_%7Bf%7D%29+%3D+%5Cbeta+%5Ccdot+ERP&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"CostOfEquity = R_{f} + &#92;beta &#92;cdot (R_{m} - R_{f}) = &#92;beta &#92;cdot ERP\" class=\"latex\" \/><\/p>\n\n\n\n<p>Thus, we first need to collect data on the company&#8217;s market capitalization and beta i.e. the sensitivity to market returns, the risk-free rate (here we use 10-y US treasury as proxy) and the equity risk premium<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\"># company's beta and marketcap\nbeta = client.get_fundamental_equity(stock_ticker, filter_='Technicals::Beta')\nmarketcap = client.get_fundamental_equity(stock_ticker, filter_='Highlights::MarketCapitalization')\n\n# risk-free rate\nUS10Y = client.get_prices_eod(\"US10Y.INDX\", period='d', order='a')\nUS10Y = pd.DataFrame(US10Y).set_index(\"date\")[\"adjusted_close\"]\nUS10Y.rename(\"10Y\", inplace=True)\nrf_rate = US10Y.values[-1] \/100\n\n# get ERP\nexcel_url = \"https:\/\/www.stern.nyu.edu\/~adamodar\/pc\/datasets\/histimpl.xls\"\ndf_ERP = pd.read_excel(excel_url, skiprows=6)\ndf_ERP = df_ERP.dropna(subset=[\"Year\"]).iloc[:-1, :].set_index(\"Year\")\nERP = df_ERP[\"Implied ERP (FCFE)\"].values[-1]<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">CostOfEquity = beta*(ERP) + rf_rate<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>Tesla Inc.&#8217;s cost of equity stands at 17.9%. This is attributed, on one hand, to the stock&#8217;s heightened sensitivity to market returns (beta), and on the other hand, to the elevated interest rate environment recorded in 2023.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cost-of-debt\">Cost of Debt<\/h3>\n\n\n\n<p>We will use the yield-to-maturity (YTM) of bond issues as proxy for the Tesla&#8217;s cost of debt. Bond data can be retrieved either through the <a href=\"https:\/\/eodhd.com\/financial-apis-blog\/types-feature-for-search-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Search API<\/a> or <a href=\"https:\/\/eodhd.com\/financial-apis\/exchanges-api-list-of-tickers-and-trading-hours\/\" target=\"_blank\" rel=\"noreferrer noopener\">Exchange API<\/a> function. In the latter case, we will need to pass the code <em>BOND<\/em> as exchange name.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">import requests\nurl = f'https:\/\/eodhd.com\/api\/exchange-symbol-list\/BOND?api_token={apikey}&amp;fmt=json&amp;delisted=1'\ndata = requests.get(url).json()\nbond_issues = pd.DataFrame(data)\ntsla_bond_issues = bond_issues[bond_issues[\"Name\"].str.contains(\"Tesla\")]<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">YTM = np.zeros(len(tsla_bond_issues))\ntoday = datetime.now()\nc = 0\n\nfor i in tsla_bond_issues[\"Code\"]:\n    bond_data = client.get_fundamentals_bonds(i, bond_only=1)\n    YTM[c] = bond_data[\"YieldToMaturity\"]\n    c+=1\n\ntsla_bond_issues[\"YTM\"] = YTM\nCostOfDebt = tsla_bond_issues[\"YTM\"].mean() \/100<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"832\" height=\"123\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/tesla_bonds.png\" alt=\"\" class=\"wp-image-3903\"\/><\/figure>\n\n\n\n<p>Hence, we will adopt 3.885% as a proxy for the company&#8217;s cost of debt. The final step involves applying the Weighted Average Cost of Capital (WACC) formula. This is a weighted average, with the weights representing the debt and equity portions in the company&#8217;s balance sheet. The resulting equation provides us with the discount rate, which will be applied to project and anticipate future cash flow projections.<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=WACC+%3D+C_%7BD%7D%281-T%29%5Cfrac%7BD%7D%7BD%2BE%7D+%2B+C_%7BE%7D%5Cfrac%7BE%7D%7BD%2BE%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"WACC = C_{D}(1-T)&#92;frac{D}{D+E} + C_{E}&#92;frac{E}{D+E}\" class=\"latex\" \/><\/p>\n\n\n\n<p>where C(D) and C(E) are the cost of debt and cost of equity, respectively, and T is the tax rate.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">Assets =  last_year[\"totalAssets\"] \nDebt = last_year[\"totalLiab\"]\ntotal = marketcap + Debt\nAfterTaxCostOfDebt = CostOfDebt * (1-tax_perc_T)\nWACC = (AfterTaxCostOfDebt*Debt\/total) + (CostOfEquity*marketcap\/total)\n<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>In this example, we calculate a WACC of 17.2% for Tesla, a figure that stands notably higher than market standards. This elevated value can be attributed to the positive equity market performance, elevated interest rates, and Tesla&#8217;s heightened sensitivity to equity market returns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-calculating-present-value-of-fcf\">Calculating present value of FCF<\/h2>\n\n\n\n<p>After estimating the company&#8217;s projections and WACC, it&#8217;s time to calculate the present value of the FCF using the WACC as the discount rate:<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=PV+FCF+%3D+%5Cfrac%7BCF_%7B1%7D%7D%7B%281%2Bi%29%5E1%7D+%2B+%5Cfrac%7BCF_%7B2%7D%7D%7B%281%2Bi%29%5E2%7D+%2B+%5Ccdots+%2B+%5Cfrac%7BCF_%7BT%7D%7D%7B%281%2Bi%29%5ET%7D+%3D+%5Csum_%7Bt%3D1%7D%5E%7BT%7D+%5Cfrac%7BCF_%7Bt%7D%7D%7B%281%2Bi%29%5Et%7D+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"PV FCF = &#92;frac{CF_{1}}{(1+i)^1} + &#92;frac{CF_{2}}{(1+i)^2} + &#92;cdots + &#92;frac{CF_{T}}{(1+i)^T} = &#92;sum_{t=1}^{T} &#92;frac{CF_{t}}{(1+i)^t} \" class=\"latex\" \/><\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">def calculate_present_value(cash_flows, discount_rate):\n    # Calculate the present value using: PV = CF \/ (1 + r)^t + TV\/(1 + r)^T\n    present_values_cf = [cf \/ (1 + discount_rate) ** t for t, cf in enumerate(cash_flows, start=1)]\n    return present_values_cf\ndf_proj[\"pv_FCF\"] = calculate_present_value(df_proj[\"freeCashFlow\"].values, WACC)<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"525\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/fcf_projections.png\" alt=\"\" class=\"wp-image-3824\"\/><\/figure>\n\n\n\n<p>Finally we compute the Terminal Value i.e. the present value of all future cash flows beyond the explicit forecast period; in our case, 2032. The formula for the Terminal Value is:<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=TV+%3D+%5Cfrac%7BCF_%7BT%7D+%5Ccdot%281%2BTGR%29%7D%7B%28WACC+-+TGR%29%7D+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"TV = &#92;frac{CF_{T} &#92;cdot(1+TGR)}{(WACC - TGR)} \" class=\"latex\" \/><\/p>\n\n\n\n<p>where TGR is the Terminal Growth Rate and represents the rate at which we expect the free cash flows of Tesla to grow beyond the explicit forecast period.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">TV = df_proj[\"freeCashFlow\"].values[-1] *(1+TGR) \/ (WACC - TGR)\npv_TV = TV\/(1+WACC)**n<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>As a final step, we sum up the present value of FCF and the terminal value to obtain the Enterprise Value. From here, we can derive the Equity Value by subtracting the outstanding debt and adding cash. The implied Share Price is finally obtained by dividing the Equity Value by the number of outstanding shares.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">Ent_Value = np.sum(df_proj[\"pv_FCF\"]) + pv_TV\nCash = last_year[\"cash\"]\nEq_Value = Ent_Value - Debt + Cash\nImpliedSharePrice = Eq_Value\/OutShares<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>Based on our assumptions, we obtained a Tesla share price of 42$ per shares which is very low considering that it is currently trading at 250$. This results is due to the very high cost of equity (17.9%) and extremely low level of company&#8217;s debt. As showed in the next chapter, for more moderate levels of WACC ~8% we can easily obtain valuation above 300$. Investors are invited to use assumption values in line with their own expectations and views of the market.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"955\" height=\"425\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/dcf_output-1.png\" alt=\"\" class=\"wp-image-3917\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-sensitivity-analysis\">Sensitivity analysis<\/h2>\n\n\n\n<p>In the context of DCF modelling, a sensitivity analysis is a technique used to understand how changes in certain key variables impact the calculated net present value (NPV) of a project or investment, and consequently, the implied share price. In this example, we vary the WACC and TGR to observe the impact of these variables on the final valuation. Intuitively, a higher WACC significantly reduces the future value of FCF and, consequently, the company&#8217;s valuation. Conversely, the TGR works in the opposite way, positively influencing the terminal value (TV) and thereby enhancing the overall valuation.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code lang=\"python\" class=\"language-python\">waccs = np.linspace(0.06, 0.18, 25)  \ntgrs = np.linspace(0.01, 0.04, 25)   \n\n# Create a meshgrid for cost of debt and growth rate\nwaccs_mesh, tgrs_mesh = np.meshgrid(waccs, tgrs)\n\n# Calculate NPV for each combination of cost of debt and growth rate\ndcf_results = np.zeros_like(waccs_mesh)\nfor i in range(len(tgrs)):\n    for j in range(len(waccs)):\n         dcf_results[i, j] = Discount_Cash_Flow(df,  n=10, OutShares=OutShares, revenue_growth_T = 0.07, ebit_perc_T = 0.23,  tax_perc_T = 0.21, dna_perc_T = 0.03, capex_perc_T = 0.05, nwc_perc_T = 0.05, WACC = waccs[j],  TGR = tgrs[i])\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\nax.plot_surface(waccs_mesh, tgrs_mesh, dcf_results, cmap='viridis')\n\nax.set_xlabel('WACC')\nax.set_ylabel('TGR')\nax.set_zlabel('Implied Share Price')\nax.set_title('Tesla Sensitivity Analysis')\n\nplt.show()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/Tesla_SA.png\" alt=\"\" class=\"wp-image-3873\" style=\"aspect-ratio:1.3333333333333333;width:839px;height:auto\"\/><\/figure>\n\n\n\n<p> This analytical approach allows for a more comprehensive assessment of the model&#8217;s robustness and provides insights into the sensitivity of the valuation to fluctuations in key parameters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>In conclusion, this tutorial has provided a comprehensive guide on how to perform a Discounted Cash Flow (DCF) analysis in Python, empowering users to assess the intrinsic value of a company&#8217;s stock based on its future cash flows. By leveraging the <a href=\"https:\/\/eodhd.com\/financial-apis\/python-financial-libraries-and-code-samples\" target=\"_blank\" rel=\"noreferrer noopener\">EODHD Pyhton Financial Library<\/a>, we could download all key financial information in an efficient way and cover all the key steps to get the implicit share price, including data preprocessing, assumption setting, and the actual DCF calculation.<\/p>\n\n\n\n<p>Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a detailed formula and explanation of its significance in the DCF calculation. This metric serves as the cornerstone for estimating a company&#8217;s intrinsic value by accounting for its operational efficiency, capital expenditures, and overall financial health. Finally, we showed a practical approach to effectively compute the Weighted Average Cost of Capital (WACC) based on the initial data.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n<p>Full code available <a href=\"https:\/\/github.com\/gbaglini\/baglinifinance\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a><br>Website: <a href=\"https:\/\/baglinifinance.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">baglinifinance.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Discounted Cash Flow (DCF) model stands as one of the most widely employed financial models for investment evaluation. This model plays a crucial role in estimating the intrinsic value of a public company&#8217;s stock. The intrinsic share price is determined through an analysis of the company&#8217;s current and anticipated future cash flows. In essence, [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":3833,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"coding-language":[30],"ready-to-go-solution":[44],"qualification":[31],"financial-apis-category":[36],"financial-apis-manuals":[37],"class_list":["post-3787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fundamental-analysis-examples","coding-language-python","ready-to-go-solution-python-financial-apis-sdk","qualification-experienced","financial-apis-category-stock-market-prices","financial-apis-manuals-stocks-fundamentals","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Automate your Discounted Cash Flow model in Python | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a formula and explanation of its significance in the DCF calculation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automate your Discounted Cash Flow model in Python\" \/>\n<meta property=\"og:description\" content=\"Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a formula and explanation of its significance in the DCF calculation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-21T12:05:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T14:25:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png\" \/>\n\t<meta property=\"og:image:width\" content=\"598\" \/>\n\t<meta property=\"og:image:height\" content=\"367\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Gianluca Baglini\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gianluca Baglini\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\"},\"author\":{\"name\":\"Gianluca Baglini\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f\"},\"headline\":\"Automate your Discounted Cash Flow model in Python\",\"datePublished\":\"2023-11-21T12:05:06+00:00\",\"dateModified\":\"2025-02-05T14:25:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\"},\"wordCount\":1708,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png\",\"articleSection\":[\"Fundamental Analysis Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\",\"name\":\"Automate your Discounted Cash Flow model in Python | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png\",\"datePublished\":\"2023-11-21T12:05:06+00:00\",\"dateModified\":\"2025-02-05T14:25:40+00:00\",\"description\":\"Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a formula and explanation of its significance in the DCF calculation.\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png\",\"width\":598,\"height\":367,\"caption\":\"valuation-models-trading-comps-financial-statement\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automate your Discounted Cash Flow model in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f\",\"name\":\"Gianluca Baglini\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g\",\"caption\":\"Gianluca Baglini\"},\"description\":\"Financial &amp; Risk Analyst, Data Scientist, Python Developer, Owner of BagliniFinance blog\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/gianluca-baglini\/\"],\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/gianlucabaglini\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Automate your Discounted Cash Flow model in Python | EODHD APIs Academy","description":"Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a formula and explanation of its significance in the DCF calculation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python","og_locale":"en_US","og_type":"article","og_title":"Automate your Discounted Cash Flow model in Python","og_description":"Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a formula and explanation of its significance in the DCF calculation.","og_url":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2023-11-21T12:05:06+00:00","article_modified_time":"2025-02-05T14:25:40+00:00","og_image":[{"width":598,"height":367,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png","type":"image\/png"}],"author":"Gianluca Baglini","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Gianluca Baglini","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python"},"author":{"name":"Gianluca Baglini","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f"},"headline":"Automate your Discounted Cash Flow model in Python","datePublished":"2023-11-21T12:05:06+00:00","dateModified":"2025-02-05T14:25:40+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python"},"wordCount":1708,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png","articleSection":["Fundamental Analysis Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python","url":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python","name":"Automate your Discounted Cash Flow model in Python | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png","datePublished":"2023-11-21T12:05:06+00:00","dateModified":"2025-02-05T14:25:40+00:00","description":"Our journey also delved into the fundamental concept of Free Cash Flow (FCF), providing a formula and explanation of its significance in the DCF calculation.","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png","width":598,"height":367,"caption":"valuation-models-trading-comps-financial-statement"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/fundamental-analysis-examples\/automate-your-discounted-cash-flow-model-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Automate your Discounted Cash Flow model in Python"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f","name":"Gianluca Baglini","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g","caption":"Gianluca Baglini"},"description":"Financial &amp; Risk Analyst, Data Scientist, Python Developer, Owner of BagliniFinance blog","sameAs":["https:\/\/www.linkedin.com\/in\/gianluca-baglini\/"],"url":"https:\/\/eodhd.com\/financial-academy\/author\/gianlucabaglini"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/11\/valuation_models_dcf.png","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-Z5","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/3787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=3787"}],"version-history":[{"count":32,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/3787\/revisions"}],"predecessor-version":[{"id":6317,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/3787\/revisions\/6317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/3833"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=3787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=3787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=3787"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=3787"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=3787"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=3787"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=3787"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=3787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}