def debt( stock: str, date: datetime = datetime.now(), lookback_period: timedelta = timedelta(days=0), period: str = '', only_interest_expense=False, # any interest-bearing liability to qualify all_liabilities=False, # including accounts payable and deferred income long_term_debt=True, # and its associated currently due portion (measures capital structure) exclude_current_portion_long_term_debt=False # if true then also above should be true ): if long_term_debt: if not exclude_current_portion_long_term_debt: return fi.total_long_term_debt(stock=stock, date=date, lookback_period=lookback_period, period=period) else: return fi.long_term_debt_excluding_current_portion( stock=stock, date=date, lookback_period=lookback_period, period=period) if all_liabilities: return fi.total_liabilities(stock=stock, date=date, lookback_period=lookback_period, period=period) if only_interest_expense: return fi.interest_expense(stock=stock, date=date, lookback_period=lookback_period, period=period)
def cost_of_debt(stock, date=datetime.now(), lookback_period=timedelta(days=0), period: str = 'FY'): interest_rate = fi.interest_expense( stock=stock, date=date, lookback_period=lookback_period, period=period ) / fi.total_long_term_debt( stock=stock, date=date, lookback_period=lookback_period, period=period) tax_rate = fi.income_tax_expense( stock=stock, date=date, lookback_period=lookback_period, period=period ) / me.earnings_before_taxes( stock=stock, date=date, lookback_period=lookback_period, period=period) return abs(interest_rate * (1 - tax_rate))
def weighted_average_cost_of_capital( stock, date=datetime.now(), lookback_period: timedelta = timedelta(days=0), lookback_lookback_period: timedelta = timedelta(days=365 * 5), period: str = 'FY', beta_period='Monthly', benchmark: str = '^GSPC'): from_date = date - lookback_period - lookback_lookback_period to_date = date - lookback_period dictio = { 'Common Equity': (cost_of_equity_capm(stock=stock, from_date=from_date, to_date=to_date, beta_period=beta_period, benchmark=benchmark), fi.total_shareholders_equity(stock=stock, date=date, lookback_period=lookback_period, period=period)), 'Preferred Equity': (cost_of_preferred_stock(stock=stock, date=date, lookback_period=lookback_period, period=period), fi.preferred_stock_value(stock=stock, date=date, lookback_period=lookback_period, period=period)), 'Debt': (cost_of_debt(stock=stock, date=date, lookback_period=lookback_period, period=period), fi.total_long_term_debt(stock=stock, date=date, lookback_period=lookback_period, period=period)) } capitals = [np.nan_to_num(v[1]) for k, v in dictio.items()] weights = [part / sum(capitals) for part in capitals] costs = [np.nan_to_num(v[0]) for k, v in dictio.items()] return np.sum([weight * cost for weight, cost in zip(weights, costs)])
def enterprise_value(stock: str, date: datetime = datetime.now(), lookback_period: timedelta = timedelta(days=0), period: str = ''): """ :param stock: :param date: :param lookback_period: :param period: :return: """ # TODO check for unfunded pension liabilities and other debt-deemed provisions, and value of associate companies output = market_capitalization(stock=stock, date=date, lookback_period=lookback_period, period=period) \ + fi.total_long_term_debt(stock=stock, date=date, lookback_period=lookback_period, period=period) \ + np.nan_to_num( fi.minority_interest(stock=stock, date=date, lookback_period=lookback_period, period=period)) \ + np.nan_to_num( fi.preferred_stock_value(stock=stock, date=date, lookback_period=lookback_period, period=period)) \ - fi.cash_and_cash_equivalents(stock=stock, date=date, lookback_period=lookback_period, period=period) print('Enterprise Value for {} on the {} is: {}'.format(stock, date, output)) return output
def beneish_m_score(stock: str, date: datetime = datetime.now(), lookback_period: timedelta = timedelta(days=0), period: str = 'TTM', describe=False): current_net_accounts_receivable = fi.net_accounts_receivable( stock=stock, date=date, lookback_period=lookback_period, period=period) current_net_sales = fi.net_sales(stock=stock, date=date, lookback_period=lookback_period, period=period) current_receivables_to_sales = current_net_accounts_receivable / current_net_sales previous_net_accounts_receivable = fi.net_accounts_receivable( stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) previous_net_sales = fi.net_sales( stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) previous_receivables_to_sales = previous_net_accounts_receivable / previous_net_sales DSRI = current_receivables_to_sales / previous_receivables_to_sales previous_gross_profit_margin = ratios.gross_profit_margin( stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) current_gross_profit_margin = ratios.gross_profit_margin( stock=stock, date=date, lookback_period=lookback_period, period=period) GMI = previous_gross_profit_margin / current_gross_profit_margin current_asset_quality = 1 - (fi.total_current_assets( stock=stock, date=date, lookback_period=lookback_period, period=period ) + fi.net_property_plant_equipment( stock=stock, date=date, lookback_period=lookback_period, period=period ) + fi.current_marketable_securities( stock=stock, date=date, lookback_period=lookback_period, period=period)) previous_asset_quality = 1 - (fi.total_current_assets( stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) + fi.net_property_plant_equipment( stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) + fi.current_marketable_securities( stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period)) AQI = current_asset_quality / previous_asset_quality SGI = fi.net_sales(stock=stock, date=date, lookback_period=lookback_period, period=period) \ / fi.net_sales(stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) current_depreciation = fi.accumulated_depreciation_amortization(stock=stock, date=date, lookback_period=lookback_period, period=period) \ / (fi.net_property_plant_equipment(stock=stock, date=date, lookback_period=lookback_period, period=period) + fi.accumulated_depreciation_amortization(stock=stock, date=date, lookback_period=lookback_period, period=period)) previous_depreciation = fi.accumulated_depreciation_amortization(stock=stock, date=date - timedelta( days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) \ / (fi.net_property_plant_equipment(stock=stock, date=date - timedelta( days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) + fi.accumulated_depreciation_amortization(stock=stock, date=date - timedelta( days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period)) DEPI = previous_depreciation / current_depreciation SGAI = (fi.selling_general_administrative(stock=stock, date=date, lookback_period=lookback_period, period=period) / fi.net_sales(stock=stock, date=date, lookback_period=lookback_period, period=period)) \ / (fi.selling_general_administrative(stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) / fi.net_sales(stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period)) previous_leverage = (fi.total_current_liabilities(stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) + fi.total_long_term_debt(stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period)) \ / fi.total_assets(stock=stock, date=date - timedelta(days=365 if period == 'FY' else 90), lookback_period=lookback_period, period=period) current_leverage = (fi.total_current_liabilities(stock=stock, date=date, lookback_period=lookback_period, period=period) + fi.total_long_term_debt(stock=stock, date=date, lookback_period=lookback_period, period=period)) \ / fi.total_assets(stock=stock, date=date, lookback_period=lookback_period, period=period) LVGI = current_leverage / previous_leverage TATA = (fi.operating_income(stock=stock, date=date, lookback_period=lookback_period, period=period) - fi.cash_flow_operating_activities(stock=stock, date=date, lookback_period=lookback_period, period=period)) \ / fi.total_assets(stock=stock, date=date, lookback_period=lookback_period, period=period) if not describe: return -4.84 + 0.92 * DSRI + 0.528 * GMI + 0.404 * AQI + 0.892 * SGI + 0.115 * DEPI - 0.172 * SGAI + 4.679 * TATA - 0.327 * LVGI else: return {'Inputs': {}}