def revenue_y_gt_accounts_receive_3_years(): return expr.Or( expr.And( expr.Gt(expr.Get('f_revenue_y.y2y'), expr.Get('f_accounts_receiv_y.y2y')), expr.Gt( expr.Before(expr.Get('f_revenue_y.y2y'), past_year=1), expr.Before(expr.Get('f_accounts_receiv_y.y2y'), past_year=1))), expr.And( expr.Gt( expr.Before(expr.Get('f_revenue_y.y2y'), past_year=1), expr.Before(expr.Get('f_accounts_receiv_y.y2y'), past_year=1)), expr.Gt( expr.Before(expr.Get('f_revenue_y.y2y'), past_year=2), expr.Before(expr.Get('f_accounts_receiv_y.y2y'), past_year=2))), expr.And( expr.Gt( expr.Before(expr.Get('f_revenue_y.y2y'), past_year=2), expr.Before(expr.Get('f_accounts_receiv_y.y2y'), past_year=2)), expr.Gt( expr.Before(expr.Get('f_revenue_y.y2y'), past_year=3), expr.Before(expr.Get('f_accounts_receiv_y.y2y'), past_year=3))))
def accounts_receiv_ave_y(): '''平均应收账款''' return MetricsMeta( 'f_accounts_receiv_ave_y', expr.Div( expr.Sum( expr.Get('accounts_receiv', period='y'), expr.Before(expr.Get('accounts_receiv', period='y'), past_year=1), expr.Get('notes_receiv', period='y'), expr.Before(expr.Get('notes_receiv', period='y'), past_year=1)), expr.Value(2)))
def acct_payable_ave_y(): '''平均应付账款''' return MetricsMeta( 'f_acct_payable_ave_y', expr.Div( expr.Sum( expr.Get('acct_payable', period='y'), expr.Get('notes_payable', period='y'), expr.Before(expr.Get('acct_payable', period='y'), past_year=1), expr.Before(expr.Get('notes_payable', period='y'), past_year=1)), expr.Value(2)))
def net_profit_growth_pay_10_years_ratio(): '''10年净利润增长/10年资本开支比''' return MetricsMeta( 'f_n_income_attr_p_pay_10_y.r', expr.Div( expr.Sub( expr.Get('n_income_attr_p', period='y'), expr.Before(expr.Get('n_income_attr_p', period='y'), past_year=9)), expr.Sum(expr.Get('c_pay_acq_const_fiolta', period='y'), [ expr.Before(expr.Get('c_pay_acq_const_fiolta', period='y'), past_year=n) for n in range(1, 10) ])), display='10年净利润增长与资本开支比')
def cashflow_free_pay_10_years_ratio(): '''10年自由现金流/10年资本开支比''' return MetricsMeta( 'f_cashflow_free_pay_10_y.r', expr.Div( expr.Sum(expr.Get('f_cashflow_free_y'), [ expr.Before(expr.Get('f_cashflow_free_y'), past_year=n) for n in range(1, 10) ]), expr.Sum(expr.Get('c_pay_acq_const_fiolta', period='y'), [ expr.Before(expr.Get('c_pay_acq_const_fiolta', period='y'), past_year=n) for n in range(1, 10) ])), display='10年自由现金流与资本开支比')
def current_y_gt_1_3_years(): return expr.Or( expr.And( expr.Gt(expr.Get('f_current_y.r'), expr.Value(1)), expr.Gt(expr.Before(expr.Get('f_current_y.r'), past_year=1), expr.Value(1))), expr.And( expr.Gt(expr.Before(expr.Get('f_current_y.r'), past_year=1), expr.Value(1)), expr.Gt(expr.Before(expr.Get('f_current_y.r'), past_year=2), expr.Value(1))), expr.And( expr.Gt(expr.Before(expr.Get('f_current_y.r'), past_year=2), expr.Value(1)), expr.Gt(expr.Before(expr.Get('f_current_y.r'), past_year=3), expr.Value(1))))
def adv_receipts_ave_y(): '''平均预收账款''' return MetricsMeta( 'f_adv_receipts_ave_y', expr.Div( expr.Sum( expr.Get('adv_receipts', period='y'), expr.Before(expr.Get('adv_receipts', period='y'), past_year=1)), expr.Value(2)))
def prepayment_ave_y(): '''平均预付账款''' return MetricsMeta( 'f_prepayment_ave_y', expr.Div( expr.Sum( expr.Get('prepayment', period='y'), expr.Before(expr.Get('prepayment', period='y'), past_year=1)), expr.Value(2)))
def inventroy_ave_y(): '''平均存货''' return MetricsMeta( 'f_inventory_ave_y', expr.Div( expr.Sum( expr.Get('inventories', period='y'), expr.Before(expr.Get('inventories', period='y'), past_year=1)), expr.Value(2)))
def revenue_y_gt_inventoires_3_years(): return expr.Or( expr.And( expr.Gt(expr.Get('f_revenue_y.y2y'), expr.Get('f_inventories_y.y2y')), expr.Gt(expr.Before(expr.Get('f_revenue_y.y2y'), past_year=1), expr.Before(expr.Get('f_inventories_y.y2y'), past_year=1))), expr.And( expr.Gt(expr.Before(expr.Get('f_revenue_y.y2y'), past_year=1), expr.Before(expr.Get('f_inventories_y.y2y'), past_year=1)), expr.Gt(expr.Before(expr.Get('f_revenue_y.y2y'), past_year=2), expr.Before(expr.Get('f_inventories_y.y2y'), past_year=2))), expr.And( expr.Gt(expr.Before(expr.Get('f_revenue_y.y2y'), past_year=2), expr.Before(expr.Get('f_inventories_y.y2y'), past_year=2)), expr.Gt(expr.Before(expr.Get('f_revenue_y.y2y'), past_year=3), expr.Before(expr.Get('f_inventories_y.y2y'), past_year=3))))
def income_attr_p_ttm(): # 滚动净利润:最近连续4个季度 ttm_q3 = [expr.Before(expr.Get('n_income_attr_p', increment=True, var_type='f'), past_quarter=i) for i in range(1, 4)] return MetricsMeta('f_income_attr_p_ttm', expr.Sum(expr.Get('n_income_attr_p', increment=True, var_type='f'), ttm_q3))
def run(y, q): rm = expr.Range(expr.Before(expr.Get('f_roe_y'), past_year=1), year_count=6) nm = self.roe_ge_15_pct_now() v = rm.eval(self.stock, y, 4) v2 = expr.Ge(rm, expr.Value(0.15)).eval(self.stock, y, 4) print('last 6 years', v, v2) v3 = nm.eval(self.stock, y, q) print('current', v3, expr.Get('f_roe').eval(self.stock, y, q)) v4 = expr.And(expr.Ge(rm, expr.Value(0.15)), nm).eval(self.stock, y, q) print('last 7 years', v4)
def roe_ttm(): ''' 年度ROE(加权平均) 根据中国证监会发布的《公开发行证券公司信息披露编报规则》第9号的通知的规定:加权平均净资产收益率(ROE)的计算公式如下:ROE= P/(E0 + NP÷2 + Ei×Mi÷M0 - Ej×Mj÷M0) 其中: P为报告期利润; NP为报告期净利润; E0为期初净资产; Ei为报告期发行新股或债转股等新增净资产; Ej为报告期回购或现金分红等减少净资产; M0为报告期月份数; Mi为新增净资产下一月份起至报告期期末的月份数; Mj为减少净资产下一月份起至报告期期末的月份数。 ''' return MetricsMeta('f_roe_ttm', expr.Div( expr.Get('f_income_attr_p_ttm'), expr.Div( expr.Sum( expr.Get('total_hldr_eqy_exc_min_int'), expr.Before( expr.Get('total_hldr_eqy_exc_min_int'), past_quarter=4)), expr.Value(2))), display='ROE(滚动)')
def last_year_f_revenue_y_r_y2y(): return expr.Before(expr.Get('f_revenue_y.r_y2y'), past_year=1)
def roe_ge_15_pct_before_6_years(): return expr.Ge( expr.Range(expr.Before(expr.Get('f_roe_y'), past_year=1), year_count=6), expr.Value(0.15))