def _DGPR(ttm_earning, ttm_earning_p1y, factor_earning, dependencies=['operating_revenue', 'operating_cost']): """ 毛利率增长率,与去年同期相比 :name: :desc: """ earning = ttm_earning.loc[:, dependencies] earning_p1y = ttm_earning_p1y.loc[:, dependencies] 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["DGPR"] = earning["gross_income_ratio"] - earning_p1y[ "gross_income_ratio"] dependencies = dependencies + ['gross_income_ratio'] earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def DGPR(tp_earning, factor_earning, dependencies=['operating_revenue', 'operating_cost', 'operating_revenue_pre_year_1', 'operating_cost_1y']): """ 毛利率增长率TTM,与去年同期相比 :name:毛利率增长率 :desc:毛利率增长率,与去年同期相比 :unit: :view_dimension: 0.01 """ earning = tp_earning.loc[:, dependencies] 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['gross_income_ratio_1y'] = np.where( CalcTools.is_zero(earning.operating_revenue_1y.values), 0, (earning.operating_revenue_1y.values - earning.operating_cost_1y.values) / earning.operating_revenue_1y.values) func = lambda x: x[0] - x[1] / abs(x[1]) if x[1] is not None and x[1] != 0 and x[0] is not None else None earning['DGPR'] = earning[['gross_income_ratio', 'gross_income_ratio_1y']].apply(func, axis=1) dependencies = dependencies + ['gross_income_ratio', 'gross_income_ratio_1y'] earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def EquityToFixedAsset(tp_management, factor_management, dependencies=[ 'total_owner_equities', 'fixed_assets', 'construction_materials', 'constru_in_process' ]): """ :name: 股东权益与固定资产比率 :desc: 股东权益MRQ/(固定资产MRQ+工程物资MRQ+在建工程MRQ)分子为NAN的科目记为0 """ management = tp_management.loc[:, dependencies] management['EquityToFixedAsset'] = np.where( CalcTools.is_zero(management.fixed_assets.values + management.construction_materials.values + management.constru_in_process.values), 0, management.total_owner_equities.values / (management.fixed_assets.values + management.construction_materials.values + management.constru_in_process.values)) management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") return factor_management
def ARRateTTM(ttm_management, factor_management, dependencies=[ 'operating_revenue', 'account_receivable', 'bill_receivable', 'advance_peceipts' ]): """ :name:应收账款周转率(TTM) :desc:营业收入/(应收账款+应收票据-预收账款) """ management = ttm_management.loc[:, dependencies] management['ar'] = (management.account_receivable + management.bill_receivable - management.advance_peceipts) / 4 management['ARRateTTM'] = np.where( CalcTools.is_zero(management.ar.values), 0, management.operating_revenue.values / management.ar.values) dependencies = dependencies + ['ar'] management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") # factor_management['ARRateTTM'] = management['ARRateTTM'] return factor_management
def LDebtToWCap(tp_solvency, factor_solvency, dependencies=[ 'total_current_assets', 'total_current_liability', 'total_non_current_assets' ]): """ :name:长期负债与营运资金比率as :desc:非流动负债合计/(流动资产合计-流动负债合计) :unit: :view_dimension: 0.01 """ 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
def FixAssetsRtTTM(ttm_management, factor_management, dependencies=[ 'operating_revenue', 'fixed_assets', 'construction_materials', 'constru_in_process' ]): """ :name: 固定资产周转率(TTM) :desc: 营业收入/(固定资产+工程物资+在建工程) """ management = ttm_management.loc[:, dependencies] management['fa'] = (management.fixed_assets + management.construction_materials + management.constru_in_process) management['FixAssetsRtTTM'] = np.where( CalcTools.is_zero(management.fa.values), 0, management.operating_revenue.values / management.fa.values * 4) dependencies = dependencies + ['fa'] management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") # factor_management['FixAssetsRtTTM'] = management['FixAssetsRtTTM'] return factor_management
def IntBDToCap(tp_solvency, factor_solvency, dependencies=[ 'shortterm_loan', 'non_current_liability_in_one_year', 'longterm_loan', 'bonds_payable', 'interest_payable', 'fixed_assets', 'total_current_assets', 'total_current_liability' ]): """ :name:带息负债/全部投入资本 :desc:带息债务/全部投入资本*100%(MRQ) """ contrarian = tp_solvency.loc[:, dependencies] contrarian['interest_bearing_liability'] = contrarian['shortterm_loan'] + \ contrarian['non_current_liability_in_one_year'] + \ contrarian['longterm_loan'] + \ contrarian['bonds_payable'] + contrarian['interest_payable'] 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']) ) dependencies = dependencies + ['interest_bearing_liability'] contrarian = contrarian.drop(dependencies, axis=1) factor_solvency = pd.merge(factor_solvency, contrarian, how='outer', on="security_code") return factor_solvency
def OptCFToIBDTTM(ttm_solvency, factor_solvency, dependencies=[ 'net_operate_cash_flow', 'shortterm_loan', 'non_current_liability_in_one_year_ttm', 'longterm_loan', 'bonds_payable', 'interest_payable' ]): """ :name:经营活动净现金流(TTM)/带息负债(TTM) :desc:经营活动净现金流(TTM)/带息负债(TTM) """ cash_flow = ttm_solvency.loc[:, dependencies] cash_flow['interest_bearing_liability'] = cash_flow['shortterm_loan'] + \ cash_flow['non_current_liability_in_one_year_ttm'] + \ cash_flow['longterm_loan'] + \ cash_flow['bonds_payable'] + cash_flow['interest_payable'] cash_flow['OptCFToIBDTTM'] = np.where( CalcTools.is_zero(cash_flow.interest_bearing_liability.values), 0, cash_flow.net_operate_cash_flow.values / cash_flow.interest_bearing_liability.values) dependencies = dependencies + ['interest_bearing_liability'] cash_flow = cash_flow.drop(dependencies, axis=1) factor_solvency = pd.merge(factor_solvency, cash_flow, how='outer', on="security_code") return factor_solvency
def EquityPCToTCap(tp_solvency, factor_solvency, dependencies=[ 'equities_parent_company_owners', 'total_owner_equities', 'shortterm_loan', 'non_current_liability_in_one_year', 'longterm_loan', 'bonds_payable', 'interest_payable' ]): """ :name:归属母公司股东的权益/全部投入资本 (补充 全部投入资本=所有者权益合计+带息债务) :desc: 归属母公司股东的权益/全部投入资本 (补充 全部投入资本=所有者权益合计+带息债务) """ management = tp_solvency.loc[:, dependencies] management["tc"] = (management.total_owner_equities + management.shortterm_loan + management.non_current_liability_in_one_year + management.longterm_loan + management.bonds_payable + management.interest_payable) management['EquityPCToTCap'] = np.where( CalcTools.is_zero(management.tc.values), 0, management.equities_parent_company_owners.values / management.tc.values) dependencies = dependencies + ['tc'] management = management.drop(dependencies, axis=1) factor_solvency = pd.merge(factor_solvency, management, how='outer', on="security_code") return factor_solvency
def FixAssetsRt(tp_management, factor_management, dependencies=[ 'fixed_assets_netbook', 'construction_materials', 'constru_in_process', 'total_assets' ]): """ :name: 固定资产比率(MRQ) :desc: (固定资产*MRQ+工程物资MRQ+在建工程MRQ)/资产总计MRQ;分母为NAN的科目记为0 :unit: :view_dimension: 0.01 """ management = tp_management.loc[:, dependencies] management['FixAssetsRt'] = np.where( CalcTools.is_zero(management.total_assets.values), 0, (management.fixed_assets_netbook.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
def AccPayablesDaysTTM(ttm_management, factor_management, dependencies=[ 'operating_cost', 'accounts_payable', 'notes_payable', 'advance_payment' ]): """ :name:应付账款周转天数(TTM) :desc:360/应付账款周转率 """ management = ttm_management.loc[:, dependencies] management['ap'] = (management.accounts_payable + management.notes_payable - management.advance_payment) / 4 management['AccPayablesDaysTTM'] = np.where( CalcTools.is_zero(management.ap.values), 0, 360 / management.operating_cost.values * management.ap.values) dependencies = dependencies + ['ap'] management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") # factor_management['AccPayablesDaysTTM'] = management['AccPayablesDaysTTM'] return factor_management
def TotaProfRtTTM(ttm_earning, factor_earning, dependencies=[ 'total_profit', 'operating_cost', 'financial_expense', 'sale_expense', 'administration_expense' ]): """ :name:成本费用利润率(TTM) :desc: 利润总额 / (营业成本+财务费用+销售费用+管理费用)*100 """ constrains = ttm_earning.loc[:, dependencies] constrains['cost'] = (constrains.operating_cost + constrains.financial_expense + constrains.sale_expense + constrains.administration_expense) constrains['TotaProfRtTTM'] = np.where( CalcTools.is_zero(constrains['cost']), 0, constrains['total_profit'] / constrains['cost']) dependencies = dependencies + ['cost'] constrains = constrains.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, constrains, how='outer', on="security_code") return factor_earning
def IntangibleAssetRatio(tp_management, factor_management, dependencies=[ 'intangible_assets', 'development_expenditure', 'good_will', 'total_assets' ]): """ 无形资产比率 无形资产比率 = (无形资产 + 研发支出 + 商誉)/ 总资产 :name: 无形资产比率 :desc:(无形资产MRQ+开发支出MRQ+商誉MRQ)/资产总计MRQ 分母为NAN的科目记为0 """ management = tp_management.loc[:, dependencies] management["ia"] = (management.intangible_assets + management.development_expenditure + management.good_will) management['IntangibleAssetRatio'] = np.where( CalcTools.is_zero(management.total_assets.values), 0, management.ia.values / management.total_assets.values) dependencies = dependencies + ['ia'] management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") # factor_management['IntangibleAssetRatio'] = management['IntangibleAssetRatio'] return factor_management
def AccPayablesRateTTM(ttm_management, factor_management, dependencies=[ 'operating_cost', 'accounts_payable', 'notes_payable', 'advance_payment' ]): """ :name: 应付账款周转率(TTM) :desc: 营业成本/(应付账款+应付票据-预付账款) :unit: :view_dimension: 0.01 """ management = ttm_management.loc[:, dependencies] management['ap'] = (management.accounts_payable + management.notes_payable - management.advance_payment) / 4 management['AccPayablesRateTTM'] = np.where( CalcTools.is_zero(management.ap.values), 0, management.operating_cost.values / management.ap.values) dependencies = dependencies + ['ap'] management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") # factor_management['AccPayablesRateTTM'] = management['AccPayablesRateTTM'] return factor_management
def ARDaysTTM(ttm_management, factor_management, dependencies=[ 'operating_revenue', 'bill_receivable', 'account_receivable', 'advance_peceipts' ]): """ :name:应收账款周转天数(TTM) :desc:360/应收账款周转率 :unit: 天 :view_dimension: 1 """ management = ttm_management.loc[:, dependencies] management['ar'] = (management.account_receivable + management.bill_receivable - management.advance_peceipts) / 4 management['ARDaysTTM'] = np.where( CalcTools.is_zero(management.operating_revenue.values), 0, 360 / management.operating_revenue.values * management.ar.values) dependencies = dependencies + ['ar'] management = management.drop(dependencies, axis=1) factor_management = pd.merge(factor_management, management, how='outer', on="security_code") # factor_management['ARDaysTTM'] = management['ARDaysTTM'] return factor_management
def OptIncToEnterpriseValueTTM(valuation_sets, factor_historical_value, dependencies=[ 'operating_revenue', 'shortterm_loan', 'longterm_loan', 'market_cap', 'cash_and_equivalents_at_end', ]): """ :name: 营业收入(TTM)/企业价值 :desc: 企业价值= 长期借款+ 短期借款+ 总市值- 现金及现金等价物 """ 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
def TotalAssetsToEnterpriseValue(valuation_sets, factor_historical_value, dependencies=[ 'total_assets_report', 'shortterm_loan', 'longterm_loan', 'market_cap', 'cash_and_equivalents_at_end', ]): """ :name: 资产总计/企业价值 MRQ :desc: 资产总计/企业价值 MRQ """ 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['TotalAssetsToEnterpriseValue'] = np.where( CalcTools.is_zero(historical_value['temp']), 0, historical_value['total_assets_report'] / historical_value['temp']) dependencies = dependencies + ['temp'] historical_value = historical_value.drop(dependencies, axis=1) factor_historical_value = pd.merge(factor_historical_value, historical_value, how='outer', on="security_code") return factor_historical_value
def PEG3YChgTTM(valuation_sets, factor_historical_value, dependencies=[ 'pe', 'np_parent_company_owners', 'np_parent_company_owners_3' ]): """ :name: PEG3 年复合增长率(TTM) :desc: 市盈率/归属于母公司所有者净利润 3 年复合增长率 """ historical_value = valuation_sets.loc[:, dependencies] tmp = np.where( CalcTools.is_zero(historical_value['np_parent_company_owners_3']), 0, (historical_value['np_parent_company_owners'] / historical_value['np_parent_company_owners_3'])) historical_value['PEG3YChgTTM'] = tmp / abs(tmp) * pow( abs(tmp), 1 / 3.0) - 1 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
def SupQuickRatio(tp_solvency, factor_solvency, dependencies=[ 'cash_equivalents', 'trading_assets', 'bill_receivable', 'account_receivable', 'other_receivable', 'total_current_liability' ]): """ :name:超速动比率 :desc:(货币资金+交易性金融资资产+应收票据+应收帐款+其他应收款)/流动负债合计(MRQ) """ management = tp_solvency.loc[:, dependencies] management['SupQuickRatio'] = np.where( CalcTools.is_zero(management.total_current_liability.values), 0, (management.cash_equivalents.values + management.trading_assets.values + management.bill_receivable.values + management.account_receivable.values + management.other_receivable.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
def EquityPCToIBDebt(tp_solvency, factor_solvency, dependencies=[ 'equities_parent_company_owners', 'shortterm_loan', 'non_current_liability_in_one_year', 'longterm_loan', 'bonds_payable', 'interest_payable' ]): """ :name:归属母公司股东的权益/带息负债 :desc:归属母公司股东的权益/带息负债(补充 带息负债 = 短期借款+一年内到期的长期负债+长期借款+应付债券+应付利息) """ management = tp_solvency.loc[:, dependencies] management["debt"] = (management.shortterm_loan + management.non_current_liability_in_one_year + management.longterm_loan + management.bonds_payable + management.interest_payable) management['EquityPCToIBDebt'] = np.where( CalcTools.is_zero(management.debt.values), 0, management.equities_parent_company_owners.values / management.debt.values) dependencies = dependencies + ['debt'] management = management.drop(dependencies, axis=1) factor_solvency = pd.merge(factor_solvency, management, how='outer', on="security_code") return factor_solvency
def OptCFToCurrLiabilityTTM(ttm_revenue_quanlity, revenue_quality, dependencies=['net_operate_cash_flow', 'total_current_liability']): """ :name: 经营活动产生的现金流量净额(TTM)/流动负债(TTM) :desc: 经营活动产生的现金流量净额(TTM)/流动负债(TTM) """ 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.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
def NetProfitRtTTM(ttm_earning, factor_earning, dependencies=['net_profit', 'operating_revenue']): """ :name: 销售净利率(TTM) :desc: 净利润/营业收入 :unit: :view_dimension: 0.01 """ earning = ttm_earning.loc[:, dependencies] earning['NetProfitRtTTM'] = np.where( CalcTools.is_zero(earning.operating_revenue.values), 0, earning.net_profit.values / earning.operating_revenue.values) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def OwnROETTM(ttm_earning, factor_earning, dependencies=['net_profit', 'total_owner_equities']): """ :name: 权益回报率(TTM) :desc: 净利润/股东权益 :unit: :view_dimension: 0.01 """ earning = ttm_earning.loc[:, dependencies] earning['OwnROETTM'] = np.where( CalcTools.is_zero(earning.total_owner_equities.values), 0, earning.net_profit.values / earning.total_owner_equities.values / 4) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def ROA5YChg(ttm_earning_5y, factor_earning, dependencies=['net_profit', 'total_assets']): """ :name: 5年资产回报率 :desc: 5年收益关于时间(年)进行线性回归的回归系数/(5年收益均值的绝对值)对于上市新股以上市前已披露的3年净利润计算之后新的年报数据披露后再计算四年、五年的收益增长率数据每年变化一次,在年报披露日 """ earning = ttm_earning_5y.loc[:, dependencies] earning['ROA5YChg'] = np.where( CalcTools.is_zero(earning.total_assets.values), 0, earning.net_profit.values / earning.total_assets.values / 4) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def NPCutToNP(tp_earning, factor_earning, dependencies=['adjusted_profit', 'net_profit']): """ :name: 扣除非经常损益后的净利润/净利润 :desc: 扣除非经常损益后的净利润/净利润 """ earning = tp_earning.loc[:, dependencies] earning['NPCutToNP'] = np.where( CalcTools.is_zero(earning.net_profit.values), 0, earning.adjusted_profit.values / earning.net_profit.values) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def NPToTORevTTM(ttm_earning, factor_earning, dependencies=['net_profit', 'total_operating_revenue']): """ :name: 净利润与营业总收入之比(TTM) :desc: 净利润/营业总收入 """ earning = ttm_earning.loc[:, dependencies] earning['NPToTORevTTM'] = np.where( CalcTools.is_zero(earning.total_operating_revenue.values), 0, earning.net_profit.values / earning.total_operating_revenue.values) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def OptProfitRtTTM(ttm_earning, factor_earning, dependencies=['operating_profit', 'operating_revenue']): """ :name: 营业净利率(TTM) :desc: 营业利润/营业收入 """ earning = ttm_earning.loc[:, dependencies] earning['OptProfitRtTTM'] = np.where( CalcTools.is_zero(earning.operating_revenue.values), 0, earning.operating_profit.values / earning.operating_revenue.values) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning
def OperatingNIToTP(tp_revenue_quanlity, revenue_quality, dependencies=['total_operating_revenue', 'total_operating_cost', 'total_profit']): """ :name: 经营活动净收益/利润总额 :desc:(注,对于非金融企业 经营活动净收益=营业总收入-营业总成本; 对于金融企业 经营活动净收益=营业收入-公允价值变动损益-投资收益-汇兑损益-营业支出 此处以非金融企业的方式计算) """ earning = tp_revenue_quanlity.loc[:, dependencies] earning['OperatingNIToTP'] = 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
def DA(tp_solvency, factor_solvency, dependencies=['total_liability', 'total_assets']): """ :name: 债务总资产比 :desc:负债合计MRQ/资产总计MRQ :unit: :view_dimension: 0.01 """ contrarian = tp_solvency.loc[:, dependencies] contrarian['DA'] = np.where( CalcTools.is_zero(contrarian['total_assets']), 0, contrarian['total_liability'] / contrarian['total_assets']) contrarian = contrarian.drop(dependencies, axis=1) factor_solvency = pd.merge(factor_solvency, contrarian, on="security_code") return factor_solvency
def _operating_profit_to_tor(ttm_earning, factor_earning, dependencies=['operating_profit', 'total_operating_revenue']): """ :name: 营业利润与营业总收入之比 :desc: 营业利润/营业总收入 :unit: :view_dimension: 0.01 """ earning = ttm_earning.loc[:, dependencies] earning['operating_profit_to_tor'] = np.where( CalcTools.is_zero(earning.total_operating_revenue.values), 0, earning.operating_profit.values / earning.total_operating_revenue.values) earning = earning.drop(dependencies, axis=1) factor_earning = pd.merge(factor_earning, earning, on="security_code") return factor_earning