I am trying to calculate the following custom factors.
Enterprise_Value, EBITDA and EV_TO_EBITDA ratio.
The following works.
Many of these calculations are redundant when done in separate factors.
Is there a more efficient of building these 3 factors, possibly reusing the previous custom factors OR calculating multiple factors within the same custom factors.
# Create custom factor to calculate a market cap based on yesterday's close
# We'll use this to get the top 2000 stocks by market cap
class EnterpriseValue(CustomFactor):
# Pre-declare inputs and window_length
inputs = [USEquityPricing.close, valuation.shares_outstanding, balance_sheet.long_term_debt,
balance_sheet.long_term_debt_and_capital_lease_obligation,
balance_sheet.cash_cash_equivalents_and_marketable_securities]
window_length = 1
# Compute market cap value
def compute(self, today, assets, out, close, shares,
long_term_debt, long_term_debt_and_capital_lease_obligation,
cash_cash_equivalents_and_marketable_securities):
out[:] = close[-1] * shares[-1] + long_term_debt_and_capital_lease_obligation[-1] \
- cash_cash_equivalents_and_marketable_securities[-1]
# Create custom factor to calculate a market cap based on yesterday's close
# We'll use this to get the top 2000 stocks by market cap
class EBITDA(CustomFactor):
# Pre-declare inputs and window_length
inputs = [income_statement.ebitda]
window_length = 200
# Compute market cap value
def compute(self, today, assets, out, ebitda):
out[:] = ebitda[-1]+ebitda[-64]+ebitda[-127]+ebitda[-190]
# out[:] = ebitda[-60]
# Create custom factor to calculate a market cap based on yesterday's close
# We'll use this to get the top 2000 stocks by market cap
class EV_TO_EBITDA(CustomFactor):
# Pre-declare inputs and window_length
inputs = [USEquityPricing.close, valuation.shares_outstanding, balance_sheet.long_term_debt,
balance_sheet.long_term_debt_and_capital_lease_obligation,
balance_sheet.cash_cash_equivalents_and_marketable_securities,
income_statement.ebitda]
window_length = 200
# Compute market cap value
def compute(self, today, assets, out, close, shares,
long_term_debt, long_term_debt_and_capital_lease_obligation,
cash_cash_equivalents_and_marketable_securities,ebitda):
ev = close[-1] * shares[-1] + long_term_debt_and_capital_lease_obligation[-1] \
- cash_cash_equivalents_and_marketable_securities[-1]
ebitda = ebitda[-1]+ebitda[-64]+ebitda[-127]+ebitda[-190]
out[:] = ev / ebitda
# out[:] = ebitda[-60]