In this article, I would like to share another value called DCF investing, which I mentioned earlier in the CAPM investing episode. From this piece, you can learn what DCF investing is in quant trading, DCF benefits, how it works, and the cons of DCF investing. You can instantly apply the algorithm logic and script to your quant and AI analysis projects.
To whom:
DCF investing refers to using Discounted Cash Flow (DCF) analysis as a valuation method to assess whether an asset, like a stock, is under- or overvalued based on its future cash flow potential. It’s often used in fundamental and value investing, especially when the investor wants to tie price to intrinsic value.
The formula of DCF is DCF=∑(FCFt/(1+r)t)+TerminalValue
CAPM investing and DCF investing are both kinds of value investing. However, unlike CAPM investing, DCF refers to a historical dataset and assumptions used to predict future pricing points, with a generally lookback period of 3 to 5 years. If the DCF pricing is greater than the current pricing point, it indicates that the stock is undervalued. Conversely, it’s overvalued
As future prediction correlates to inflation or deflation or cost of capital, so as you can see from the formula used in quant trading, it deals with discount rate as well, which is used to discount the predicted free cash flow in each upcoming year, for the purpose to predict a more precise pricing point.
DCF investing is a kind of long-term investment that ignores the short-term noises and effects from the market and focuses on the company's intrinsic value and the future valuation based on the company's performance and growth. It’s because, in the end, the stock pricing reflects the company's valuation. If the company valuation is trending up, no matter how volatile it is now, it can rebound to be a reasonable pricing point in the upcoming period. Thus, if the future pricing point is higher than the current one, it’s a potential candidate ticker to investment.
Compared to CAPM investing, it deals with more complex factors to calculate the pricing point, which includes growth rate, discount rate, lookback period, free cash flow, and terminal value. These factors are more difficult to manipulate compared to the P/E and P/B, which are more on the accounting side. The number from the accounting side and the shares issued, to some degree, can be manipulated. Thus, it’s more reliable if the company's free cash flow and growth rate are stable.
First things first, people need to scan and select specific companies that have stable free cash flow growth. In general, the CAGR of free cash flow is greater than 5% yearly, which companies might have not been in early stage already.
Second, people need to get the latest free cash flow number from the target stock company. Also, a prediction window period is required as well. Generally, 3 to 5 years can be considered in most industries. For example, 3 years for the technology sector might not be suitable. Lastly, the latest outstanding shares and the net debt number are required as well.
Third, as mentioned earlier, DCF focues on the future intrinsic value calculation, so people need to discount the predicted free cash flow. Here we need the WACC, which is Weighted Average Cost of Capital and here is the Python script as follows
def calculate_wacc(ticker, exchange):
"""Calculate WACC for a given company"""
if exchange == 'SP500':
market_ticker = '^GSPC'
elif exchange == 'NASDAQ':
market_ticker = '^IXIC'
elif exchange == 'NYSE':
market_ticker = '^NYA'
# Get basic info
# info = “”
# 1. Calculate cost of equity (using CAPM)
risk_free_rate = get_risk_free_rate()
market_return = get_market_return(exchange)
beta = calculate_beta(ticker, market_ticker)
cost_of_equity = risk_free_rate + beta * (market_return - risk_free_rate)
# 2. Calculate cost of debt
debt_calculation = get_cost_of_debt(ticker)
cost_of_debt = debt_calculation[0]
total_debt = debt_calculation[1]
net_debt = debt_calculation[2]
# 3. Get capital structure (weights of debt and equity)
try:
companyinfo = “”
market_cap = “”
current_pricing = “”
sharesoustanding_V1 = “”
# Get market capitalization (equity value)
# Calculate weights
total_capital = market_cap + total_debt
weight_of_equity = market_cap / total_capital
weight_of_debt = total_debt / total_capital
# 4. Calculate WACC
wacc = (weight_of_equity * cost_of_equity) + (weight_of_debt * cost_of_debt)
final_result = {
'ticker': ticker,
'exchange': exchange,
'wacc': round(wacc,2),
'cost_of_equity': round(cost_of_equity,2),
'cost_of_debt': round(cost_of_debt,2),
'weight_of_equity': round(weight_of_equity, 2),
'weight_of_debt': round(weight_of_debt, 2),
'beta': beta,
'risk_free_rate': round(risk_free_rate,2),
'market_return': market_return,
'market_cap': market_cap,
'total_debt': total_debt,
"net_debt": net_debt,
"current_price": round(current_pricing,4),
"shares outstanding": sharesoustanding_V1
}
return final_result
except Exception as e:
print("no wacc")
final_result = {
'ticker': ticker,
'exchange': exchange,
'wacc': 0.0,
'cost_of_equity': 0.0,
'cost_of_debt': 0.0,
'weight_of_equity': 0.0,
'weight_of_debt': 0.0,
'beta': beta,
'risk_free_rate': risk_free_rate,
'market_return': market_return,
'market_cap': 0,
'total_debt': total_debt,
"net_debt": net_debt,
"current_price": 0.0,
"shares outstanding": 0
}
return final_result
Lastly, it’s the terminal growth rate to calculate the terminal value or TV. The terminal growth rate is the constant rate at which a company’s free cash flow (FCF) is expected to grow forever beyond the forecast period in a Discounted Cash Flow (DCF) model. It's used to calculate the Terminal Value (TV), which represents the bulk of a company's value in most DCF models (especially when the forecast period is short, e.g., 5–10 years). You don’t need to calculate the terminal value growth rate from scratch. This number varies by sector, and in general, it will not be greater than the GDP growth rate. For example, we will suggest using the GDP growth rate applied to terminal value calculation
Here is the formula of terminal value calculation: Terminal Value (TV)=r−gFCFn×(1+g)
The downside of DCF investing is obvious, which is more for stable performing companies or large companies. As DCF intrinsic value prediction requires lots of company internal dataset that supports this prediction. For early-stage companies in the stock market, they might not have stable free cash flow and growth rate, or they are not earning ye,t and the free cash flow might be negative. In these cases, it’s not suitable to adopt DCF model in quant trading to scan the undervalued companies
Also, DCF is based on an assumption. It’s a kind of ideal investment strategy that might ignore the dynamic factors from the cost of capital, terminal growth rate, and so on. So it deals with more complex dataset preparation from macro, micro and internal, in order to ensure the prediciton can be refererable and reliable
Lastly, DCF is more like a supplement to narrow down the investment options, rather than being used to invest in a standalone mode. After all, it’s an assumption model. Working with other metrics and algorithm together make DCF work in a more realistic mode.
If you use generative AI to analyse investment opportunities, in terms of DCF investing, here is a list of components you need to consider and include in the AI prompt as follows:
def calculate_dcf(fcf, years, fcf_cagr, discount_rate, terminal_growth_rate, net_debt, shares_outstanding):
# Project future cash flows based on FCF CAGR
projected_fcf = []
for year in range(1, years + 1):
fcf = fcf * (1 + fcf_cagr) # Apply FCF CAGR to estimate next year's FCF
projected_fcf.append(fcf)
# Discount future cash flows to present value
discounted_cash_flows = [cf / (1 + discount_rate) ** year for year, cf in enumerate(projected_fcf, start=1)]
# Terminal value calculation (using perpetuity formula: FCF * (1 + growth rate) / (discount rate - growth rate))
terminal_value = projected_fcf[-1] * (1 + terminal_growth_rate) / (discount_rate - terminal_growth_rate)
# Discount terminal value back to present value
discounted_terminal_value = terminal_value / (1 + discount_rate) ** years
# Sum of discounted future cash flows and discounted terminal value gives the DCF
dcf_value = sum(discounted_cash_flows) + discounted_terminal_value
# Calculate equity value (DCF value minus net debt)
equity_value = dcf_value - net_debt
# Calculate intrinsic value per share
if shares_outstanding !=0:
dcf_value_per_share = equity_value / shares_outstanding
else:
dcf_value_per_share = 0
return dcf_value_per_share
If you are interested in getting the AI prompt sample which can be used to get insights from generative AI and also like to explore the full python script on value investing opportunity, please subscribe our news letter and leave a message with “DCF investing script and AI prompt.