示例#1
0
def api_data_warning_currency_funds():
    """ 货币资金排雷
    """
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 5, type=int)

    income_statement = get_stock_income_statement(code, limit=limit)
    balances = get_stock_balance_sheet(code, limit=limit)

    revenues = {
        item.account_date: item.total_revenue
        for item in income_statement
    }
    items = []
    for bl in balances:
        item = {}
        item["account_date"] = bl.account_date
        item["currency_funds"] = bl.currency_funds
        item["crcfnd_assets_ratio"] = bl.currency_funds / bl.total_assets
        item["asset_liab_ratio"] = bl.total_liab / bl.total_assets
        item["crcfnd_revenue_ratio"] = bl.currency_funds / revenues.get(
            bl.account_date)
        items.append(item)

    items.sort(key=itemgetter("account_date"), reverse=True)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template("stock/report/tables/_warning_currency_funds.html",
                            items=items)
        }
    })
示例#2
0
def api_data_total_holders_equity():
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 10, type=int)

    balances = get_stock_balance_sheet(code, limit=limit)
    balances.sort(key=attrgetter("account_date"))

    x_labels = []
    values = []

    for bln in balances:
        x_labels.append(bln.account_date.strftime("%Y年报"))
        values.append(float(bln.total_holders_equity))

    holders_equity = {
        "xLabels": x_labels,
        "name": "净资产",
        "values": values,
    }

    return jsonify({
        "message": "successful",
        "data": {
            "echarts_bar": holders_equity
        }
    })
示例#3
0
def api_data_asset_structure():
    """ 资产结构 - 轻重资产
    """
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 5, type=int)
    productive_assets = get_productive_assets(code, limit=limit)
    balances = get_stock_balance_sheet(code, limit=limit)
    income_statement = get_stock_income_statement(code, limit=limit)

    tmp = defaultdict(dict)
    for item in balances:
        dt = item.account_date
        tmp[dt]["productive_asset_ratio"] = round(
            productive_assets[dt] / item.total_assets, 2)
    for item in income_statement:
        dt = item.account_date
        prdasset = productive_assets.get(dt)
        if prdasset:
            tmp[dt]["profit_prdasset_ratio"] = round(
                item.profit_total_amt / productive_assets[dt], 2)
    data = []
    for dt, item in tmp.items():
        item["account_date"] = dt
        data.append(item)
    data.sort(key=itemgetter("account_date"), reverse=True)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template("stock/report/tables/_asset_structure.html",
                            items=data)
        }
    })
示例#4
0
def api_data_brief_balance_sheet():
    code = request.args.get("code", type=str)
    items = get_stock_balance_sheet(code, limit=5)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template("stock/report/tables/_brief_balance_sheet.html",
                            items=items)
        }
    })
示例#5
0
def api_data_warning_other_assets():
    """排雷--存货、交易性金融资产、固定资产、在建工程
    """
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 10, type=int)

    balances = get_stock_balance_sheet(code, limit=limit)
    indicatos = get_stock_indicators(code, limit=limit)

    act_dt_to_fixed_asset_trunover_ratio = {
        ind.account_date: ind.fixed_asset_turnover_ratio
        for ind in indicatos
    }
    act_dt_to_inventory_turnover_days = {
        ind.account_date: ind.inventory_turnover_days
        for ind in indicatos
    }

    items = []
    for bl in balances:
        item = {}
        act_dt = bl.account_date
        item["account_date"] = bl.account_date
        item["inventory_ratio"] = bl.inventory / bl.total_assets if isinstance(
            bl.inventory, float) else None
        item[
            "construction_in_process_ratio"] = bl.construction_in_process / bl.total_assets if isinstance(
                bl.construction_in_process, float) else None
        item[
            "tradable_fnncl_assets_ratio"] = bl.tradable_fnncl_assets / bl.total_assets if isinstance(
                bl.tradable_fnncl_assets, float) else None
        item[
            "fixed_asset_turnover_ratio"] = act_dt_to_fixed_asset_trunover_ratio.get(
                act_dt)
        item[
            "inventory_turnover_days"] = act_dt_to_inventory_turnover_days.get(
                act_dt)
        items.append(item)
    items.sort(key=itemgetter("account_date"), reverse=True)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template("stock/report/tables/_warning_other_assets.html",
                            items=items)
        }
    })
示例#6
0
def api_data_financial_risk():
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 10, type=int)

    indicators = get_stock_indicators(code)
    account_receivable_ratios = get_account_receivable_ratio(code)
    balances = get_stock_balance_sheet(code)

    goodwill_ratios = dict()
    currency_interest_liab_ratios = dict()
    for bln in balances:
        dt = bln.account_date
        goodwill_ratios[dt] = none_to_zeros(
            bln.goodwill) / bln.total_holders_equity
        interest_bearing_liab = none_to_zeros(bln.st_loan) + none_to_zeros(bln.lt_loan) + none_to_zeros(bln.bond_payable) \
                            + none_to_zeros(bln.tradable_fnncl_liab) + none_to_zeros(bln.noncurrent_liab_due_in1y)  # 有息负债
        currency_interest_liab_ratios[
            dt] = bln.currency_funds / interest_bearing_liab if interest_bearing_liab != 0 else float(
                "inf")

    simple_indicators = []
    for item in indicators:
        dt = item.account_date
        new_item = dict()
        new_item["account_date"] = dt
        new_item["asset_liab_ratio"] = item.asset_liab_ratio  # 资产负债率
        new_item["equity_multiplier"] = item.equity_multiplier  # 权益乘数
        new_item["equity_ratio"] = item.equity_ratio  # 产权比率
        new_item["current_ratio"] = item.current_ratio  # 流动比率
        new_item["quick_ratio"] = item.quick_ratio  # 速动比率
        new_item["account_receivable_ratio"] = account_receivable_ratios.get(
            dt)  # 应收账款占收入
        new_item["goodwill_ratio"] = goodwill_ratios.get(dt)
        new_item[
            "currency_interest_liab_ratio"] = currency_interest_liab_ratios.get(
                dt)
        simple_indicators.append(new_item)
    simple_indicators.sort(key=itemgetter("account_date"), reverse=True)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template("stock/report/tables/_financial_risk.html",
                            indicators=simple_indicators)
        }
    })
示例#7
0
def api_data_total_assets():
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 10, type=int)

    balances = get_stock_balance_sheet(code, limit=limit)
    balances.sort(key=attrgetter("account_date"))

    x_labels = []
    values = []
    for item in balances:
        x_labels.append(item.account_date.strftime("%Y年报"))
        values.append(float(item.total_assets))

    data = {
        "xLabels": x_labels,
        "name": "总资产",
        "values": values,
    }
    return jsonify({"message": "successful", "data": {"echarts_bar": data}})
示例#8
0
def api_data_five_forces():
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 5, type=int)

    balances = get_stock_balance_sheet(code, limit=limit)
    income_statement = get_stock_income_statement(code, limit=limit)
    indicators = get_stock_indicators(code, limit=limit)

    revenues = {
        item.account_date: item.total_revenue
        for item in income_statement
    }
    gross_ratios = {
        item.account_date: item.gross_selling_rate * 0.01
        for item in indicators
    }

    items = []
    for bln in balances:
        dt = bln.account_date
        revenue = revenues.get(dt)
        if not revenue:
            continue
        item = dict()
        item["account_date"] = dt
        item["account_receivable_ratio"] = none_to_zeros(
            bln.account_receivable) / revenue
        item["pre_payment_ratio"] = none_to_zeros(bln.pre_payment) / revenue
        item["accounts_payable_ratio"] = none_to_zeros(
            bln.accounts_payable) / revenue
        item["pre_receivable_ratio"] = none_to_zeros(
            bln.pre_receivable) / revenue
        item["gross_selling_ratio"] = gross_ratios.get(dt)
        items.append(item)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template("stock/report/tables/_five_forces.html",
                            items=items)
        }
    })
示例#9
0
def api_data_warning_account_receivable():
    """ 应收票据排雷
    """
    code = request.args.get("code", type=str)
    limit = request.args.get("limit", 5, type=int)

    balances = get_stock_balance_sheet(code, limit=limit)
    indicatos = get_stock_indicators(code, limit=limit)
    actdt_to_rcvb_turnover_days = {
        ind.account_date: ind.receivable_turnover_days
        for ind in indicatos
    }

    ac_ratios = get_account_receivable_ratio(code)
    bc_ratios = get_bills_receivable_ratio(code)
    items = []
    for bl in balances:
        item = {}
        act_dt = bl.account_date
        item["account_date"] = act_dt
        item["act_rcvb_ratio"] = ac_ratios.get(act_dt)
        item["bills_rcvb_ratio"] = bc_ratios.get(act_dt)
        item["bills_rcvb"] = bl.bills_receivable
        item["bill_payable"] = bl.bill_payable
        item["act_rcvb_turnover_days"] = actdt_to_rcvb_turnover_days.get(
            act_dt)
        item[
            "othr_rcvb_ratio"] = bl.othr_receivables / bl.total_assets if isinstance(
                bl.othr_receivables, float) else None
        items.append(item)
    items.sort(key=itemgetter("account_date"), reverse=True)
    return jsonify({
        "message": "successful",
        "data": {
            "html":
            render_template(
                "stock/report/tables/_warning_account_receivable.html",
                items=items)
        }
    })