コード例 #1
0
    def TNWorthToNDebt(
        tp_solvency,
        factor_solvency,
        dependencies=[
            'equities_parent_company_owners', 'intangible_assets',
            'development_expenditure', 'good_will', 'long_deferred_expense',
            'deferred_tax_assets', 'shortterm_loan',
            'non_current_liability_in_one_year', 'longterm_loan',
            'bonds_payable', 'interest_payable', 'cash_equivalents'
        ]):
        """
        :name:有形净值/净债务
        :desc:有形净值/净债务(MRQ)
        :unit:
        :view_dimension: 0.01
        """

        management = tp_solvency.loc[:, dependencies]
        management['ta'] = (management.equities_parent_company_owners -
                            management.intangible_assets -
                            management.development_expenditure -
                            management.good_will -
                            management.long_deferred_expense -
                            management.deferred_tax_assets)
        management['nd'] = (management.shortterm_loan +
                            management.non_current_liability_in_one_year +
                            management.longterm_loan +
                            management.bonds_payable +
                            management.interest_payable -
                            management.cash_equivalents)
        management['TNWorthToNDebt'] = np.where(
            CalcTools.is_zero(management.nd.values), 0,
            management.ta.values / management.nd.values)
        dependencies = dependencies + ['ta', 'nd']
        management = management.drop(dependencies, axis=1)
        factor_solvency = pd.merge(factor_solvency,
                                   management,
                                   how='outer',
                                   on="security_code")
        return factor_solvency
コード例 #2
0
    def LongDebtToAsset(
            tp_management,
            factor_management,
            dependencies=['total_non_current_liability', 'total_assets']):
        """
        :name: 长期负债与资产总计之比(MRQ)
        :desc: 非流动负债合计MRQ/资产总计MRQ
        :unit:
        :view_dimension: 0.01
        """

        management = tp_management.loc[:, dependencies]
        management['LongDebtToAsset'] = np.where(
            CalcTools.is_zero(management.total_assets.values), 0,
            management.total_non_current_liability.values /
            management.total_assets.values)
        management = management.drop(dependencies, axis=1)
        factor_management = pd.merge(factor_management,
                                     management,
                                     how='outer',
                                     on="security_code")
        return factor_management
コード例 #3
0
 def QuickRatio(tp_solvency,
                factor_solvency,
                dependencies=[
                    'total_current_assets', 'total_current_liability',
                    'inventories'
                ]):
     """
     :name:速动比率
     :desc:(流动资产合计-存货)/流动负债合计(MRQ)
     """
     management = tp_solvency.loc[:, dependencies]
     management['QuickRatio'] = np.where(
         CalcTools.is_zero(management.total_current_liability.values), 0,
         (management.total_current_assets.values -
          management.inventories.values) /
         management.total_current_liability.values)
     management = management.drop(dependencies, axis=1)
     factor_solvency = pd.merge(factor_solvency,
                                management,
                                how='outer',
                                on="security_code")
     return factor_solvency
コード例 #4
0
 def OPCToDebtTTM(ttm_solvency,
                  factor_solvency,
                  dependencies=[
                      'net_operate_cash_flow', 'total_current_liability_ttm'
                  ]):
     """
     :name:现金流债务比(TTM)
     :desc:经营活动现金净流量(TTM)/流动负债(MRQ)
     :unit:
     :view_dimension: 0.01
     """
     cash_flow = ttm_solvency.loc[:, dependencies]
     cash_flow['OPCToDebtTTM'] = np.where(
         CalcTools.is_zero(cash_flow.total_current_liability_ttm.values), 0,
         cash_flow.net_operate_cash_flow.values /
         cash_flow.total_current_liability_ttm.values)
     cash_flow = cash_flow.drop(dependencies, axis=1)
     factor_solvency = pd.merge(factor_solvency,
                                cash_flow,
                                how='outer',
                                on="security_code")
     return factor_solvency
コード例 #5
0
 def SalesServCashToOR(tp_cash_flow,
                       factor_cash_flow,
                       dependencies=[
                           'goods_sale_and_service_render_cash',
                           'operating_revenue'
                       ]):
     """
     :name: 销售商品和提供劳务收到的现金/营业收入
     :desc: 销售商品和提供劳务收到的现金/营业收入
     """
     cash_flow = tp_cash_flow.loc[:, dependencies]
     cash_flow['SalesServCashToOR'] = 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(dependencies, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow,
                                 cash_flow,
                                 how='outer',
                                 on="security_code")
     # factor_cash_flow['SalesServCashToOR'] = cash_flow['SalesServCashToOR']
     return factor_cash_flow
コード例 #6
0
 def OptOnReToAssetTTM(ttm_cash_flow,
                       factor_cash_flow,
                       dependencies=[
                           'net_operate_cash_flow', 'net_profit',
                           'total_assets'
                       ]):
     """
     :name:(经营活动产生的金流量净额(TTM)-净利润(TTM)) /总资产(TTM)
     :desc:(经营活动产生的金流量净额(TTM) - 净利润(TTM)) /总资产(TTM)
     """
     cash_flow = ttm_cash_flow.loc[:, dependencies]
     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(dependencies, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow,
                                 cash_flow,
                                 how='outer',
                                 on="security_code")
     # factor_cash_flow['OptOnReToAssetTTM'] = cash_flow['OptOnReToAssetTTM']
     return factor_cash_flow
コード例 #7
0
    def MktLev(tp_solvency,
               factor_solvency,
               dependencies=['total_non_current_liability', 'market_cap']):
        """
        :name:市场杠杆
        :desc:非流动负债合计MRQ/(非流动负债台计MRO+总市值)
        :unit:
        :view_dimension: 0.01
        """

        management = tp_solvency.loc[:, dependencies]
        management['MktLev'] = np.where(
            CalcTools.is_zero(management.market_cap.values), 0,
            management.total_non_current_liability.values /
            (management.total_non_current_liability.values +
             management.market_cap.values))
        management = management.drop(dependencies, axis=1)
        factor_solvency = pd.merge(factor_solvency,
                                   management,
                                   how='outer',
                                   on="security_code")
        return factor_solvency
コード例 #8
0
    def NonCurrAssetRatio(
            tp_management,
            factor_management,
            dependencies=['total_non_current_assets', 'total_assets']):
        """
        :name: 非流动资产比率(MRQ)
        :desc: 非流动资产/总资产*100%(MRQ)
        :unit:
        :view_dimension: 0.01
        """

        management = tp_management.loc[:, dependencies]
        management['NonCurrAssetRatio'] = np.where(
            CalcTools.is_zero(management.total_assets.values), 0,
            management.total_non_current_assets.values /
            management.total_assets.values)
        management = management.drop(dependencies, axis=1)
        factor_management = pd.merge(factor_management,
                                     management,
                                     how='outer',
                                     on="security_code")
        return factor_management
コード例 #9
0
 def OptCFToCurrLiabilityTTM(ttm_revenue_quanlity,
                             revenue_quality,
                             dependencies=[
                                 'net_operate_cash_flow_indirect',
                                 'total_current_liability'
                             ]):
     """
     :name: 经营活动产生的现金流量净额(TTM)/流动负债(TTM)
     :desc: 经营活动产生的现金流量净额(TTM)/流动负债(TTM)
     :unit:
     :view_dimension: 0.01
     """
     cash_flow = ttm_revenue_quanlity.loc[:, dependencies]
     cash_flow['OptCFToCurrLiabilityTTM'] = np.where(
         CalcTools.is_zero(cash_flow.total_current_liability.values), 0,
         cash_flow.net_operate_cash_flow_indirect.values /
         cash_flow.total_current_liability.values)
     cash_flow = cash_flow.drop(dependencies, axis=1)
     revenue_quality = pd.merge(revenue_quality,
                                cash_flow,
                                how='outer',
                                on="security_code")
     return revenue_quality
コード例 #10
0
 def OptToEnterpriseTTM(ttm_cash_flow,
                        factor_cash_flow,
                        dependencies=[
                            'net_operate_cash_flow', 'longterm_loan',
                            'shortterm_loan', 'market_cap',
                            'cash_and_equivalents_at_end'
                        ]):
     """
     :name: 经营活动产生的现金流量净额(TTM)/企业价值(TTM)
     :desc: 经营活动产生的现金流量净额(TTM)/(长期借款(TTM)+ 短期借款(TTM)+ 总市值 - 期末现金及现金等价物(TTM)
     """
     cash_flow = ttm_cash_flow.loc[:, dependencies]
     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(dependencies, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow,
                                 cash_flow,
                                 how='outer',
                                 on="security_code")
     return factor_cash_flow
コード例 #11
0
    def OptIncToEnterpriseValueTTM(valuation_sets, factor_historical_value, dependencies=['operating_revenue',
                                                                                           'shortterm_loan',
                                                                                           'longterm_loan',
                                                                                           'market_cap',
                                                                                           'cash_and_equivalents_at_end',
                                                                                           ]):
        """
        :name: 营业收入(TTM)/企业价值
        :desc: 企业价值= 长期借款+ 短期借款+ 总市值- 现金及现金等价物
        :unit:
        :view_dimension: 0.01
        """
        historical_value = valuation_sets.loc[:, dependencies]

        fuc = lambda x: x[1] + x[2] + x[3] - x[4]
        historical_value['temp'] = historical_value[dependencies].apply(fuc, axis=1)
        historical_value['OptIncToEnterpriseValueTTM'] = np.where(CalcTools.is_zero(historical_value['temp']), 0,
                                                                  historical_value['operating_revenue'] /
                                                                  historical_value['temp'])
        dependencies = dependencies + ['temp']
        historical_value = historical_value.drop(columns=dependencies, axis=1)
        factor_historical_value = pd.merge(factor_historical_value, historical_value, how='outer', on="security_code")
        return factor_historical_value
コード例 #12
0
 def LDebtToWCap(tp_solvency,
                 factor_solvency,
                 dependencies=[
                     'total_current_assets', 'total_current_liability',
                     'total_non_current_assets'
                 ]):
     """
     :name:长期负债与营运资金比率
     :desc:非流动负债合计/(流动资产合计-流动负债合计)
     """
     management = tp_solvency.loc[:, dependencies]
     management['LDebtToWCap'] = np.where(
         CalcTools.is_zero(management.total_current_assets.values -
                           management.total_current_liability.values), 0,
         management.total_non_current_assets.values /
         (management.total_current_assets.values -
          management.total_current_liability.values))
     management = management.drop(dependencies, axis=1)
     factor_solvency = pd.merge(factor_solvency,
                                management,
                                how='outer',
                                on="security_code")
     return factor_solvency
コード例 #13
0
    def CashRatioTTM(ttm_solvency,
                     factor_solvency,
                     dependencies=[
                         'cash_and_equivalents_at_end', 'total_current_assets'
                     ]):
        """
        :name:期末现金及现金等价物余额(TTM)/流动负债(TTM)
        :desc:期末现金及现金等价物余额(TTM)/流动负债(TTM)
        :unit:
        :view_dimension: 0.01
        """

        cash_flow = ttm_solvency.loc[:, dependencies]
        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(dependencies, axis=1)
        factor_solvency = pd.merge(factor_solvency,
                                   cash_flow,
                                   how='outer',
                                   on="security_code")
        return factor_solvency
コード例 #14
0
 def OptCFToCurrLiability(tp_solvency,
                          factor_solvency,
                          dependencies=[
                              'net_operate_cash_flow_mrq',
                              'total_current_liability'
                          ]):
     """
     :name:经营活动产生的现金流量净额(MRQ)/流动负债(MRQ)
     :desc:经营活动产生的现金流量净额(MRQ)/流动负债(MRQ)
     :unit:
     :view_dimension: 0.01
     """
     cash_flow = tp_solvency.loc[:, dependencies]
     cash_flow['OptCFToCurrLiability'] = np.where(
         CalcTools.is_zero(cash_flow.total_current_liability.values), 0,
         cash_flow.net_operate_cash_flow_mrq.values /
         cash_flow.total_current_liability.values)
     cash_flow = cash_flow.drop(dependencies, axis=1)
     factor_solvency = pd.merge(factor_solvency,
                                cash_flow,
                                how='outer',
                                on="security_code")
     return factor_solvency
コード例 #15
0
 def NetNonOIToTPTTM(ttm_revenue_quanlity,
                     revenue_quality,
                     dependencies=[
                         'total_profit', 'non_operating_revenue',
                         'non_operating_expense'
                     ]):
     """
     :name:营业外收支净额(TTM)/利润总额(TTM)
     :desc: 营业外收支净额(TTM)/利润总额(TTM)
     :unit:
     :view_dimension: 0.01
     """
     earning = ttm_revenue_quanlity.loc[:, dependencies]
     earning['NetNonOIToTPTTM'] = 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(dependencies, axis=1)
     revenue_quality = pd.merge(revenue_quality,
                                earning,
                                how='outer',
                                on="security_code")
     return revenue_quality
コード例 #16
0
 def NOCFToOpt(tp_cash_flow,
               factor_cash_flow,
               dependencies=[
                   'net_operate_cash_flow', 'total_operating_revenue',
                   'total_operating_cost'
               ]):
     """
     :name: 经营活动产生的现金流量净额/(营业总收入-营业总成本)
     :desc: 经营活动产生的现金流量净额/(营业总收入-营业总成本)
     """
     cash_flow = tp_cash_flow.loc[:, dependencies]
     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(dependencies, axis=1)
     factor_cash_flow = pd.merge(factor_cash_flow,
                                 cash_flow,
                                 how='outer',
                                 on="security_code")
     # factor_cash_flow['NOCFToOpt'] = cash_flow['NOCFToOpt']
     return factor_cash_flow
コード例 #17
0
    def FixAssetsRt(tp_management,
                    factor_management,
                    dependencies=[
                        'fixed_assets', 'construction_materials',
                        'constru_in_process', 'total_assets'
                    ]):
        """
        :name: 固定资产比率
        :desc: (固定资产*MRQ+工程物资MRQ+在建工程MRQ)/资产总计MRQ;分母为NAN的科目记为0
        """

        management = tp_management.loc[:, dependencies]
        management['FixAssetsRt'] = np.where(
            CalcTools.is_zero(management.total_assets.values), 0,
            (management.fixed_assets.values +
             management.construction_materials.values +
             management.constru_in_process.values) /
            management.total_assets.values)
        management = management.drop(dependencies, axis=1)
        factor_management = pd.merge(factor_management,
                                     management,
                                     how='outer',
                                     on="security_code")
        return factor_management
コード例 #18
0
 def DTE(tp_solvency,
         factor_solvency,
         dependencies=[
             'total_liability', 'total_current_liability',
             'fixed_assets_netbook'
         ]):
     """
     :name:有形净值债务率
     :desc:负债合计/有形净值(MRQ)
     :unit:
     :view_dimension: 0.01
     """
     contrarian = tp_solvency.loc[:, dependencies]
     contrarian['DTE'] = np.where(
         CalcTools.is_zero(contrarian['total_current_liability'] +
                           contrarian['fixed_assets_netbook']), 0,
         contrarian['total_current_liability'] /
         (contrarian['total_current_liability'] +
          contrarian['fixed_assets_netbook']))
     contrarian = contrarian.drop(dependencies, axis=1)
     factor_solvency = pd.merge(factor_solvency,
                                contrarian,
                                on="security_code")
     return factor_solvency
コード例 #19
0
 def InterestCovTTM(ttm_solvency,
                    factor_solvency,
                    dependencies=[
                        'total_profit', 'financial_expense',
                        'interest_income'
                    ]):
     """
     :name: 利息保障倍数
     :desc:息税前利润/利息费用,息税前利润=利润总额+利息费用,利息费用=利息支出-利息收入
     """
     earning = ttm_solvency.loc[:, dependencies]
     earning['InterestCovTTM'] = np.where(
         CalcTools.is_zero(earning.financial_expense.values -
                           earning.interest_income.values), 0,
         (earning.total_profit.values + earning.financial_expense.values -
          earning.interest_income.values) /
         (earning.financial_expense.values -
          earning.interest_income.values))
     earning = earning.drop(dependencies, axis=1)
     factor_solvency = pd.merge(factor_solvency,
                                earning,
                                how='outer',
                                on="security_code")
     return factor_solvency
コード例 #20
0
 def OperatingNIToTPTTM(ttm_revenue_quanlity,
                        revenue_quality,
                        dependencies=[
                            'total_operating_revenue',
                            'total_operating_cost', 'total_profit'
                        ]):
     """
     :name: 经营活动净收益/利润总额(TTM)
     :desc: 经营活动净收益(TTM)/利润总额(TTM)*100%(注,对于非金融企业 经营活动净收益=营业总收入-营业总成本; 对于金融企业 经营活动净收益=营业收入-公允价值变动损益-投资收益-汇兑损益-营业支出 此处以非金融企业的方式计算)
     :unit:
     :view_dimension: 0.01
     """
     earning = ttm_revenue_quanlity.loc[:, dependencies]
     earning['OperatingNIToTPTTM'] = np.where(
         CalcTools.is_zero(earning.total_profit.values), 0,
         (earning.total_operating_revenue.values -
          earning.total_operating_cost.values) /
         earning.total_profit.values)
     earning = earning.drop(dependencies, axis=1)
     revenue_quality = pd.merge(revenue_quality,
                                earning,
                                how='outer',
                                on="security_code")
     return revenue_quality