Beispiel #1
0
 def degm(ttm_earning, ttm_earning_p1y, factor_earning):
     """
     毛利率增长,与去年同期相比
     :param ttm_earning_p1y:
     :param ttm_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['operating_revenue', 'operating_cost']
     earning = ttm_earning.loc[:, columns_list]
     earning_p1y = ttm_earning_p1y.loc[:, columns_list]
     earning['gross_income_ratio'] = np.where(
         CalcTools.is_zero(earning.operating_revenue.values), 0,
         (earning.operating_revenue.values - earning.operating_cost.values)
         / earning.operating_revenue.values)
     earning_p1y['gross_income_ratio'] = np.where(
         CalcTools.is_zero(earning_p1y.operating_revenue.values), 0,
         (earning_p1y.operating_revenue.values -
          earning_p1y.operating_cost.values) /
         earning_p1y.operating_revenue.values)
     earning["degm"] = earning["gross_income_ratio"] - earning_p1y[
         "gross_income_ratio"]
     columns_list.append('gross_income_ratio')
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
 def oper_cash_in_to_asset_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = ['net_operate_cash_flow', 'total_assets']
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['OptToAssertTTM'] = np.where(
         CalcTools.is_zero(cash_flow.total_assets.values), 0,
         cash_flow.net_operate_cash_flow.values /
         cash_flow.total_assets.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def nocf_to_net_debt_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = ['net_operate_cash_flow', 'net_liability']
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['OptCFToNetDebtTTM'] = np.where(
         CalcTools.is_zero(cash_flow.net_liability.values), 0,
         cash_flow.net_operate_cash_flow.values /
         cash_flow.net_liability.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def cash_rate_of_sales_latest(tp_cash_flow, factor_cash_flow):
     columns_list = ['net_operate_cash_flow', 'operating_revenue']
     cash_flow = tp_cash_flow.loc[:, columns_list]
     cash_flow['CashOfSales'] = np.where(
         CalcTools.is_zero(cash_flow.operating_revenue.values), 0,
         cash_flow.net_operate_cash_flow.values /
         cash_flow.operating_revenue.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def net_profit_cash_cover_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = ['net_operate_cash_flow', 'np_parent_company_owners']
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['NetProCashCoverTTM'] = np.where(
         CalcTools.is_zero(cash_flow.np_parent_company_owners.values), 0,
         cash_flow.net_operate_cash_flow.values /
         cash_flow.np_parent_company_owners.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def acca_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = ['net_operate_cash_flow', 'net_profit', 'total_assets']
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['OptOnReToAssetTTM'] = np.where(
         CalcTools.is_zero(cash_flow.total_assets.values), 0,
         (cash_flow.net_operate_cash_flow.values -
          cash_flow.net_profit.values) / (cash_flow.total_assets.values))
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def cash_to_current_liability_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = ['cash_and_equivalents_at_end', 'total_current_assets']
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['CashRatioTTM'] = np.where(
         CalcTools.is_zero(cash_flow.total_current_assets.values), 0,
         cash_flow.cash_and_equivalents_at_end.values /
         cash_flow.total_current_assets.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def oper_cash_in_to_current_liability_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = ['net_operate_cash_flow', 'total_current_liability']
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['OptCFToCurrLiabilityTTM'] = np.where(
         CalcTools.is_zero(cash_flow.total_current_liability.values), 0,
         cash_flow.net_operate_cash_flow.values /
         cash_flow.total_current_liability.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
Beispiel #9
0
 def debts_asset_ratio_latest(tp_contrarian, factor_contrarian):
     columns_list = ['total_liability', 'total_assets']
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['DA'] = np.where(
         CalcTools.is_zero(contrarian['total_assets']), 0,
         contrarian['total_liability'] / contrarian['total_assets'])
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
Beispiel #10
0
 def sales_cost_ratio_ttm(tp_contrarian, factor_contrarian):
     columns_list = ['operating_cost', 'operating_revenue']
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['SalesCostTTM'] = np.where(
         CalcTools.is_zero(contrarian['operating_revenue']), 0,
         contrarian['operating_cost'] / contrarian['operating_revenue'])
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
 def sale_service_cash_to_or_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = [
         'goods_sale_and_service_render_cash', 'operating_revenue'
     ]
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['SaleServCashToOptReTTM'] = np.where(
         CalcTools.is_zero(cash_flow.operating_revenue.values), 0,
         cash_flow.goods_sale_and_service_render_cash.values /
         cash_flow.operating_revenue.values)
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
Beispiel #12
0
 def financial_expense_rate_ttm(tp_contrarian, factor_contrarian):
     columns_list = ['financial_expense', 'total_operating_cost']
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['FinExpTTM'] = np.where(
         CalcTools.is_zero(contrarian['total_operating_cost']), 0,
         contrarian['financial_expense'] /
         contrarian['total_operating_cost'])
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
Beispiel #13
0
 def tax_ratio_ttm(tp_contrarian, factor_contrarian):
     columns_list = ['operating_tax_surcharges', 'operating_revenue']
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['TaxRTTM'] = np.where(
         CalcTools.is_zero(contrarian['operating_revenue']), 0,
         contrarian['operating_tax_surcharges'] /
         contrarian['operating_revenue'])
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
 def cfo_to_ev_ttm(ttm_cash_flow, factor_cash_flow):
     columns_list = [
         'net_operate_cash_flow', 'longterm_loan', 'shortterm_loan',
         'market_cap', 'cash_and_equivalents_at_end'
     ]
     cash_flow = ttm_cash_flow.loc[:, columns_list]
     cash_flow['OptToEnterpriseTTM'] = np.where(CalcTools.is_zero(
         cash_flow.longterm_loan.values + cash_flow.shortterm_loan.values + \
         cash_flow.market_cap.values - cash_flow.cash_and_equivalents_at_end.values), 0,
         cash_flow.net_operate_cash_flow.values / (cash_flow.longterm_loan.values + cash_flow.shortterm_loan.values + \
                                                   cash_flow.market_cap.values - cash_flow.cash_and_equivalents_at_end.values))
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
 def nocf_to_operating_ni_latest(tp_cash_flow, factor_cash_flow):
     columns_list = [
         'net_operate_cash_flow', 'total_operating_revenue',
         'total_operating_cost'
     ]
     cash_flow = tp_cash_flow.loc[:, columns_list]
     cash_flow['NOCFToOpt'] = np.where(
         CalcTools.is_zero((cash_flow.total_operating_revenue.values -
                            cash_flow.total_operating_cost.values)), 0,
         cash_flow.net_operate_cash_flow.values /
         (cash_flow.total_operating_revenue.values -
          cash_flow.total_operating_cost.values))
     cash_flow = cash_flow.drop(columns_list, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow, cash_flow, on="symbol")
     return factor_cash_flow
Beispiel #16
0
 def npcut_to_np(tp_earning, factor_earning):
     """
     扣除非经常损益后的净利润/净利润
     :param tp_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['adjusted_profit', 'net_profit']
     earning = tp_earning.loc[:, columns_list]
     earning['npcut_to_np'] = np.where(
         CalcTools.is_zero(earning.net_profit.values), 0,
         earning.adjusted_profit.values / earning.net_profit.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #17
0
 def roe_cut(tp_earning, factor_earning):
     """
     :param tp_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['adjusted_profit', 'equities_parent_company_owners']
     earning = tp_earning.loc[:, columns_list]
     earning['roe_cut'] = np.where(
         CalcTools.is_zero(earning.equities_parent_company_owners.values),
         0, earning.adjusted_profit.values /
         earning.equities_parent_company_owners.values / 4)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #18
0
 def operating_profit_ratio(ttm_earning, factor_earning):
     """
     营业净利率
     营业净利率=营业利润/营业收入
     :param ttm_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['operating_profit', 'operating_revenue']
     earning = ttm_earning.loc[:, columns_list]
     earning['operating_profit_ratio'] = np.where(
         CalcTools.is_zero(earning.operating_revenue.values), 0,
         earning.operating_profit.values / earning.operating_revenue.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #19
0
 def np_to_tor(ttm_earning, factor_earning):
     """
     净利润与营业总收入之比
     净利润与营业总收入之比=净利润/营业总收入
     :param ttm_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['net_profit', 'total_operating_revenue']
     earning = ttm_earning.loc[:, columns_list]
     earning['np_to_tor'] = np.where(
         CalcTools.is_zero(earning.total_operating_revenue.values), 0,
         earning.net_profit.values / earning.total_operating_revenue.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #20
0
 def roe5(ttm_earning_5y, factor_earning):
     """
     5年权益回报率
     :param ttm_earning_5y:
     :param factor_earning:
     :return:
     """
     columns_list = ['net_profit', 'total_owner_equities']
     earning = ttm_earning_5y.loc[:, columns_list]
     earning['roe5'] = np.where(
         CalcTools.is_zero(earning.total_owner_equities.values), 0,
         earning.net_profit.values / earning.total_owner_equities.values /
         4)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #21
0
 def invest_r_associates_to_tp_latest(tp_earning, factor_earning):
     """
     对联营和营公司投资收益/利润总额
     :param tp_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['invest_income_associates', 'total_profit']
     earning = tp_earning.loc[:, columns_list]
     earning['invest_r_associates_to_tp_latest'] = np.where(
         CalcTools.is_zero(earning.total_profit.values), 0,
         earning.invest_income_associates.values /
         earning.total_profit.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #22
0
 def roa(ttm_earning, factor_earning):
     """
     资产回报率
     资产回报率=净利润/总资产
     :param ttm_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['net_profit', 'total_assets']
     earning = ttm_earning.loc[:, columns_list]
     earning['roa'] = np.where(
         CalcTools.is_zero(earning.total_assets.values), 0,
         earning.net_profit.values / earning.total_assets.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #23
0
 def debt_tangible_equity_ratio_latest(tp_contrarian, factor_contrarian):
     columns_list = [
         'total_liability', 'total_current_liability', 'fixed_assets'
     ]
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['DTE'] = np.where(
         CalcTools.is_zero(contrarian['total_current_liability'] +
                           contrarian['fixed_assets']), 0,
         contrarian['total_current_liability'] /
         (contrarian['total_current_liability'] +
          contrarian['fixed_assets']))
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
Beispiel #24
0
 def period_costs_rate_ttm(tp_contrarian, factor_contrarian):
     columns_list = [
         'financial_expense', 'sale_expense', 'administration_expense',
         'operating_revenue'
     ]
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['PeridCostTTM'] = np.where(
         CalcTools.is_zero(contrarian['operating_revenue']), 0,
         (contrarian['financial_expense'] + contrarian['sale_expense'] + contrarian['administration_expense']) / \
         contrarian['operating_revenue']
     )
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
Beispiel #25
0
 def gross_income_ratio(ttm_earning, factor_earning):
     """
     销售毛利率
     销售毛利率=(营业收入-营业成本)/营业收入
     :param ttm_earning:
     :param factor_earning:
     :return:
     """
     columns_list = ['operating_revenue', 'operating_cost']
     earning = ttm_earning.loc[:, columns_list]
     earning['gross_income_ratio'] = np.where(
         CalcTools.is_zero(earning.operating_revenue.values), 0,
         (earning.operating_revenue.values - earning.operating_cost.values)
         / earning.operating_revenue.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #26
0
    def cetop(tp_historical_value, factor_historical_value):
        """
        # 经营活动产生的现金流量净额与市值比
        :param tp_historical_value:
        :param factor_historical_value:
        :return:
        """
        columns_lists = ['symbol', 'net_operate_cash_flow', 'market_cap']
        historical_value = tp_historical_value.loc[:, columns_lists]

        historical_value['CEToPTTM'] = np.where(CalcTools.is_zero(historical_value['market_cap']), 0,
                                                                  historical_value['net_operate_cash_flow'] /
                                                                  historical_value['market_cap'])

        historical_value = historical_value.drop(columns=['net_operate_cash_flow', 'market_cap'], axis=1)
        factor_historical_value = pd.merge(factor_historical_value, historical_value, on="symbol")

        return factor_historical_value
Beispiel #27
0
    def peg_5y(tp_historical_value, factor_historical_value):
        """
        # 市盈率/归属于母公司所有者净利润 5 年复合增长率
        :param tp_historical_value:
        :param factor_historical_value:
        :return:
        """
        columns_lists = ['symbol', 'pe', 'np_parent_company_owners', 'np_parent_company_owners_5']
        historical_value = tp_historical_value.loc[:, columns_lists]

        tmp = np.where(CalcTools.is_zero(historical_value['np_parent_company_owners_5']), 0,
                       (historical_value['np_parent_company_owners'] / historical_value['np_parent_company_owners_5']))
        historical_value['PEG5YChgTTM'] = tmp / abs(tmp) * pow(abs(tmp), 1 / 5.0) - 1

        historical_value = historical_value.drop(
            columns=['pe', 'np_parent_company_owners', 'np_parent_company_owners_5'], axis=1)
        factor_historical_value = pd.merge(factor_historical_value, historical_value, on="symbol")
        return factor_historical_value
Beispiel #28
0
 def net_non_oi_to_tp_latest(tp_earning, factor_earning):
     """
     营业外收支净额/利润总额
     :param tp_earning:
     :param factor_earning:
     :return:
     """
     columns_list = [
         'total_profit', 'non_operating_revenue', 'non_operating_expense'
     ]
     earning = tp_earning.loc[:, columns_list]
     earning['net_non_oi_to_tp_latest'] = np.where(
         CalcTools.is_zero(earning.total_profit.values), 0,
         (earning.non_operating_revenue.values +
          earning.non_operating_expense.values) /
         earning.total_profit.values)
     earning = earning.drop(columns_list, axis=1)
     factor_earning = pd.merge(factor_earning, earning, on="symbol")
     return factor_earning
Beispiel #29
0
 def inte_bear_debt_to_total_capital_latest(tp_contrarian,
                                            factor_contrarian):
     columns_list = [
         'interest_bearing_liability', 'fixed_assets',
         'total_current_assets', 'total_current_liability'
     ]
     contrarian = tp_contrarian.loc[:, columns_list]
     contrarian['IntBDToCap'] = np.where(
         CalcTools.is_zero(contrarian['fixed_assets'] + contrarian['total_current_assets'] + \
                           contrarian['total_current_liability']), 0,
         contrarian['interest_bearing_liability'] / (contrarian['fixed_assets'] + \
                                                     contrarian['total_current_assets'] + contrarian[
                                                         'total_current_liability'])
     )
     contrarian = contrarian.drop(columns_list, axis=1)
     factor_contrarian = pd.merge(factor_contrarian,
                                  contrarian,
                                  on="symbol")
     return factor_contrarian
Beispiel #30
0
    def etop(tp_historical_value, factor_historical_value):
        """
        收益市值比
        # 收益市值比= 净利润/总市值
        :param tp_historical_value:
        :param factor_historical_value:
        :return:
        """
        columns_lists = ['symbol', 'net_profit', 'market_cap']
        historical_value = tp_historical_value.loc[:, columns_lists]

        historical_value['EarnToPrice'] = np.where(CalcTools.is_zero(historical_value['market_cap']),
                                                             0,
                                                             historical_value['net_profit'] /
                                                             historical_value['market_cap'])

        historical_value = historical_value.drop(columns=['net_profit', 'market_cap'], axis=1)
        factor_historical_value = pd.merge(factor_historical_value, historical_value, on="symbol")
        return factor_historical_value