Esempio n. 1
0
def liquid_assets(stock: str,
                  date: datetime = datetime.now(),
                  lookback_period: timedelta = timedelta(days=0),
                  period: str = ''):
    return fi.cash_and_cash_equivalents(stock=stock, date=date, lookback_period=lookback_period, period=period) \
           + fi.current_marketable_securities(stock=stock, date=date, lookback_period=lookback_period, period=period) \
           + fi.net_accounts_receivable(stock=stock, date=date, lookback_period=lookback_period, period=period)
def net_working_capital(stock: str, date: datetime = datetime.now(), lookback_period: timedelta = timedelta(days=0),
                        period: str = '',
                        exclude_current_portion_cash_and_debt=False,
                        only_include_payables_receivables_inventory=False):
    # broadest (as it includes all accounts)
    if not (exclude_current_portion_cash_and_debt or only_include_payables_receivables_inventory):
        return fi.current_total_assets(stock=stock, date=date, lookback_period=lookback_period, period=period) \
               - fi.current_total_liabilities(stock=stock, date=date, lookback_period=lookback_period, period=period)

    if exclude_current_portion_cash_and_debt:  # more narrow
        return (fi.current_total_assets(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)) \
               - (fi.current_total_liabilities(stock=stock, date=date, lookback_period=lookback_period, period=period)
                  - fi.long_term_debt_current_maturities(stock=stock, date=date, lookback_period=lookback_period,
                                                         period=period))

    if only_include_payables_receivables_inventory:  # most narrow
        return fi.net_accounts_receivable(stock=stock, date=date, lookback_period=lookback_period, period=period) \
               + fi.net_inventory(stock=stock, date=date, lookback_period=lookback_period, period=period) \
               - fi.accounts_payable(stock=stock, date=date, lookback_period=lookback_period, period=period)
def net_credit_sales(stock: str, date: datetime = datetime.now(), lookback_period: timedelta = timedelta(days=0),
                     period: str = ''):
    return fi.net_sales(stock=stock, date=date, lookback_period=lookback_period, period=period) \
           - fi.net_accounts_receivable(stock=stock, date=date, lookback_period=lookback_period, period=period)
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': {}}