예제 #1
0
 def get_income_data(provider: Provider, sleep, desc, pc, lock, region,
                     batch):
     # 收益表
     IncomeStatement.record_data(provider=provider,
                                 share_para=(desc, pc, lock, True, region),
                                 sleeping_time=sleep,
                                 batch_size=batch)
예제 #2
0
def risky_company(region: Region,
                  the_date=None,
                  income_yoy=-0.1,
                  profit_yoy=-0.1,
                  entity_ids=None):
    if not the_date:
        the_date = to_pd_timestamp(now_time_str(region))

    codes = []
    start_timestamp = to_pd_timestamp(the_date) - datetime.timedelta(130)
    # 营收降,利润降,流动比率低,速动比率低
    finance_filter = or_(FinanceFactor.op_income_growth_yoy < income_yoy,
                         FinanceFactor.net_profit_growth_yoy <= profit_yoy,
                         FinanceFactor.current_ratio < 0.7,
                         FinanceFactor.quick_ratio < 0.5)
    df = FinanceFactor.query_data(region=region,
                                  entity_ids=entity_ids,
                                  start_timestamp=start_timestamp,
                                  filters=[finance_filter],
                                  columns=['code'])
    if pd_is_not_null(df):
        codes = codes + df.code.tolist()

    # 高应收,高存货,高商誉
    balance_filter = (BalanceSheet.accounts_receivable + BalanceSheet.inventories + BalanceSheet.goodwill) \
                     > BalanceSheet.total_equity
    df = BalanceSheet.query_data(region=region,
                                 entity_ids=entity_ids,
                                 start_timestamp=start_timestamp,
                                 filters=[balance_filter],
                                 columns=['code'])
    if pd_is_not_null(df):
        codes = codes + df.code.tolist()

    # 应收>利润*1/2
    df1 = BalanceSheet.query_data(
        region=region,
        entity_ids=entity_ids,
        start_timestamp=start_timestamp,
        columns=[BalanceSheet.code, BalanceSheet.accounts_receivable])
    if pd_is_not_null(df1):
        df1.drop_duplicates(subset='code', keep='last', inplace=True)
        df1 = df1.set_index('code', drop=True).sort_index()

    df2 = IncomeStatement.query_data(
        region=region,
        entity_ids=entity_ids,
        start_timestamp=start_timestamp,
        columns=[IncomeStatement.code, IncomeStatement.net_profit])
    if pd_is_not_null(df2):
        df2.drop_duplicates(subset='code', keep='last', inplace=True)
        df2 = df2.set_index('code', drop=True).sort_index()

    if pd_is_not_null(df1) and pd_is_not_null(df2):
        codes = codes + df1[df1.accounts_receivable > df2.net_profit /
                            2].index.tolist()

    return list(set(codes))
예제 #3
0
def test_000001_income_statement():
    correct_timestamps = [
        '2018-09-30', '2018-06-30', '2018-03-31', '2017-12-31', '2017-09-30',
        '2017-06-30', '2017-03-31', '2016-12-31', '2016-09-30', '2016-06-30',
        '2016-03-31', '2015-12-31', '2015-09-30', '2015-06-30', '2015-03-31',
        '2014-12-31', '2014-09-30', '2014-06-30', '2014-03-31', '2013-12-31',
        '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31', '2012-09-30',
        '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30',
        '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31',
        '2009-12-31', '2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31',
        '2008-09-30', '2008-06-30', '2008-03-31', '2007-12-31', '2007-09-30',
        '2007-06-30', '2007-03-31', '2006-12-31', '2006-09-30', '2006-06-30',
        '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30', '2005-03-31',
        '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31',
        '2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30',
        '2002-06-30', '2002-03-31', '2001-12-31', '2001-09-30', '2001-06-30',
        '2001-03-31', '2000-12-31', '2000-06-30', '1999-12-31', '1999-06-30',
        '1998-12-31', '1998-06-30', '1997-12-31', '1997-06-30', '1996-12-31',
        '1996-06-30', '1995-12-31', '1995-06-30', '1994-12-31', '1994-06-30',
        '1993-12-31', '1993-06-30', '1992-12-31', '1991-12-31', '1990-12-31',
        '1989-12-31'
    ]
    result = IncomeStatement.query_data(
        region=Region.CHN,
        session=session,
        provider=Provider.EastMoney,
        return_type='domain',
        codes=['000001'],
        end_timestamp='2018-12-30',
        order=IncomeStatement.report_date.desc(),
        time_field='report_date')
    assert len(correct_timestamps) == len(result)
    timestamps = [to_time_str(item.report_date) for item in result]
    assert set(correct_timestamps) == set(timestamps)
    latest: IncomeStatement = result[0]

    assert latest.operating_income == 86660000000
    assert latest.fi_net_interest_income == 54530000000
    assert latest.fi_interest_income == 121700000000
    assert latest.fi_interest_expenses == 67130000000
    assert latest.fi_net_incomes_from_fees_and_commissions == 23710000000
    assert latest.fi_incomes_from_fees_and_commissions == 28920000000
    assert latest.fi_expenses_for_fees_and_commissions == 5218000000
    assert latest.investment_income == 7099000000
    assert latest.fi_income_from_fair_value_change == 1047000000
    assert latest.fi_income_from_exchange == -40000000
    assert latest.fi_other_income == 144000000

    assert latest.operating_costs == 26430000000
    assert latest.business_taxes_and_surcharges == 847000000
    assert latest.fi_operate_and_manage_expenses == 25580000000

    assert latest.operating_profit == 26610000000
    assert latest.non_operating_income == 14000000
    assert latest.non_operating_costs == 62000000

    assert latest.total_profits == 26570000000
예제 #4
0
def test_000778_income_statement():
    correct_timestamps = [
        '2018-09-30', '2018-06-30', '2018-03-31', '2017-12-31', '2017-09-30',
        '2017-06-30', '2017-03-31', '2016-12-31', '2016-09-30', '2016-06-30',
        '2016-03-31', '2015-12-31', '2015-09-30', '2015-06-30', '2015-03-31',
        '2014-12-31', '2014-09-30', '2014-06-30', '2014-03-31', '2013-12-31',
        '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31', '2012-09-30',
        '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30',
        '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31',
        '2009-12-31', '2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31',
        '2008-09-30', '2008-06-30', '2008-03-31', '2007-12-31', '2007-09-30',
        '2007-06-30', '2007-03-31', '2006-12-31', '2006-09-30', '2006-06-30',
        '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30', '2005-03-31',
        '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31',
        '2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30',
        '2002-06-30', '2002-03-31', '2001-12-31', '2001-06-30', '2000-12-31',
        '2000-06-30', '1999-12-31', '1999-06-30', '1998-12-31', '1998-06-30',
        '1997-12-31', '1997-06-30', '1996-12-31', '1995-12-31', '1994-12-31'
    ]
    result = IncomeStatement.query_data(
        session=session,
        provider='eastmoney',
        return_type='domain',
        codes=['000778'],
        end_timestamp='2018-12-30',
        order=IncomeStatement.report_date.desc(),
        time_field='report_date')
    assert len(correct_timestamps) == len(result)
    timestamps = [to_time_str(item.report_date) for item in result]
    assert set(correct_timestamps) == set(timestamps)
    latest: IncomeStatement = result[0]

    assert latest.operating_income == 31710000000
    assert latest.total_operating_costs == 29230000000
    assert latest.operating_costs == 26220000000
    assert latest.rd_costs == 185500000
    assert latest.net_change_in_insurance_contract_reserves == 0
    assert latest.business_taxes_and_surcharges == 359700000
    assert latest.sales_costs == 771400000
    assert latest.managing_costs == 472900000
    assert latest.financing_costs == 397500000
    assert latest.assets_devaluation == 824400000
    assert latest.investment_income == 104100000
    assert latest.investment_income_from_related_enterprise == 61290000

    assert latest.operating_profit == 2637000000
    assert latest.non_operating_income == 38340000
    assert latest.non_operating_costs == 221700000

    assert latest.total_profits == 2454000000
    assert latest.tax_expense == 579600000
    assert latest.net_profit == 1874000000
    assert latest.net_profit_as_parent == 1811000000
    assert latest.net_profit_as_minority_interest == 63570000
    assert latest.deducted_net_profit == 1897000000

    assert latest.eps == 0.4537
    assert latest.diluted_eps == 0.4537

    assert latest.other_comprehensive_income == -521000000
    assert latest.other_comprehensive_income_as_parent == -522400000
    assert latest.other_comprehensive_income_as_minority_interest == 1403000
    assert latest.total_comprehensive_income == 1353000000
    assert latest.total_comprehensive_income_as_parent == 1288000000
    assert latest.total_comprehensive_income_as_minority_interest == 64980000
예제 #5
0
    ],
    columns=["pledge_total_ratio", "start_date", "end_date", "code"],
    codes=risk_stock_list,
)

# 应收账款  000568
BalanceSheetData = BalanceSheet.query_data(
    filters=[BalanceSheet.report_period == "year"],
    columns=["accounts_receivable", "report_date", "code"],
    codes=risk_stock_list,
    end_timestamp=risk_end,
)
# 营业收入
IncomeStatementData = IncomeStatement.query_data(
    filters=[IncomeStatement.report_period == "year"],
    columns=["operating_income", "report_date", "code"],
    codes=risk_stock_list,
    end_timestamp=risk_end,
)
HolderTradingData = HolderTrading.query_data(
    filters=[HolderTrading.holder_direction == "减持"],
    codes=risk_stock_list,
    start_timestamp=risk_start,
    end_timestamp=risk_end,
    provider="emquantapi",
)

risk_reason_1 = pd.DataFrame()
ranks = [
    name for name in risk_stock_list
    if not risk_model(name, risk_end, EquityPledgeData, BalanceSheetData,
                      IncomeStatementData, HolderTradingData)[0]