Exemplo n.º 1
0
def calc_rotc(end_date):
    #end_date = context.now
    quarter = dao_u.get_report_quarter(end_date)
    q = query(
        financials.financial_indicator.ebit,
        financials.financial_indicator.net_working_capital,
        # financials.financial_indicator.working_capital,
        financials.balance_sheet.accts_receivable,
        financials.balance_sheet.other_accts_receivable,
        financials.balance_sheet.prepayment,
        financials.balance_sheet.inventory,
        financials.financial_indicator.non_interest_bearing_current_debt,
        financials.balance_sheet.long_term_equity_investment,
        financials.balance_sheet.net_fixed_assets
    )
    rotc_df = get_financials(q, quarter = quarter, interval = '1q')
    # rotc_df.fillna({'accts_receivable':0,'other_accts_receivable':0,'prepayment':0,'inventory':0,'non_interest_bearing_current_debt':0,'long_term_equity_investment':0}, inplace=True)

    # shengqigongshi 版
    # 净营运资本 = 应收账款 + 其他应收款 + 预付账款 + 存货 - 无息流动负债 + 长期股权投资
    rotc_df['tangible_capital_2'] = rotc_df['accts_receivable'] + rotc_df['other_accts_receivable'] + rotc_df['prepayment'] + rotc_df['inventory'] - rotc_df['non_interest_bearing_current_debt'] + rotc_df['long_term_equity_investment'] + rotc_df['net_fixed_assets']
    # 海外版
    rotc_df['tangible_capital'] = rotc_df['net_working_capital'] + rotc_df['net_fixed_assets']

    # rotc_df['rotc'] = rotc_df['ebit']/rotc_df['tc'] * 100
    rotc_df['rotc'] = list(map(_calc_rotc_1, rotc_df['ebit'], rotc_df['tangible_capital']))
    # 参考
    rotc_df['rotc_2'] = rotc_df['ebit']/rotc_df['tangible_capital_2'] * 100

    rotc_df.sort_values(by='rotc', ascending=False, inplace=True)
    rotc_df['score_1'] = range(1, len(rotc_df.index) + 1)

    rotc_df['rotc'] = list(map(_calc_rotc_2, rotc_df['ebit'], rotc_df['tangible_capital']))

    return rotc_df
Exemplo n.º 2
0
def _get_roa_roe_quarter_report(stocks, today, n_report_quarters, is_roa):
    quarter = dao_u.get_report_quarter(today)
    
    fin_df = get_financials(
        (query(financials.financial_indicator.annual_return_on_asset_net_profit) if is_roa else query(financials.financial_indicator.annual_return_on_equity))
        .filter(
            financials.stockcode.in_(stocks)
        ), quarter = quarter, interval = str(n_report_quarters) + 'q'
    )
    
    roe_list = []
    if len(stocks) == 1:
        roe_list.append(fin_df.mean())
    else:
        for s in stocks:
            roe_list.append(fin_df[s].mean())

    return pd.Series(roe_list, index = stocks)
Exemplo n.º 3
0
def get_market_pb(today=None, ignore_bank=False):
    if today == None:
        today = dao_u.get_last_date()
    quarter = dao_u.get_report_quarter(today)

    df_equity = get_financials(query(
        fundamentals.balance_sheet.equity_parent_company).filter(
            fundamentals.balance_sheet.equity_parent_company > 0),
                               quarter=quarter,
                               interval='1q')

    q = query(
        fundamentals.eod_derivative_indicator.market_cap,
        #fundamentals.eod_derivative_indicator.a_share_market_val,
        fundamentals.balance_sheet.equity_parent_company).filter(
            fundamentals.balance_sheet.equity_parent_company > 0)
    if ignore_bank:
        q = q.filter(
            sql.not_(
                fundamentals.eod_derivative_indicator.stockcode.in_(
                    BANK_STOCKS)))

    df_cap = get_fundamentals(q, entry_date=today, interval='1d')
    df_x = df_cap.iloc[:, 0]

    # fillna: how about df_x.combine_first(df_equity)? performance issue
    # df_x.combine_first(df_equity)
    null_equities = list(df_x[df_x['equity_parent_company'].isnull()].index)
    for s in null_equities:
        if hasattr(df_equity, s):
            df_x.ix[s, 'equity_parent_company'] = df_equity.ix[
                0, s]  #df_equity.ix[s,'equity_parent_company']

    df_x2 = df_x[df_x['market_cap'].notnull()]
    df_x2 = df_x2[df_x2['equity_parent_company'].notnull()]

    total_equity = df_x2['equity_parent_company'].sum()
    market_cap = df_x2['market_cap'].sum()
    return market_cap / total_equity
Exemplo n.º 4
0
def calc_ebit_to_ev(end_date):
    #end_date = context.now
    quarter = dao_u.get_report_quarter(end_date)
    q = query(
        financials.financial_indicator.ebit,
        financials.balance_sheet.minority_interest,
        financials.financial_indicator.interest_bearing_debt,
        financials.balance_sheet.total_liabilities,
        financials.financial_indicator.non_interest_bearing_current_debt,
        financials.financial_indicator.non_interest_bearing_non_current_debt,
        financials.balance_sheet.cash
    )
    yield_df = get_financials(q, quarter = quarter, interval = '1q')

    market_cap_df = get_fundamentals(
        query(
            fundamentals.eod_derivative_indicator.market_cap,
            fundamentals.eod_derivative_indicator.ev_2
        ), entry_date = end_date + datetime.timedelta(days=-1), interval = '1d')

    market_cap_df = market_cap_df.iloc[:,0]
    yield_df = pd.concat([yield_df, market_cap_df], axis=1)

    # shengqigongshi 版
    # interest_bearing_debt = total_liabilities - non_interest_bearing_current_debt - non_interest_bearing_non_current_debt
    yield_df['ev_my'] = yield_df['market_cap'] + yield_df['minority_interest'] + (yield_df['total_liabilities'] - yield_df['non_interest_bearing_current_debt'] - yield_df['non_interest_bearing_non_current_debt'])
    # # 长投版
    # yield_df['ev_my'] = yield_df['market_cap'] + yield_df['interest_bearing_debt'] - yield_df['cash']
    # # 海外版
    # yield_df['ev_my'] = yield_df['market_cap'] + yield_df['interest_bearing_debt']
    yield_df['yield'] = yield_df['ebit']/yield_df['ev_my'] * 100
    # RQ 的参考
    yield_df['yield_2'] = yield_df['ebit']/yield_df['ev_2']

    yield_df.sort_values(by='yield', ascending=False, inplace=True)
    yield_df['score_2'] = range(1, len(yield_df.index) + 1)

    return yield_df