Пример #1
0
def cash_flow_statement_to_es(force=False):
    es_index_mapping('cash_flow_statement', CashFlowStatement)

    for _, security_item in get_security_list().iterrows():
        try:
            start_date = None
            if not force:
                query = {"term": {"securityId": ""}}
                query["term"]["securityId"] = security_item["id"]
                latest_record = es_get_latest_record(
                    index='cash_flow_statement',
                    time_field='reportDate',
                    query=query)
                logger.info("latest_record:{}".format(latest_record))
                if latest_record:
                    start_date = latest_record['reportDate']

            for json_object in get_cash_flow_statement_items(
                    security_item, start_date=start_date):
                if start_date and is_same_date(start_date,
                                               json_object['reportDate']):
                    continue

                cash_flow_statement = CashFlowStatement(
                    meta={'id': json_object['id']})
                fill_doc_type(cash_flow_statement, json_object)
                cash_flow_statement.save()
        except Exception as e:
            logger.warn("wrong CashFlowStatement:{},error:{}", security_item,
                        e)
Пример #2
0
def stock_kdata_to_es(start='000001', end='666666', codes=US_STOCK_CODES, force=False):
    for _, security_item in get_security_list(start=start, end=end, exchanges=['sh', 'sz', 'nasdaq'],
                                              codes=codes).iterrows():
        # 创建索引
        index_name = get_es_kdata_index(security_item['type'], security_item['exchange'])
        es_index_mapping(index_name, StockKData)

        start_date = None
        if not force:
            query = {
                "term": {"securityId": ""}
            }
            query["term"]["securityId"] = security_item["id"]
            latest_record = es_get_latest_record(index_name, query=query)
            logger.info("latest_record:{}".format(latest_record))
            if latest_record:
                start_date = latest_record['timestamp']
        actions = []
        for _, kdata_item in get_kdata(security_item, start_date=start_date).iterrows():
            if start_date and is_same_date(start_date, kdata_item['timestamp']):
                continue

            try:
                id = '{}_{}'.format(kdata_item['securityId'], kdata_item['timestamp'])
                kdata = StockKData(meta={'id': id}, id=id)
                kdata.meta['index'] = index_name
                fill_doc_type(kdata, json.loads(kdata_item.to_json()))
                # kdata.save(index=index_name)
                actions.append(kdata.to_dict(include_meta=True))
            except Exception as e:
                logger.warn("wrong KdataDay:{},error:{}", kdata_item, e)
        if actions:
            resp = elasticsearch.helpers.bulk(es, actions)
            logger.info(resp)
Пример #3
0
def usa_stock_finance_to_es(force=False):
    es_index_mapping('finance_summary', FinanceSummary)

    for _, security_item in get_security_list(exchanges=['nasdaq'],
                                              codes=US_STOCK_CODES).iterrows():
        try:
            start_date = None
            if not force:
                query = {"term": {"securityId": ""}}
                query["term"]["securityId"] = security_item["id"]
                latest_record = es_get_latest_record(index='finance_summary',
                                                     time_field='reportDate',
                                                     query=query)
                logger.info("latest_record:{}".format(latest_record))
                if latest_record:
                    start_date = latest_record['reportDate']
            actions = []
            for _, json_object in get_finance_summary_items(
                    security_item, start_date=start_date).iterrows():
                if start_date and is_same_date(start_date,
                                               json_object['reportDate']):
                    continue

                finance_summary = FinanceSummary(
                    meta={'id': json_object['id']})
                fill_doc_type(finance_summary, json_object.to_dict())
                actions.append(finance_summary.to_dict(include_meta=True))
            if actions:
                resp = elasticsearch.helpers.bulk(es, actions)
                logger.info(resp)
        except Exception as e:
            logger.warn("wrong FinanceSummary:{},error:{}", security_item, e)
Пример #4
0
def stock_meta_to_es(force=False):
    es_index_mapping('stock_meta', StockMeta)
    start_date = None
    if not force:
        latest_record = es_get_latest_record('stock_meta',
                                             time_field='listDate')
        logger.info("latest_record:{}".format(latest_record))
        if latest_record:
            start_date = latest_record['listDate']

    actions = []
    for _, item in get_security_list(mode='es',
                                     start_date=start_date,
                                     exchanges=EXCHANGE_LIST_COL).iterrows():
        if start_date and is_same_date(start_date, item['listDate']):
            continue
        try:
            stock_meta = StockMeta(meta={'id': item['id']})
            fill_doc_type(stock_meta, json.loads(item.to_json()))
            actions.append(stock_meta.to_dict(include_meta=True))
        except Exception as e:
            logger.warn("wrong SecurityItem:{},error:{}", item, e)
    if actions:
        resp = elasticsearch.helpers.bulk(es, actions)
        logger.info(resp)
Пример #5
0
def stock_kdata_to_es(start='000001', end='666666', force=False):
    for _, security_item in get_security_list(start=start, end=end).iterrows():
        # 创建索引
        index_name = get_es_kdata_index(security_item['type'],
                                        security_item['exchange'])
        es_index_mapping(index_name, StockKData)

        start_date = None
        if not force:
            query = {"term": {"securityId": ""}}
            query["term"]["securityId"] = security_item["id"]
            latest_record = es_get_latest_record(index_name, query=query)
            logger.info("latest_record:{}".format(latest_record))
            if latest_record:
                start_date = latest_record['timestamp']
        actions = []
        for _, kdata_item in get_kdata(security_item,
                                       start_date=start_date).iterrows():
            if start_date and is_same_date(start_date,
                                           kdata_item['timestamp']):
                continue

            try:
                id = '{}_{}'.format(kdata_item['securityId'],
                                    kdata_item['timestamp'])
                kdata = StockKData(meta={'id': id}, id=id)
                fill_doc_type(kdata, json.loads(kdata_item.to_json()))
                # kdata.save(index=index_name)
                actions.append(kdata.to_dict(include_meta=True))
            except Exception as e:
                logger.warn("wrong KdataDay:{},error:{}", kdata_item, e)
        if actions:
            resp = elasticsearch.helpers.bulk(es, actions)
            logger.info(resp)
Пример #6
0
def income_statement_to_es(force=False):
    es_index_mapping('income_statement', IncomeStatement)

    for _, security_item in get_security_list().iterrows():
        try:
            start_date = None
            if not force:
                query = {"term": {"securityId": ""}}
                query["term"]["securityId"] = security_item["id"]
                latest_record = es_get_latest_record(index='income_statement',
                                                     time_field='reportDate',
                                                     query=query)
                logger.info("latest_record:{}".format(latest_record))
                if latest_record:
                    start_date = latest_record['reportDate']
            actions = []
            for json_object in get_income_statement_items(
                    security_item, start_date=start_date):
                if start_date and is_same_date(start_date,
                                               json_object['reportDate']):
                    continue

                income_statement = IncomeStatement(
                    meta={'id': json_object['id']})
                fill_doc_type(income_statement, json_object)
                # income_statement.save()
                actions.append(income_statement.to_dict(include_meta=True))
            if actions:
                resp = elasticsearch.helpers.bulk(es, actions)
                logger.info(resp)
        except Exception as e:
            logger.warn("wrong IncomeStatement:{},error:{}", security_item, e)
Пример #7
0
def stock_kdata_to_es(start='000001', end='666666', force=False):
    for _, security_item in get_security_list(start=start, end=end).iterrows():
        # 创建索引
        index_name = get_es_kdata_index(security_item['id'])
        es_index_mapping(index_name, StockKData)

        start_date = None
        if not force:
            latest_record = es_get_latest_record(index_name)
            logger.info("latest_record:{}".format(latest_record))
            if latest_record:
                start_date = latest_record['timestamp']

        for _, kdata_item in get_kdata(security_item,
                                       start_date=start_date).iterrows():
            if start_date and is_same_date(start_date,
                                           kdata_item['timestamp']):
                continue

            try:
                id = '{}_{}'.format(kdata_item['securityId'],
                                    kdata_item['timestamp'])
                kdata = StockKData(meta={'id': id}, id=id)
                fill_doc_type(kdata, json.loads(kdata_item.to_json()))
                kdata.save(index=index_name)
            except Exception as e:
                logger.warn("wrong KdataDay:{},error:{}", kdata_item, e)
Пример #8
0
    def on_event(self, event_item):
        self.logger.debug(event_item)
        if not self.last_date or not is_same_date(self.last_date,
                                                  self.current_time):
            self.last_date = to_timestamp(
                event_item['timestamp']) - timedelta(days=1)
            self.last_kdata = get_kdata(self.security_item,
                                        the_date=to_time_str(self.last_date))

            if self.last_kdata is None:
                fetch_kdata(exchange_str=self.security_item['exchange'])
                self.last_kdata = get_kdata(self.security_item,
                                            the_date=to_time_str(
                                                self.last_date))

            if self.last_kdata is not None:
                self.last_close = self.last_kdata.loc[
                    to_time_str(self.last_date), 'close']
            else:
                self.logger.exception("could not get last close for:{}".format(
                    self.last_date))

            self.update_today_triggered()

        change_pct = (event_item['price'] - self.last_close) / self.last_close

        self.logger.info(
            "{} last day close is:{},now price is:{},the change_pct is:{}".
            format(self.security_item['id'], self.last_close,
                   event_item['price'], change_pct))
        self.check_subscription(current_price=event_item['price'],
                                change_pct=change_pct)
Пример #9
0
    def on_tick(self, tick_item):
        # 只计算日内,超短线
        if not is_same_date(self.current_time, tick_item['timestamp']):
            self.today_traded = False
            if not self.df.empty:
                self.df = pd.DataFrame()
        else:
            if not self.today_traded:
                if not self.df.empty and self.df.index.size == 1:
                    self.df = index_df_with_time(self.df)
                self.df = self.df.append(tick_item, ignore_index=True)
                # 14:50时,计算当日资金流
                if ("14:50:" in tick_item['timestamp']):
                    money_flow = (self.df['turnover'] * self.df['direction']).sum()
                    money_all = (self.df['turnover'] * abs(self.df['direction'])).sum()

                    # 净流入
                    if money_flow > 0 and not self.account_service.get_position(tick_item['securityId']):
                        # 使用用后复权价格
                        factor = \
                            get_kdata(tick_item['securityId'], the_date=pd.Timestamp(tick_item['timestamp']).date())[
                                'factor']
                        self.buy(tick_item['securityId'], current_price=tick_item['price'] * factor)
                    # 净流出
                    elif money_flow < 0 and self.account_service.get_position(tick_item['securityId']):
                        # 使用用后复权价格
                        factor = \
                            get_kdata(tick_item['securityId'], the_date=pd.Timestamp(tick_item['timestamp']).date())[
                                'factor']
                        self.sell(tick_item['securityId'], current_price=tick_item['price'] * factor)
                    self.today_traded = True
    def update_daily_user_statistic(self, user_id, record, update_timestamp):
        latest_user_daily_statistic = self.user_map_latest_user_daily_statistic.get(user_id)

        if not latest_user_daily_statistic:
            the_record = es_get_latest_daily_user_statistic(user_id=user_id)
            if the_record:
                latest_user_daily_statistic = EosUserStatistic(
                    meta={'id': the_record['id'], 'index': daily_user_statistic_index_name},
                    **the_record)
                self.user_map_latest_user_daily_statistic[user_id] = latest_user_daily_statistic

        # ignore the user statistic has computed before
        if latest_user_daily_statistic and self.kdata_timestamp <= to_timestamp(
                latest_user_daily_statistic['updateTimestamp']):
            return

        if not latest_user_daily_statistic or not is_same_date(latest_user_daily_statistic['timestamp'],
                                                               self.df['timestamp'][0]):
            doc_id = '{}_{}_{}'.format(user_id, self.security_id, self.last_day_time_str)
            latest_user_daily_statistic = EosUserStatistic(
                meta={'id': doc_id, 'index': daily_user_statistic_index_name},
                id=doc_id,
                userId=user_id,
                timestamp=self.last_day_time_str,
                securityId=self.security_id,
                code=self.security_item['code'],
                name=self.security_item['name'])
            self.user_map_latest_user_daily_statistic[user_id] = latest_user_daily_statistic

        # update user daily statistic
        self.update_statistic_doc(latest_user_daily_statistic, record, update_timestamp)
Пример #11
0
    def on_tick(self, tick_item):
        # 只计算日内,超短线
        if not is_same_date(self.current_time, tick_item['timestamp']):
            self.today_traded = False
            if not self.df.empty:
                self.df = pd.DataFrame()
        else:
            if not self.today_traded:
                if not self.df.empty and self.df.index.size == 1:
                    self.df = index_df_with_time(self.df)
                self.df = self.df.append(tick_item, ignore_index=True)
                # 14:50时,计算当日资金流
                if ("14:50:" in tick_item['timestamp']):
                    money_flow = (self.df['turnover'] * self.df['direction']).sum()
                    money_all = (self.df['turnover'] * abs(self.df['direction'])).sum()

                    # 净流入
                    if money_flow > 0 and not self.account_service.get_position(tick_item['securityId']):
                        # 使用用后复权价格
                        factor = \
                            get_kdata(tick_item['securityId'], the_date=pd.Timestamp(tick_item['timestamp']).date())[
                                'factor']
                        self.buy(tick_item['securityId'], current_price=tick_item['price'] * factor)
                    # 净流出
                    elif money_flow < 0 and self.account_service.get_position(tick_item['securityId']):
                        # 使用用后复权价格
                        factor = \
                            get_kdata(tick_item['securityId'], the_date=pd.Timestamp(tick_item['timestamp']).date())[
                                'factor']
                        self.sell(tick_item['securityId'], current_price=tick_item['price'] * factor)
                    self.today_traded = True
Пример #12
0
def security_meta_to_es(security_type='cryptocurrency', force=False):
    if security_type == 'cryptocurrency':
        doc_type = CryptoCurrencyMeta

    es_index_mapping('crypto_currency_meta', doc_type)
    start_date = None
    if not force:
        latest_record = es_get_latest_record('crypto_currency_meta',
                                             time_field='listDate')
        logger.info("latest_record:{}".format(latest_record))
        if latest_record and 'listDate' in latest_record:
            start_date = latest_record['listDate']

    actions = []
    for _, item in get_security_list(security_type=security_type).iterrows():
        if start_date and item['listDate'] and is_same_date(
                start_date, item['listDate']):
            continue
        try:
            security_meta = doc_type(meta={'id': item['id']})
            fill_doc_type(security_meta, json.loads(item.to_json()))
            actions.append(security_meta.to_dict(include_meta=True))
        except Exception as e:
            logger.warn("wrong SecurityItem:{},error:{}", item, e)
    if actions:
        resp = elasticsearch.helpers.bulk(es_client, actions)
        logger.info(resp)
Пример #13
0
def usa_stock_finance_to_es(force=False):
    es_index_mapping('finance_summary', FinanceSummary)

    for _, security_item in get_security_list(exchanges=['nasdaq'], codes=US_STOCK_CODES).iterrows():
        try:
            start_date = None
            if not force:
                query = {
                    "term": {"securityId": ""}
                }
                query["term"]["securityId"] = security_item["id"]
                latest_record = es_get_latest_record(index='finance_summary', time_field='reportDate', query=query)
                logger.info("latest_record:{}".format(latest_record))
                if latest_record:
                    start_date = latest_record['reportDate']
            actions = []
            for _, json_object in get_finance_summary_items(security_item, start_date=start_date).iterrows():
                if start_date and is_same_date(start_date, json_object['reportDate']):
                    continue

                finance_summary = FinanceSummary(meta={'id': json_object['id']})
                fill_doc_type(finance_summary, json_object.to_dict())
                actions.append(finance_summary.to_dict(include_meta=True))
            if actions:
                resp = elasticsearch.helpers.bulk(es, actions)
                logger.info(resp)
        except Exception as e:
            logger.warn("wrong FinanceSummary:{},error:{}", security_item, e)
Пример #14
0
def cash_flow_statement_to_es(force=False):
    es_index_mapping('cash_flow_statement', CashFlowStatement)

    for _, security_item in get_security_list().iterrows():
        try:
            start_date = None
            if not force:
                query = {
                    "term": {"securityId": ""}
                }
                query["term"]["securityId"] = security_item["id"]
                latest_record = es_get_latest_record(index='cash_flow_statement', time_field='reportDate', query=query)
                logger.info("latest_record:{}".format(latest_record))
                if latest_record:
                    start_date = latest_record['reportDate']
            actions = []
            for json_object in get_cash_flow_statement_items(security_item, start_date=start_date):
                if start_date and is_same_date(start_date, json_object['reportDate']):
                    continue

                cash_flow_statement = CashFlowStatement(meta={'id': json_object['id']})
                fill_doc_type(cash_flow_statement, json_object)
                # cash_flow_statement.save()
                actions.append(cash_flow_statement.to_dict(include_meta=True))
            if actions:
                resp = elasticsearch.helpers.bulk(es, actions)
                logger.info(resp)
        except Exception as e:
            logger.warn("wrong CashFlowStatement:{},error:{}", security_item, e)
Пример #15
0
def kdata_to_es(start=None,
                end=None,
                security_type='stock',
                exchanges=['sh', 'sz'],
                force=False):
    if security_type == 'stock':
        doc_type = StockKData
    elif security_type == 'index':
        doc_type = IndexKData
    elif security_type == 'cryptocurrency':
        doc_type = CryptoCurrencyKData

    for _, security_item in get_security_list(security_type=security_type,
                                              exchanges=exchanges,
                                              start=start,
                                              end=end).iterrows():
        # 创建索引
        index_name = get_es_kdata_index(security_item['type'],
                                        security_item['exchange'])
        es_index_mapping(index_name, doc_type)

        start_date = None

        if not force:
            query = {"term": {"securityId": ""}}
            query["term"]["securityId"] = security_item["id"]
            latest_record = es_get_latest_record(index_name, query=query)
            logger.info("latest_record:{}".format(latest_record))
            if latest_record:
                start_date = latest_record['timestamp']
        actions = []

        df_kdata = get_kdata(security_item, start_date=start_date)

        for _, kdata_item in df_kdata.iterrows():
            if start_date and is_same_date(start_date,
                                           kdata_item['timestamp']):
                continue

            try:
                id = '{}_{}'.format(kdata_item['securityId'],
                                    kdata_item['timestamp'])
                kdata = doc_type(meta={'id': id}, id=id)
                kdata.meta['index'] = index_name
                kdata_json = json.loads(kdata_item.to_json())

                fill_doc_type(kdata, kdata_json)
                # kdata.save(index=index_name)
                actions.append(kdata.to_dict(include_meta=True))
            except Exception as e:
                logger.warn("wrong KdataDay:{},error:{}", kdata_item, e)
        if actions:
            resp = elasticsearch.helpers.bulk(es_client, actions)
            logger.info(resp)
Пример #16
0
def fetch_kdata(exchange_str='bitstamp'):
    ccxt_exchange = eval("ccxt.{}()".format(exchange_str))
    if ccxt_exchange.has['fetchOHLCV']:
        for _, security_item in get_security_list(security_type='cryptocurrency', exchanges=[exchange_str]).iterrows():
            try:
                if security_item['name'] not in CRYPTOCURRENCY_PAIR:
                    continue

                start_date, df = get_latest_download_trading_date(security_item)
                # 日K线只抓到昨天
                end_date = pd.Timestamp.today() - pd.DateOffset(1)

                if start_date and (start_date > end_date):
                    logger.info("{} kdata is ok".format(security_item['code']))
                    continue

                try:
                    kdatas = ccxt_exchange.fetch_ohlcv(security_item['name'], timeframe='1d')
                    # for rateLimit
                    time.sleep(5)
                except Exception as e:
                    logger.exception("fetch_kdata for {} {} failed".format(exchange_str, security_item['name']), e)
                    continue

                for kdata in kdatas:
                    timestamp = pd.Timestamp.fromtimestamp(int(kdata[0] / 1000))
                    if is_same_date(timestamp, pd.Timestamp.today()):
                        continue
                    kdata_json = {
                        'timestamp': to_time_str(timestamp),
                        'code': security_item['code'],
                        'name': security_item['name'],
                        'open': kdata[1],
                        'high': kdata[2],
                        'low': kdata[3],
                        'close': kdata[4],
                        'volume': kdata[5],
                        'securityId': security_item['id'],
                        'preClose': None,
                        'change': None,
                        'changePct': None
                    }
                    df = df.append(kdata_json, ignore_index=True)
                if not df.empty:
                    df = df.loc[:, KDATA_COMMON_COL]
                    kdata_df_save(df, get_kdata_path(security_item), calculate_change=True)
                    logger.info(
                        "fetch_kdata for exchange:{} security:{} success".format(exchange_str, security_item['name']))
            except Exception as e:
                logger.info(
                    "fetch_kdata for exchange:{} security:{} failed".format(exchange_str, security_item['name'], e))
    else:
        logger.warning("exchange:{} not support fetchOHLCV".format(exchange_str))
Пример #17
0
def finance_sheet_to_es(sheet_type='balance_sheet', force=False):
    if sheet_type == 'balance_sheet':
        doc_type = BalanceSheet
    elif sheet_type == 'income_statement':
        doc_type = IncomeStatement
    elif sheet_type == 'cash_flow_statement':
        doc_type = CashFlowStatement

    es_index_mapping(sheet_type, doc_type)

    for _, security_item in get_security_list().iterrows():
        try:
            start_date = None
            if not force:
                query = {"term": {"securityId": ""}}
                query["term"]["securityId"] = security_item["id"]
                latest_record = es_get_latest_record(index=sheet_type,
                                                     time_field='reportDate',
                                                     query=query)
                logger.info("latest_record:{}".format(latest_record))
                if latest_record:
                    start_date = latest_record['reportDate']
            actions = []

            items = []
            if sheet_type == 'balance_sheet':
                items = get_balance_sheet_items(security_item,
                                                start_date=start_date)
            elif sheet_type == 'income_statement':
                items = get_income_statement_items(security_item,
                                                   start_date=start_date)
            elif sheet_type == 'cash_flow_statement':
                items = get_cash_flow_statement_items(security_item,
                                                      start_date=start_date)

            for json_object in items:
                if start_date and is_same_date(start_date,
                                               json_object['reportDate']):
                    continue

                the_doc = doc_type(meta={'id': json_object['id']})
                fill_doc_type(the_doc, json_object)
                # balance_sheet.save()
                actions.append(the_doc.to_dict(include_meta=True))
            if actions:
                resp = elasticsearch.helpers.bulk(es_client, actions)
                logger.info(resp)
        except Exception as e:
            logger.warning("{} wrong {},error:{}", security_item, sheet_type,
                           e)
Пример #18
0
    def generate_eos_daily_statistic(self):
        # ignore the statistic has computed before
        if self.latest_statistic_record and self.kdata_timestamp <= to_timestamp(
                self.latest_statistic_record['updateTimestamp']):
            return

        # update the statistic
        if (not self.latest_statistic_record) or (not is_same_date(self.latest_statistic_record['timestamp'],
                                                                   self.df['timestamp'][0])):
            doc_id = "{}_{}".format(self.security_id, self.last_day_time_str)
            self.latest_statistic_record = CommonStatistic(meta={'id': doc_id, 'index': statistic_index_name},
                                                           id=doc_id,
                                                           timestamp=self.last_day_time_str,
                                                           securityId=self.security_id,
                                                           code=self.security_item['code'],
                                                           name=self.security_item['name'])

        volume = self.df['volume'].sum()
        turnover = self.df['turnover'].sum()
        flow = (self.df['turnover'] * self.df['direction']).sum()

        flowIn = self.df[self.df['direction'] == 1]['turnover'].sum()
        flowOut = self.df[self.df['direction'] == -1]['turnover'].sum()

        bigFlowIn = self.df[(self.df['direction'] == 1) & (self.df['turnover'] >= self.BIG_ORDER)]['turnover'].sum()
        middleFlowIn = self.df[(self.df['direction'] == 1) & (self.df['turnover'] >= self.MIDDLE_ORDER) & (
                self.df['turnover'] < self.BIG_ORDER)]['turnover'].sum()
        smallFlowIn = self.df[(self.df['direction'] == 1) & (self.df['turnover'] < self.MIDDLE_ORDER)]['turnover'].sum()

        bigFlowOut = self.df[(self.df['direction'] == -1) & (self.df['turnover'] >= self.BIG_ORDER)]['turnover'].sum()
        middleFlowOut = self.df[(self.df['direction'] == -1) & (self.df['turnover'] >= self.MIDDLE_ORDER) & (
                self.df['turnover'] < self.BIG_ORDER)]['turnover'].sum()
        smallFlowOut = self.df[(self.df['direction'] == -1) & (self.df['turnover'] < self.MIDDLE_ORDER)][
            'turnover'].sum()

        self.update_statistic_doc(self.latest_statistic_record, {'volume': volume,
                                                                 'turnover': turnover,
                                                                 'flow': flow,
                                                                 'flowIn': flowIn,
                                                                 'flowOut': flowOut,
                                                                 'bigFlowIn': bigFlowIn,
                                                                 'middleFlowIn': middleFlowIn,
                                                                 'smallFlowIn': smallFlowIn,
                                                                 'bigFlowOut': bigFlowOut,
                                                                 'middleFlowOut': middleFlowOut,
                                                                 'smallFlowOut': smallFlowOut
                                                                 }, updateTimestamp=self.last_mirco_time_str)
Пример #19
0
def stock_meta_to_es(force=False):
    es_index_mapping('stock_meta', StockMeta)
    start_date = None
    if not force:
        latest_record = es_get_latest_record('stock_meta',
                                             time_field='listDate')
        logger.info("latest_record:{}".format(latest_record))
        if latest_record:
            start_date = latest_record['latestDate']

    for _, item in get_security_list(mode='es',
                                     start_date=start_date).iterrows():
        if start_date and is_same_date(start_date, item['listDate']):
            continue
        try:
            stock_meta = StockMeta(meta={'id': item['id']})
            fill_doc_type(stock_meta, json.loads(item.to_json()))
            stock_meta.save()
        except Exception as e:
            logger.warn("wrong SecurityItem:{},error:{}", item, e)
Пример #20
0
def stock_meta_to_es(force=False):
    es_index_mapping('stock_meta', StockMeta)
    start_date = None
    if not force:
        latest_record = es_get_latest_record('stock_meta', time_field='listDate')
        logger.info("latest_record:{}".format(latest_record))
        if latest_record:
            start_date = latest_record['listDate']

    actions = []
    for _, item in get_security_list(mode='es', start_date=start_date, exchanges=EXCHANGE_LIST_COL).iterrows():
        if start_date and is_same_date(start_date, item['listDate']):
            continue
        try:
            stock_meta = StockMeta(meta={'id': item['id']})
            fill_doc_type(stock_meta, json.loads(item.to_json()))
            actions.append(stock_meta.to_dict(include_meta=True))
        except Exception as e:
            logger.warn("wrong SecurityItem:{},error:{}", item, e)
    if actions:
        resp = elasticsearch.helpers.bulk(es, actions)
        logger.info(resp)
Пример #21
0
def get_cash_flow_statement_items(security_item,
                                  start_date=None,
                                  report_period=None,
                                  report_event_date=None):
    path = get_cash_flow_statement_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = settings.DOWNLOAD_TXT_ENCODING if settings.DOWNLOAD_TXT_ENCODING else detect_encoding(
        url='file://' + os.path.abspath(path)).get('encoding')

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()
        # for idx, line in enumerate(lines):
        #     yield idx, line.split()
        reportDate = lines[0].split()[1:-1]
        # /*一、经营活动产生的现金流量*/
        # 销售商品、提供劳务收到的现金
        cashFromSellingCommoditiesOrOfferingLabor = lines[3].split()[1:-1]
        # 收到的税费返还
        refundOfTaxAndFeeReceived = lines[4].split()[1:-1]
        # 收到的其他与经营活动有关的现金
        cashReceivedRelatingToOtherOperatingActivities = lines[5].split()[1:-1]
        # 经营活动现金流入小计
        subTotalOfCashInflowsFromOperatingActivities = lines[6].split()[1:-1]
        # 购买商品、接受劳务支付的现金
        cashPaidForGoodsAndServices = lines[7].split()[1:-1]
        # 支付给职工以及为职工支付的现金
        cashPaidToAndOnBehalfOfemployees = lines[8].split()[1:-1]
        # 支付的各项税费
        paymentsOfTaxesAndSurcharges = lines[9].split()[1:-1]
        # 支付的其他与经营活动有关的现金
        cashPaidRelatingToOtherOperatingActivities = lines[10].split()[1:-1]
        # 经营活动现金流出小计
        subTotalOfCashOutflowsFromOperatingActivities = lines[11].split()[1:-1]
        # 经营活动产生的现金流量净额
        netCashFlowsFromOperatingActivities = lines[12].split()[1:-1]
        # /*二、投资活动产生的现金流量*/
        # 收回投资所收到的现金
        cashReceivedFromDisposalOfInvestments = lines[14].split()[1:-1]
        # 取得投资收益所收到的现金
        cashReceivedFromReturnsOnIvestments = lines[15].split()[1:-1]
        # 处置固定资产、无形资产和其他长期资产所收回的现金净额
        netCashReceivedFromDisposalAssets = lines[16].split()[1:-1]
        # 处置子公司及其他营业单位收到的现金净额
        netCashReceivedFromDisposalSubsidiaries = lines[17].split()[1:-1]
        # 收到的其他与投资活动有关的现金
        cashReceivedFromOtherInvesting = lines[18].split()[1:-1]
        # 投资活动现金流入小计
        subTotalOfCashInflowsFromInvesting = lines[19].split()[1:-1]
        # 购建固定资产、无形资产和其他长期资产所支付的现金
        cashPaidToAcquireFixedAssets = lines[20].split()[1:-1]
        # 投资所支付的现金
        cashPaidToAcquireInvestments = lines[21].split()[1:-1]
        # 取得子公司及其他营业单位支付的现金净额
        netCashPaidToAcquireSubsidiaries = lines[22].split()[1:-1]
        # 支付的其他与投资活动有关的现金
        cashPaidRelatingToOtherInvesting = lines[23].split()[1:-1]
        # 投资活动现金流出小计
        subTotalOfCashOutflowsFromInvesting = lines[24].split()[1:-1]
        # 投资活动产生的现金流量净额
        netCashFlowsFromInvesting = lines[25].split()[1:-1]
        # /*三、筹资活动产生的现金流量*/
        # 吸收投资收到的现金
        cashReceivedFromCapitalContributions = lines[27].split()[1:-1]
        # 其中:子公司吸收少数股东投资收到的现金
        cashReceivedFromMinorityShareholdersOfSubsidiaries = lines[28].split(
        )[1:-1]
        # 取得借款收到的现金
        cashReceivedFromBorrowings = lines[29].split()[1:-1]
        # 发行债券收到的现金
        cashReceivedFromIssuingBonds = lines[30].split()[1:-1]
        # 收到其他与筹资活动有关的现金
        cashReceivedRelatingToOtherFinancingActivities = lines[31].split(
        )[1:-1]
        # 筹资活动现金流入小计
        subTotalOfCashInflowsFromFinancingActivities = lines[32].split()[1:-1]
        # 偿还债务支付的现金
        cashRepaymentsOfBorrowings = lines[33].split()[1:-1]
        # 分配股利、利润或偿付利息所支付的现金
        cashPaymentsForInterestExpensesAndDistributionOfDividendsOrProfits = lines[
            34].split()[1:-1]
        # 其中:子公司支付给少数股东的股利、利润
        cashPaymentsForDividendsOrProfitToMinorityShareholders = lines[
            35].split()[1:-1]
        # 支付其他与筹资活动有关的现金
        cashPaymentsRelatingToOtherFinancingActivities = lines[36].split(
        )[1:-1]
        # 筹资活动现金流出小计
        subTotalOfCashOutflowsFromFinancingActivities = lines[37].split()[1:-1]
        # 筹资活动产生的现金流量净额
        netCashFlowsFromFinancingActivities = lines[38].split()[1:-1]
        # /*四、汇率变动对现金及现金等价物的影响*/
        effectOfForeignExchangeRate = lines[39].split()[1:-1]
        # /*五、现金及现金等价物净增加额*/
        netIncreaseInCash = lines[40].split()[1:-1]
        # 加:期初现金及现金等价物余额
        cashAtBeginningOfyear = lines[41].split()[1:-1]
        # /*六、期末现金及现金等价物余额*/
        cashAtEndOfyear = lines[42].split()[1:-1]
        # /*附注*/
        # 净利润
        netProfit = lines[44].split()[1:-1]
        # 少数股东权益
        minorityBookValue = lines[45].split()[1:-1]
        # 未确认的投资损失
        unrealisedInvestmentLosses = lines[46].split()[1:-1]
        # 资产减值准备
        allowanceForAssetDevaluation = lines[47].split()[1:-1]
        # 固定资产折旧、油气资产折耗、生产性物资折旧
        depreciationOfFixedAssets = lines[48].split()[1:-1]
        # 无形资产摊销
        amorizationOfIntangibleAssets = lines[49].split()[1:-1]
        # 长期待摊费用摊销
        longTermDeferredExpenses = lines[50].split()[1:-1]
        # 待摊费用的减少
        decreaseOfDeferredExpenses = lines[51].split()[1:-1]
        # 预提费用的增加
        IncreaseOfwithholdingExpenses = lines[52].split()[1:-1]
        # 处置固定资产、无形资产和其他长期资产的损失
        lossOnDisposalOfFixedAssets = lines[53].split()[1:-1]
        # 固定资产报废损失
        lossOnFixedAssetsDamaged = lines[54].split()[1:-1]
        # 公允价值变动损失
        lossOnFairValueChange = lines[55].split()[1:-1]
        # 递延收益增加(减:减少)
        changeOnDeferredRevenue = lines[56].split()[1:-1]
        # 预计负债
        estimatedLiabilities = lines[57].split()[1:-1]
        # 财务费用
        financingExpenses = lines[58].split()[1:-1]
        # 投资损失
        investmentLoss = lines[59].split()[1:-1]
        # 递延所得税资产减少
        decreaseOnDeferredIncomeTaxAssets = lines[60].split()[1:-1]
        # 递延所得税负债增加
        increaseOnDeferredIncomeTaxLiabilities = lines[61].split()[1:-1]
        # 存货的减少
        decreaseInInventories = lines[62].split()[1:-1]
        # 经营性应收项目的减少
        decreaseInReceivablesUnderOperatingActivities = lines[63].split()[1:-1]
        # 经营性应付项目的增加
        increaseInReceivablesUnderOperatingActivities = lines[64].split()[1:-1]
        # 已完工尚未结算款的减少(减:增加)
        decreaseOnAmountDue = lines[65].split()[1:-1]
        # 已结算尚未完工款的增加(减:减少)
        increaseOnSettlementNotYetCompleted = lines[66].split()[1:-1]
        # 其他
        other = lines[67].split()[1:-1]
        # 经营活动产生现金流量净额
        netCashFlowFromOperatingActivities = lines[68].split()[1:-1]
        # 债务转为资本
        debtsTransferToCapital = lines[69].split()[1:-1]
        # 一年内到期的可转换公司债券
        oneYearDueConvertibleBonds = lines[70].split()[1:-1]
        # 融资租入固定资产
        financingRentToFixedAsset = lines[71].split()[1:-1]
        # 现金的期末余额
        cashAtTheEndOfPeriod = lines[72].split()[1:-1]
        # 现金的期初余额
        cashAtTheBeginningOfPeriod = lines[73].split()[1:-1]
        # 现金等价物的期末余额
        cashEquivalentsAtTheEndOfPeriod = lines[74].split()[1:-1]
        # 现金等价物的期初余额
        cashEquivalentsAtTheBeginningOfPeriod = lines[75].split()[1:-1]
        # 现金及现金等价物的净增加额
        netIncreaseInCashAndCashEquivalents = lines[76].split()[1:-1]
        result_json = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            if report_period and not is_same_date(report_period,
                                                  reportDate[idx]):
                continue

            reportEventDate = get_report_event_date(
                security_item, report_date=reportDate[idx])

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(
                    report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id":
                '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate":
                to_time_str(reportDate[idx]),
                "reportEventDate":
                reportEventDate,
                "securityId":
                security_item["id"],
                "code":
                security_item["code"],
                # /*一、经营活动产生的现金流量*/
                # 销售商品、提供劳务收到的现金
                "cashFromSellingCommoditiesOrOfferingLabor":
                to_float(cashFromSellingCommoditiesOrOfferingLabor[idx]),
                # 收到的税费返还
                "refundOfTaxAndFeeReceived":
                to_float(refundOfTaxAndFeeReceived[idx]),
                # 收到的其他与经营活动有关的现金
                "cashReceivedRelatingToOtherOperatingActivities":
                to_float(cashReceivedRelatingToOtherOperatingActivities[idx]),
                # 经营活动现金流入小计
                "subTotalOfCashInflowsFromOperatingActivities":
                to_float(subTotalOfCashInflowsFromOperatingActivities[idx]),
                # 购买商品、接受劳务支付的现金
                "cashPaidForGoodsAndServices":
                to_float(cashPaidForGoodsAndServices[idx]),
                # 支付给职工以及为职工支付的现金
                "cashPaidToAndOnBehalfOfemployees":
                to_float(cashPaidToAndOnBehalfOfemployees[idx]),
                # 支付的各项税费
                "paymentsOfTaxesAndSurcharges":
                to_float(paymentsOfTaxesAndSurcharges[idx]),
                # 支付的其他与经营活动有关的现金
                "cashPaidRelatingToOtherOperatingActivities":
                to_float(cashPaidRelatingToOtherOperatingActivities[idx]),
                # 经营活动现金流出小计
                "subTotalOfCashOutflowsFromOperatingActivities":
                to_float(subTotalOfCashOutflowsFromOperatingActivities[idx]),
                # 经营活动产生的现金流量净额
                "netCashFlowsFromOperatingActivities":
                to_float(netCashFlowsFromOperatingActivities[idx]),
                # /*二、投资活动产生的现金流量*/
                # 收回投资所收到的现金
                "cashReceivedFromDisposalOfInvestments":
                to_float(cashReceivedFromDisposalOfInvestments[idx]),
                # 取得投资收益所收到的现金
                "cashReceivedFromReturnsOnIvestments":
                to_float(cashReceivedFromReturnsOnIvestments[idx]),
                # 处置固定资产、无形资产和其他长期资产所收回的现金净额
                "netCashReceivedFromDisposalAssets":
                to_float(netCashReceivedFromDisposalAssets[idx]),
                # 处置子公司及其他营业单位收到的现金净额
                "netCashReceivedFromDisposalSubsidiaries":
                to_float(netCashReceivedFromDisposalSubsidiaries[idx]),
                # 收到的其他与投资活动有关的现金
                "cashReceivedFromOtherInvesting":
                to_float(cashReceivedFromOtherInvesting[idx]),
                # 投资活动现金流入小计
                "subTotalOfCashInflowsFromInvesting":
                to_float(subTotalOfCashInflowsFromInvesting[idx]),
                # 购建固定资产、无形资产和其他长期资产所支付的现金
                "cashPaidToAcquireFixedAssets":
                to_float(cashPaidToAcquireFixedAssets[idx]),
                # 投资所支付的现金
                "cashPaidToAcquireInvestments":
                to_float(cashPaidToAcquireInvestments[idx]),
                # 取得子公司及其他营业单位支付的现金净额
                "netCashPaidToAcquireSubsidiaries":
                to_float(netCashPaidToAcquireSubsidiaries[idx]),
                # 支付的其他与投资活动有关的现金
                "cashPaidRelatingToOtherInvesting":
                to_float(cashPaidRelatingToOtherInvesting[idx]),
                # 投资活动现金流出小计
                "subTotalOfCashOutflowsFromInvesting":
                to_float(subTotalOfCashOutflowsFromInvesting[idx]),
                # 投资活动产生的现金流量净额
                "netCashFlowsFromInvesting":
                to_float(netCashFlowsFromInvesting[idx]),
                # /*三、筹资活动产生的现金流量*/
                # 吸收投资收到的现金
                "cashReceivedFromCapitalContributions":
                to_float(cashReceivedFromCapitalContributions[idx]),
                # 其中:子公司吸收少数股东投资收到的现金
                "cashReceivedFromMinorityShareholdersOfSubsidiaries":
                cashReceivedFromMinorityShareholdersOfSubsidiaries[idx],
                # 取得借款收到的现金
                "cashReceivedFromBorrowings":
                to_float(cashReceivedFromBorrowings[idx]),
                # 发行债券收到的现金
                "cashReceivedFromIssuingBonds":
                to_float(cashReceivedFromIssuingBonds[idx]),
                # 收到其他与筹资活动有关的现金
                "cashReceivedRelatingToOtherFinancingActivities":
                to_float(cashReceivedRelatingToOtherFinancingActivities[idx]),
                # 筹资活动现金流入小计
                "subTotalOfCashInflowsFromFinancingActivities":
                to_float(subTotalOfCashInflowsFromFinancingActivities[idx]),
                # 偿还债务支付的现金
                "cashRepaymentsOfBorrowings":
                to_float(cashRepaymentsOfBorrowings[idx]),
                # 分配股利、利润或偿付利息所支付的现金
                "cashPaymentsForInterestExpensesAndDistributionOfDividendsOrProfits":
                cashPaymentsForInterestExpensesAndDistributionOfDividendsOrProfits[
                    idx],
                # 其中:子公司支付给少数股东的股利、利润
                "cashPaymentsForDividendsOrProfitToMinorityShareholders":
                cashPaymentsForDividendsOrProfitToMinorityShareholders[idx],
                # 支付其他与筹资活动有关的现金
                "cashPaymentsRelatingToOtherFinancingActivities":
                to_float(cashPaymentsRelatingToOtherFinancingActivities[idx]),
                # 筹资活动现金流出小计
                "subTotalOfCashOutflowsFromFinancingActivities":
                to_float(subTotalOfCashOutflowsFromFinancingActivities[idx]),
                # 筹资活动产生的现金流量净额
                "netCashFlowsFromFinancingActivities":
                to_float(netCashFlowsFromFinancingActivities[idx]),
                # /*四、汇率变动对现金及现金等价物的影响*/
                "effectOfForeignExchangeRate":
                to_float(effectOfForeignExchangeRate[idx]),
                # /*五、现金及现金等价物净增加额*/
                "netIncreaseInCash":
                to_float(netIncreaseInCash[idx]),
                # 加:期初现金及现金等价物余额
                "cashAtBeginningOfyear":
                to_float(cashAtBeginningOfyear[idx]),
                # /*六、期末现金及现金等价物余额*/
                "cashAtEndOfyear":
                to_float(cashAtEndOfyear[idx]),
                # /*附注*/
                # 净利润
                "netProfit":
                to_float(netProfit[idx]),
                # 少数股东权益
                "minorityBookValue":
                to_float(minorityBookValue[idx]),
                # 未确认的投资损失
                "unrealisedInvestmentLosses":
                to_float(unrealisedInvestmentLosses[idx]),
                # 资产减值准备
                "allowanceForAssetDevaluation":
                to_float(allowanceForAssetDevaluation[idx]),
                # 固定资产折旧、油气资产折耗、生产性物资折旧
                "depreciationOfFixedAssets":
                to_float(depreciationOfFixedAssets[idx]),
                # 无形资产摊销
                "amorizationOfIntangibleAssets":
                to_float(amorizationOfIntangibleAssets[idx]),
                # 长期待摊费用摊销
                "longTermDeferredExpenses":
                to_float(longTermDeferredExpenses[idx]),
                # 待摊费用的减少
                "decreaseOfDeferredExpenses":
                to_float(decreaseOfDeferredExpenses[idx]),
                # 预提费用的增加
                "IncreaseOfwithholdingExpenses":
                to_float(IncreaseOfwithholdingExpenses[idx]),
                # 处置固定资产、无形资产和其他长期资产的损失
                "lossOnDisposalOfFixedAssets":
                to_float(lossOnDisposalOfFixedAssets[idx]),
                # 固定资产报废损失
                "lossOnFixedAssetsDamaged":
                to_float(lossOnFixedAssetsDamaged[idx]),
                # 公允价值变动损失
                "lossOnFairValueChange":
                to_float(lossOnFairValueChange[idx]),
                # 递延收益增加(减:减少)
                "changeOnDeferredRevenue":
                to_float(changeOnDeferredRevenue[idx]),
                # 预计负债
                "estimatedLiabilities":
                to_float(estimatedLiabilities[idx]),
                # 财务费用
                "financingExpenses":
                to_float(financingExpenses[idx]),
                # 投资损失
                "investmentLoss":
                to_float(investmentLoss[idx]),
                # 递延所得税资产减少
                "decreaseOnDeferredIncomeTaxAssets":
                to_float(decreaseOnDeferredIncomeTaxAssets[idx]),
                # 递延所得税负债增加
                "increaseOnDeferredIncomeTaxLiabilities":
                to_float(increaseOnDeferredIncomeTaxLiabilities[idx]),
                # 存货的减少
                "decreaseInInventories":
                to_float(decreaseInInventories[idx]),
                # 经营性应收项目的减少
                "decreaseInReceivablesUnderOperatingActivities":
                to_float(decreaseInReceivablesUnderOperatingActivities[idx]),
                # 经营性应付项目的增加
                "increaseInReceivablesUnderOperatingActivities":
                to_float(increaseInReceivablesUnderOperatingActivities[idx]),
                # 已完工尚未结算款的减少(减:增加)
                "decreaseOnAmountDue":
                to_float(decreaseOnAmountDue[idx]),
                # 已结算尚未完工款的增加(减:减少)
                "increaseOnSettlementNotYetCompleted":
                to_float(increaseOnSettlementNotYetCompleted[idx]),
                # 其他
                "other":
                to_float(other[idx]),
                # 经营活动产生现金流量净额
                "netCashFlowFromOperatingActivities":
                to_float(netCashFlowFromOperatingActivities[idx]),
                # 债务转为资本
                "debtsTransferToCapital":
                to_float(debtsTransferToCapital[idx]),
                # 一年内到期的可转换公司债券
                "oneYearDueConvertibleBonds":
                to_float(oneYearDueConvertibleBonds[idx]),
                # 融资租入固定资产
                "financingRentToFixedAsset":
                to_float(financingRentToFixedAsset[idx]),
                # 现金的期末余额
                "cashAtTheEndOfPeriod":
                to_float(cashAtTheEndOfPeriod[idx]),
                # 现金的期初余额
                "cashAtTheBeginningOfPeriod":
                to_float(cashAtTheBeginningOfPeriod[idx]),
                # 现金等价物的期末余额
                "cashEquivalentsAtTheEndOfPeriod":
                to_float(cashEquivalentsAtTheEndOfPeriod[idx]),
                # 现金等价物的期初余额
                "cashEquivalentsAtTheBeginningOfPeriod":
                to_float(cashEquivalentsAtTheBeginningOfPeriod[idx]),
                # 现金及现金等价物的净增加额
                "netIncreaseInCashAndCashEquivalents":
                to_float(netIncreaseInCashAndCashEquivalents[idx])
            }

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_json

            result_json.append(the_json)

        if result_json:
            result_json = sorted(result_json,
                                 key=lambda x: pd.Timestamp(x['reportDate']))

        return result_json
Пример #22
0
def get_income_statement_items(security_item,
                               start_date=None,
                               report_period=None,
                               report_event_date=None):
    path = get_income_statement_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = settings.DOWNLOAD_TXT_ENCODING if settings.DOWNLOAD_TXT_ENCODING else detect_encoding(
        url='file://' + os.path.abspath(path)).get('encoding')

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()
        # for idx, line in enumerate(lines):
        #     yield idx, line.split()

        reportDate = lines[0].split()[1:-1]
        # /*营业总收入*/
        # 营业收入
        operatingRevenue = lines[2].split()[1:-1]
        # /*营业总成本*/
        OperatingTotalCosts = lines[4].split()[1:-1]
        # 营业成本
        OperatingCosts = lines[5].split()[1:-1]
        # 营业税金及附加
        businessTaxesAndSurcharges = lines[6].split()[1:-1]
        # 销售费用
        sellingExpenses = lines[7].split()[1:-1]
        # 管理费用
        ManagingCosts = lines[8].split()[1:-1]
        # 财务费用
        financingExpenses = lines[9].split()[1:-1]
        # 资产减值损失
        assetsDevaluation = lines[10].split()[1:-1]
        # 公允价值变动收益
        incomeFromChangesInFairValue = lines[11].split()[1:-1]
        # 投资收益
        investmentIncome = lines[12].split()[1:-1]
        # 其中:对联营企业和合营企业的投资收益
        investmentIncomeFromRelatedEnterpriseAndJointlyOperating = lines[
            13].split()[1:-1]
        # 汇兑收益
        exchangeGains = lines[14].split()[1:-1]
        # /*营业利润*/
        operatingProfit = lines[15].split()[1:-1]
        # 加:营业外收入
        nonOperatingIncome = lines[16].split()[1:-1]
        # 减:营业外支出
        nonOperatingExpenditure = lines[17].split()[1:-1]
        # 其中:非流动资产处置损失
        disposalLossOnNonCurrentLiability = lines[18].split()[1:-1]
        # /*利润总额*/
        totalProfits = lines[19].split()[1:-1]
        # 减:所得税费用
        incomeTaxExpense = lines[20].split()[1:-1]
        # /*净利润*/
        netProfit = lines[21].split()[1:-1]
        # 归属于母公司所有者的净利润
        netProfitAttributedToParentCompanyOwner = lines[22].split()[1:-1]
        # 少数股东损益
        minorityInterestIncome = lines[23].split()[1:-1]
        # /*每股收益*/
        # 基本每股收益(元/股)
        EPS = lines[25].split()[1:-1]
        # 稀释每股收益(元/股)
        dilutedEPS = lines[26].split()[1:-1]
        # /*其他综合收益*/
        otherComprehensiveIncome = lines[27].split()[1:-1]
        # /*综合收益总额*/
        accumulatedOtherComprehensiveIncome = lines[28].split()[1:-1]
        # 归属于母公司所有者的综合收益总额
        attributableToOwnersOfParentCompany = lines[29].split()[1:-1]
        # 归属于少数股东的综合收益总额
        attributableToMinorityShareholders = lines[30].split()[1:-1]

        result_json = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            if report_period and not is_same_date(report_period,
                                                  reportDate[idx]):
                continue

            reportEventDate = get_report_event_date(
                security_item, report_date=reportDate[idx])

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(
                    report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id":
                '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate":
                to_time_str(reportDate[idx]),
                "reportEventDate":
                reportEventDate,
                "securityId":
                security_item["id"],
                "code":
                security_item["code"],
                # /*营业总收入*/
                # 营业收入
                "operatingRevenue":
                to_float(operatingRevenue[idx]),
                # /*营业总成本*/
                "OperatingTotalCosts":
                to_float(OperatingTotalCosts[idx]),
                # 营业成本
                "OperatingCosts":
                to_float(OperatingCosts[idx]),
                # 营业税金及附加
                "businessTaxesAndSurcharges":
                to_float(businessTaxesAndSurcharges[idx]),
                # 销售费用
                "sellingExpenses":
                to_float(sellingExpenses[idx]),
                # 管理费用
                "ManagingCosts":
                to_float(ManagingCosts[idx]),
                # 财务费用
                "financingExpenses":
                to_float(financingExpenses[idx]),
                # 资产减值损失
                "assetsDevaluation":
                to_float(assetsDevaluation[idx]),
                # 公允价值变动收益
                "incomeFromChangesInFairValue":
                to_float(incomeFromChangesInFairValue[idx]),
                # 投资收益
                "investmentIncome":
                to_float(investmentIncome[idx]),
                # 其中:对联营企业和合营企业的投资收益
                "investmentIncomeFromRelatedEnterpriseAndJointlyOperating":
                investmentIncomeFromRelatedEnterpriseAndJointlyOperating[idx],
                # 汇兑收益
                "exchangeGains":
                to_float(exchangeGains[idx]),
                # /*营业利润*/
                "operatingProfit":
                to_float(operatingProfit[idx]),
                # 加:营业外收入
                "nonOperatingIncome":
                to_float(nonOperatingIncome[idx]),
                # 减:营业外支出
                "nonOperatingExpenditure":
                to_float(nonOperatingExpenditure[idx]),
                # 其中:非流动资产处置损失
                "disposalLossOnNonCurrentLiability":
                to_float(disposalLossOnNonCurrentLiability[idx]),
                # /*利润总额*/
                "totalProfits":
                to_float(totalProfits[idx]),
                # 减:所得税费用
                "incomeTaxExpense":
                to_float(incomeTaxExpense[idx]),
                # /*净利润*/
                "netProfit":
                to_float(netProfit[idx]),
                # 归属于母公司所有者的净利润
                "netProfitAttributedToParentCompanyOwner":
                to_float(netProfitAttributedToParentCompanyOwner[idx]),
                # 少数股东损益
                "minorityInterestIncome":
                to_float(minorityInterestIncome[idx]),
                # /*每股收益*/
                # 基本每股收益(元/股)
                "EPS":
                to_float(EPS[idx]),
                # 稀释每股收益(元/股)
                "dilutedEPS":
                to_float(dilutedEPS[idx]),
                # /*其他综合收益*/
                "otherComprehensiveIncome":
                to_float(otherComprehensiveIncome[idx]),
                # /*综合收益总额*/
                "accumulatedOtherComprehensiveIncome":
                to_float(accumulatedOtherComprehensiveIncome[idx]),
                # 归属于母公司所有者的综合收益总额
                "attributableToOwnersOfParentCompany":
                to_float(attributableToOwnersOfParentCompany[idx]),
                # 归属于少数股东的综合收益总额
                "attributableToMinorityShareholders":
                to_float(attributableToMinorityShareholders[idx])
            }

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_json

            result_json.append(the_json)

        if result_json:
            result_json = sorted(result_json,
                                 key=lambda x: pd.Timestamp(x['reportDate']))
        return result_json
Пример #23
0
def get_balance_sheet_items(security_item,
                            start_date=None,
                            report_period=None,
                            report_event_date=None):
    path = get_balance_sheet_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = settings.DOWNLOAD_TXT_ENCODING if settings.DOWNLOAD_TXT_ENCODING else detect_encoding(
        url='file://' + os.path.abspath(path)).get('encoding')

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()

        # for idx, line in enumerate(lines):
        #     yield idx, line.split()

        reportDate = lines[0].split()[1:-1]
        # 货币资金
        moneyFunds = lines[3].split()[1:-1]
        # 交易性金融资产
        heldForTradingFinancialAssets = lines[4].split()[1:-1]
        # 衍生金融资产
        derivative = lines[5].split()[1:-1]
        # 应收票据
        billsReceivable = lines[6].split()[1:-1]
        # 应收账款
        accountsReceivable = lines[7].split()[1:-1]
        # 预付款项
        prepaidAccounts = lines[8].split()[1:-1]
        # 应收利息
        interestReceivable = lines[9].split()[1:-1]
        # 应收股利
        dividendReceivable = lines[10].split()[1:-1]
        # 其他应收款
        otherReceivables = lines[11].split()[1:-1]

        # 买入返售金融资产
        buyingBackTheSaleOfFinancialAssets = lines[12].split()[1:-1]
        # 存货
        inventory = lines[13].split()[1:-1]
        # 划分为持有待售的资产
        assetsForSale = lines[14].split()[1:-1]
        # 一年内到期的非流动资产
        nonCurrentAssetsDueWithinOneYear = lines[15].split()[1:-1]

        # 待摊费用
        unamortizedExpenditures = lines[16].split()[1:-1]
        # 待处理流动资产损益
        waitDealIntangibleAssetsLossOrIncome = lines[17].split()[1:-1]

        # 其他流动资产
        otherCurrentAssets = lines[18].split()[1:-1]
        # 流动资产合计
        totalCurrentAssets = lines[19].split()[1:-1]

        # 非流动资产

        # 发放贷款及垫款
        loansAndPaymentsOnBehalf = lines[21].split()[1:-1]

        # 可供出售金融资产
        availableForSaleFinancialAssets = lines[22].split()[1:-1]
        # 持有至到期投资
        heldToMaturityInvestment = lines[23].split()[1:-1]
        # 长期应收款
        longTermReceivables = lines[24].split()[1:-1]
        # 长期股权投资
        longTermEquityInvestment = lines[25].split()[1:-1]
        # 投资性房地产
        investmentRealEstate = lines[26].split()[1:-1]
        # 固定资产净额
        NetfixedAssets = lines[27].split()[1:-1]
        # 在建工程
        constructionInProcess = lines[28].split()[1:-1]
        # 工程物资
        engineerMaterial = lines[29].split()[1:-1]
        # 固定资产清理
        fixedAssetsInLiquidation = lines[30].split()[1:-1]
        # 生产性生物资产
        productiveBiologicalAssets = lines[31].split()[1:-1]
        # 公益性生物资产
        nonProfitLivingAssets = lines[32].split()[1:-1]
        # 油气资产
        oilAndGasAssets = lines[33].split()[1:-1]
        # 无形资产
        intangibleAssets = lines[34].split()[1:-1]
        # 开发支出
        developmentExpenditure = lines[35].split()[1:-1]
        # 商誉
        goodwill = lines[36].split()[1:-1]
        # 长期待摊费用
        longTermDeferredExpenses = lines[37].split()[1:-1]
        # 递延所得税资产
        deferredIncomeTaxAssets = lines[38].split()[1:-1]
        # 其他非流动资产
        OtherNonCurrentAssets = lines[39].split()[1:-1]
        # 非流动资产合计
        nonCurrentAssets = lines[40].split()[1:-1]
        # 资产总计
        totalAssets = lines[41].split()[1:-1]

        # / *流动负债 * /
        # 短期借款
        shortTermBorrowing = lines[43].split()[1:-1]
        # 交易性金融负债
        transactionFinancialLiabilities = lines[44].split()[1:-1]
        # 应付票据
        billsPayable = lines[45].split()[1:-1]
        # 应付账款
        accountsPayable = lines[46].split()[1:-1]
        # 预收款项
        accountsReceivedInAdvance = lines[47].split()[1:-1]
        # 应付手续费及佣金
        handlingChargesAndCommissionsPayable = lines[48].split()[1:-1]
        # 应付职工薪酬
        employeeBenefitsPayable = lines[49].split()[1:-1]
        # 应交税费
        taxesAndSurchargesPayable = lines[50].split()[1:-1]
        # 应付利息
        interestPayable = lines[51].split()[1:-1]
        # 应付股利
        dividendpayable = lines[52].split()[1:-1]
        # 其他应付款
        otherPayables = lines[53].split()[1:-1]
        # 预提费用
        withholdingExpenses = lines[54].split()[1:-1]
        # 一年内的递延收益
        deferredIncomeWithinOneYear = lines[55].split()[1:-1]
        # 应付短期债券
        shortTermDebenturesPayable = lines[56].split()[1:-1]
        # 一年内到期的非流动负债
        nonCurrentLiabilitiesMaturingWithinOneYear = lines[57].split()[1:-1]
        # 其他流动负债
        otherCurrentLiability = lines[58].split()[1:-1]
        # 流动负债合计
        totalCurrentLiabilities = lines[59].split()[1:-1]

        # / *非流动负债 * /
        # 长期借款
        LongTermBorrowing = lines[61].split()[1:-1]
        # 应付债券
        bondPayable = lines[62].split()[1:-1]
        # 长期应付款
        longTermPayables = lines[63].split()[1:-1]
        # 长期应付职工薪酬
        longTermEmployeeBenefitsPayable = lines[64].split()[1:-1]
        # 专项应付款
        specialPayable = lines[65].split()[1:-1]
        # 预计非流动负债
        expectedNonCurrentLiabilities = lines[66].split()[1:-1]
        # 递延所得税负债
        deferredIncomeTaxLiabilities = lines[67].split()[1:-1]
        # 长期递延收益
        longTermDeferredRevenue = lines[68].split()[1:-1]
        # 其他非流动负债
        otherNonCurrentLiabilities = lines[69].split()[1:-1]
        # 非流动负债合计
        totalNonCurrentLiabilities = lines[70].split()[1:-1]
        # 负债合计
        totalLiabilities = lines[71].split()[1:-1]

        # / *所有者权益 * /
        # 实收资本(或股本)
        totalShareCapital = lines[73].split()[1:-1]

        # 资本公积
        capitalSurplus = lines[74].split()[1:-1]
        # 减:库存股
        treasuryStock = lines[75].split()[1:-1]
        # 其他综合收益
        otherComprehensiveIncome = lines[76].split()[1:-1]
        # 专项储备
        theSpecialReserve = lines[77].split()[1:-1]

        # 盈余公积
        surplusReserves = lines[78].split()[1:-1]
        # 一般风险准备
        generalRiskPreparation = lines[79].split()[1:-1]
        # 未分配利润
        undistributedProfits = lines[80].split()[1:-1]
        # 归属于母公司股东权益合计(净资产)
        bookValue = lines[81].split()[1:-1]

        # 少数股东权益
        minorityBookValue = lines[82].split()[1:-1]

        # 所有者权益(或股东权益)合计
        totalBookValue = lines[83].split()[1:-1]

        # 负债和所有者权益(或股东权益)总计
        totalLiabilitiesAndOwnersEquity = lines[84].split()[1:-1]

        result_json = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            reportEventDate = get_report_event_date(
                security_item, report_date=reportDate[idx])

            if report_period and not is_same_date(report_period,
                                                  reportDate[idx]):
                continue

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(
                    report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id":
                '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate":
                to_time_str(reportDate[idx]),
                "reportEventDate":
                reportEventDate,
                "securityId":
                security_item["id"],
                "code":
                security_item["code"],
                # 货币资金
                "moneyFunds":
                to_float(moneyFunds[idx]),
                # 交易性金融资产
                "heldForTradingFinancialAssets":
                to_float(heldForTradingFinancialAssets[idx]),
                # 衍生金融资产
                "derivative":
                to_float(derivative[idx]),
                # 应收票据
                "billsReceivable":
                to_float(billsReceivable[idx]),
                # 应收账款
                "accountsReceivable":
                to_float(accountsReceivable[idx]),
                # 预付款项
                "prepaidAccounts":
                to_float(prepaidAccounts[idx]),
                # 应收利息
                "interestReceivable":
                to_float(interestReceivable[idx]),
                # 应收股利
                "dividendReceivable":
                to_float(dividendReceivable[idx]),
                # 其他应收款
                "otherReceivables":
                to_float(otherReceivables[idx]),

                # 买入返售金融资产
                "buyingBackTheSaleOfFinancialAssets":
                to_float(buyingBackTheSaleOfFinancialAssets[idx]),
                # 存货
                "inventory":
                to_float(inventory[idx]),
                # 划分为持有待售的资产
                "assetsForSale":
                to_float(assetsForSale[idx]),
                # 一年内到期的非流动资产
                "nonCurrentAssetsDueWithinOneYear":
                to_float(nonCurrentAssetsDueWithinOneYear[idx]),

                # 待摊费用
                "unamortizedExpenditures":
                to_float(unamortizedExpenditures[idx]),
                # 待处理流动资产损益
                "waitDealIntangibleAssetsLossOrIncome":
                to_float(waitDealIntangibleAssetsLossOrIncome[idx]),

                # 其他流动资产
                "otherCurrentAssets":
                to_float(otherCurrentAssets[idx]),
                # 流动资产合计
                "totalCurrentAssets":
                to_float(totalCurrentAssets[idx]),

                # 非流动资产

                # 发放贷款及垫款
                "loansAndPaymentsOnBehalf":
                to_float(loansAndPaymentsOnBehalf[idx]),

                # 可供出售金融资产
                "availableForSaleFinancialAssets":
                to_float(availableForSaleFinancialAssets[idx]),
                # 持有至到期投资
                "heldToMaturityInvestment":
                to_float(heldToMaturityInvestment[idx]),
                # 长期应收款
                "longTermReceivables":
                to_float(longTermReceivables[idx]),
                # 长期股权投资
                "longTermEquityInvestment":
                to_float(longTermEquityInvestment[idx]),
                # 投资性房地产
                "investmentRealEstate":
                to_float(investmentRealEstate[idx]),
                # 固定资产净额
                "NetfixedAssets":
                to_float(NetfixedAssets[idx]),
                # 在建工程
                "constructionInProcess":
                to_float(constructionInProcess[idx]),
                # 工程物资
                "engineerMaterial":
                to_float(engineerMaterial[idx]),
                # 固定资产清理
                "fixedAssetsInLiquidation":
                to_float(fixedAssetsInLiquidation[idx]),
                # 生产性生物资产
                "productiveBiologicalAssets":
                to_float(productiveBiologicalAssets[idx]),
                # 公益性生物资产
                "nonProfitLivingAssets":
                to_float(nonProfitLivingAssets[idx]),
                # 油气资产
                "oilAndGasAssets":
                to_float(oilAndGasAssets[idx]),
                # 无形资产
                "intangibleAssets":
                to_float(intangibleAssets[idx]),
                # 开发支出
                "developmentExpenditure":
                to_float(developmentExpenditure[idx]),
                # 商誉
                "goodwill":
                to_float(goodwill[idx]),
                # 长期待摊费用
                "longTermDeferredExpenses":
                to_float(longTermDeferredExpenses[idx]),
                # 递延所得税资产
                "deferredIncomeTaxAssets":
                to_float(deferredIncomeTaxAssets[idx]),
                # 其他非流动资产
                "OtherNonCurrentAssets":
                to_float(OtherNonCurrentAssets[idx]),
                # 非流动资产合计
                "nonCurrentAssets":
                to_float(nonCurrentAssets[idx]),
                # 资产总计
                "totalAssets":
                to_float(totalAssets[idx]),

                # / *流动负债 * /
                # 短期借款
                "shortTermBorrowing":
                to_float(shortTermBorrowing[idx]),
                # 交易性金融负债
                "transactionFinancialLiabilities":
                to_float(transactionFinancialLiabilities[idx]),
                # 应付票据
                "billsPayable":
                to_float(billsPayable[idx]),
                # 应付账款
                "accountsPayable":
                to_float(accountsPayable[idx]),
                # 预收款项
                "accountsReceivedInAdvance":
                to_float(accountsReceivedInAdvance[idx]),
                # 应付手续费及佣金
                "handlingChargesAndCommissionsPayable":
                to_float(handlingChargesAndCommissionsPayable[idx]),
                # 应付职工薪酬
                "employeeBenefitsPayable":
                to_float(employeeBenefitsPayable[idx]),
                # 应交税费
                "taxesAndSurchargesPayable":
                to_float(taxesAndSurchargesPayable[idx]),
                # 应付利息
                "interestPayable":
                to_float(interestPayable[idx]),
                # 应付股利
                "dividendpayable":
                to_float(dividendpayable[idx]),
                # 其他应付款
                "otherPayables":
                to_float(otherPayables[idx]),
                # 预提费用
                "withholdingExpenses":
                to_float(withholdingExpenses[idx]),
                # 一年内的递延收益
                "deferredIncomeWithinOneYear":
                to_float(deferredIncomeWithinOneYear[idx]),
                # 应付短期债券
                "shortTermDebenturesPayable":
                to_float(shortTermDebenturesPayable[idx]),
                # 一年内到期的非流动负债
                "nonCurrentLiabilitiesMaturingWithinOneYear":
                to_float(nonCurrentLiabilitiesMaturingWithinOneYear[idx]),
                # 其他流动负债
                "otherCurrentLiability":
                to_float(otherCurrentLiability[idx]),
                # 流动负债合计
                "totalCurrentLiabilities":
                to_float(totalCurrentLiabilities[idx]),

                # / *非流动负债 * /
                # 长期借款
                "LongTermBorrowing":
                to_float(LongTermBorrowing[idx]),
                # 应付债券
                "bondPayable":
                to_float(bondPayable[idx]),
                # 长期应付款
                "longTermPayables":
                to_float(longTermPayables[idx]),
                # 长期应付职工薪酬
                "longTermEmployeeBenefitsPayable":
                to_float(longTermEmployeeBenefitsPayable[idx]),
                # 专项应付款
                "specialPayable":
                to_float(specialPayable[idx]),
                # 预计非流动负债
                "expectedNonCurrentLiabilities":
                to_float(expectedNonCurrentLiabilities[idx]),
                # 递延所得税负债
                "deferredIncomeTaxLiabilities":
                to_float(deferredIncomeTaxLiabilities[idx]),
                # 长期递延收益
                "longTermDeferredRevenue":
                to_float(longTermDeferredRevenue[idx]),
                # 其他非流动负债
                "otherNonCurrentLiabilities":
                to_float(otherNonCurrentLiabilities[idx]),
                # 非流动负债合计
                "totalNonCurrentLiabilities":
                to_float(totalNonCurrentLiabilities[idx]),
                # 负债合计
                "totalLiabilities":
                to_float(totalLiabilities[idx]),

                # / *所有者权益 * /
                # 实收资本(或股本)
                "totalShareCapital":
                to_float(totalShareCapital[idx]),

                # 资本公积
                "capitalSurplus":
                to_float(capitalSurplus[idx]),
                # 减:库存股
                "treasuryStock":
                to_float(treasuryStock[idx]),
                # 其他综合收益
                "otherComprehensiveIncome":
                to_float(otherComprehensiveIncome[idx]),
                # 专项储备
                "theSpecialReserve":
                to_float(theSpecialReserve[idx]),

                # 盈余公积
                "surplusReserves":
                to_float(surplusReserves[idx]),
                # 一般风险准备
                "generalRiskPreparation":
                to_float(generalRiskPreparation[idx]),
                # 未分配利润
                "undistributedProfits":
                to_float(undistributedProfits[idx]),
                # 归属于母公司股东权益合计(净资产)
                "bookValue":
                to_float(bookValue[idx]),

                # 少数股东权益
                "minorityBookValue":
                to_float(minorityBookValue[idx]),

                # 所有者权益(或股东权益)合计
                "totalBookValue":
                to_float(totalBookValue[idx]),

                # 负债和所有者权益(或股东权益)总计
                "totalLiabilitiesAndOwnersEquity":
                to_float(totalLiabilitiesAndOwnersEquity[idx])
            }

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_json

            result_json.append(the_json)

        if (result_json):
            result_json = sorted(result_json,
                                 key=lambda x: pd.Timestamp(x['reportDate']))
        return result_json
Пример #24
0
    def consume_topic_with_func(self, topic, func):
        if not topic:
            while True:
                self.on_timer({"timestamp": self.current_time})

                if is_same_date(self.current_time, pd.Timestamp.now()):
                    time.sleep(self.time_step.total_seconds())

                self.current_time += self.time_step

        consumer = KafkaConsumer(
            topic,
            # client_id='fooltrader',
            # group_id=self.bot_name,
            value_deserializer=lambda m: json.loads(m.decode('utf8')),
            bootstrap_servers=[KAFKA_HOST])
        topic_partition = TopicPartition(topic=topic, partition=0)
        start_timestamp = int(self.start_date.timestamp())

        end_offset = consumer.end_offsets([topic_partition])[topic_partition]
        if end_offset == 0:
            self.logger.warning("topic:{} end offset:{}".format(
                topic, end_offset))
            # 等有数据才能做进一步的判断
            for message in consumer:
                self.logger.info("first message:{} to topic:{}".format(
                    message, topic))
                break
            consumer.poll(5, 1)
            consumer.seek(topic_partition, 0)

        # 找到以start_timestamp为起点的offset
        partition_map_offset_and_timestamp = consumer.offsets_for_times(
            {topic_partition: start_timestamp})

        if partition_map_offset_and_timestamp:
            offset_and_timestamp = partition_map_offset_and_timestamp[
                topic_partition]

            if offset_and_timestamp:
                # partition  assigned after poll, and we could seek
                consumer.poll(5, 1)
                # move to the offset
                consumer.seek(topic_partition, offset_and_timestamp.offset)
                # 目前的最大offset
                end_offset = consumer.end_offsets([topic_partition
                                                   ])[topic_partition]
                for message in consumer:
                    if 'timestamp' in message.value:
                        message_time = to_timestamp(message.value['timestamp'])
                    else:
                        message_time = to_timestamp(message.timestamp)

                    # 设定了结束日期的话,时间到了或者kafka没数据了就结束
                    if self.end_date and (message_time > self.end_date
                                          or message.offset + 1 == end_offset):
                        consumer.close()
                        break

                    self.current_time = message_time

                    # 收市后计算
                    if False:
                        self.account_service.calculate_closing_account(
                            self.current_time)

                    # self.on_event(message.value)
                    getattr(self, func)(message.value)

            else:
                consumer.poll(5, 1)
                consumer.seek(
                    topic_partition,
                    consumer.end_offsets([topic_partition])[topic_partition] -
                    1)
                message = consumer.poll(5000, 1)
                kafka_end_date = datetime.fromtimestamp(
                    message[topic_partition][0].timestamp).strftime(
                        TIME_FORMAT_DAY)
                self.logger.warning(
                    "start:{} is after the last record:{}".format(
                        self.start_date, kafka_end_date))
Пример #25
0
def get_income_statement_items(security_item,
                               start_date=None,
                               report_period=None,
                               report_event_date=None,
                               return_type='json'):
    """
    get income statement items.

    Parameters
    ----------
    security_item : SecurityItem or str
        the security item,id or code
    start_date : TimeStamp str or TimeStamp
        start date
    report_period : TimeStamp str or TimeStamp
        the finance report period,eg.'20170331'
    report_event_date : TimeStamp str or TimeStamp
        the finance report published date
    return_type : str
        {'json','doc'},default: 'json'

    Returns
    -------
    list of IncomeStatement
    list of json

    """

    security_item = to_security_item(security_item)

    path = get_income_statement_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = 'GB2312'

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()
        # for idx, line in enumerate(lines):
        #     yield idx, line.split()

        reportDate = lines[0].split()[1:-1]
        # /*营业总收入*/
        # 营业收入
        operatingRevenue = lines[2].split()[1:-1]
        # /*营业总成本*/
        operatingTotalCosts = lines[4].split()[1:-1]
        # 营业成本
        operatingCosts = lines[5].split()[1:-1]
        # 营业税金及附加
        businessTaxesAndSurcharges = lines[6].split()[1:-1]
        # 销售费用
        sellingExpenses = lines[7].split()[1:-1]
        # 管理费用
        ManagingCosts = lines[8].split()[1:-1]
        # 财务费用
        financingExpenses = lines[9].split()[1:-1]
        # 资产减值损失
        assetsDevaluation = lines[10].split()[1:-1]
        # 公允价值变动收益
        incomeFromChangesInFairValue = lines[11].split()[1:-1]
        # 投资收益
        investmentIncome = lines[12].split()[1:-1]
        # 其中:对联营企业和合营企业的投资收益
        investmentIncomeFromRelatedEnterpriseAndJointlyOperating = lines[
            13].split()[1:-1]
        # 汇兑收益
        exchangeGains = lines[14].split()[1:-1]
        # /*营业利润*/
        operatingProfit = lines[15].split()[1:-1]
        # 加:营业外收入
        nonOperatingIncome = lines[16].split()[1:-1]
        # 减:营业外支出
        nonOperatingExpenditure = lines[17].split()[1:-1]
        # 其中:非流动资产处置损失
        disposalLossOnNonCurrentLiability = lines[18].split()[1:-1]
        # /*利润总额*/
        totalProfits = lines[19].split()[1:-1]
        # 减:所得税费用
        incomeTaxExpense = lines[20].split()[1:-1]
        # /*净利润*/
        netProfit = lines[21].split()[1:-1]
        # 归属于母公司所有者的净利润
        netProfitAttributedToParentCompanyOwner = lines[22].split()[1:-1]
        # 少数股东损益
        minorityInterestIncome = lines[23].split()[1:-1]
        # /*每股收益*/
        # 基本每股收益(元/股)
        EPS = lines[25].split()[1:-1]
        # 稀释每股收益(元/股)
        dilutedEPS = lines[26].split()[1:-1]
        # /*其他综合收益*/
        otherComprehensiveIncome = lines[27].split()[1:-1]
        # /*综合收益总额*/
        accumulatedOtherComprehensiveIncome = lines[28].split()[1:-1]
        # 归属于母公司所有者的综合收益总额
        attributableToOwnersOfParentCompany = lines[29].split()[1:-1]
        # 归属于少数股东的综合收益总额
        attributableToMinorityShareholders = lines[30].split()[1:-1]

        result_list = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            if report_period and not is_same_date(report_period,
                                                  reportDate[idx]):
                continue

            reportEventDate = get_report_event_date(
                security_item, report_date=reportDate[idx])

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(
                    report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id":
                '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate":
                to_time_str(reportDate[idx]),
                "reportEventDate":
                reportEventDate,
                "securityId":
                security_item["id"],
                "code":
                security_item["code"],
                # /*营业总收入*/
                # 营业收入
                "operatingRevenue":
                to_float(operatingRevenue[idx]),
                # /*营业总成本*/
                "operatingTotalCosts":
                to_float(operatingTotalCosts[idx]),
                # 营业成本
                "operatingCosts":
                to_float(operatingCosts[idx]),
                # 营业税金及附加
                "businessTaxesAndSurcharges":
                to_float(businessTaxesAndSurcharges[idx]),
                # 销售费用
                "sellingExpenses":
                to_float(sellingExpenses[idx]),
                # 管理费用
                "ManagingCosts":
                to_float(ManagingCosts[idx]),
                # 财务费用
                "financingExpenses":
                to_float(financingExpenses[idx]),
                # 资产减值损失
                "assetsDevaluation":
                to_float(assetsDevaluation[idx]),
                # 公允价值变动收益
                "incomeFromChangesInFairValue":
                to_float(incomeFromChangesInFairValue[idx]),
                # 投资收益
                "investmentIncome":
                to_float(investmentIncome[idx]),
                # 其中:对联营企业和合营企业的投资收益
                "investmentIncomeFromRelatedEnterpriseAndJointlyOperating":
                investmentIncomeFromRelatedEnterpriseAndJointlyOperating[idx],
                # 汇兑收益
                "exchangeGains":
                to_float(exchangeGains[idx]),
                # /*营业利润*/
                "operatingProfit":
                to_float(operatingProfit[idx]),
                # 加:营业外收入
                "nonOperatingIncome":
                to_float(nonOperatingIncome[idx]),
                # 减:营业外支出
                "nonOperatingExpenditure":
                to_float(nonOperatingExpenditure[idx]),
                # 其中:非流动资产处置损失
                "disposalLossOnNonCurrentLiability":
                to_float(disposalLossOnNonCurrentLiability[idx]),
                # /*利润总额*/
                "totalProfits":
                to_float(totalProfits[idx]),
                # 减:所得税费用
                "incomeTaxExpense":
                to_float(incomeTaxExpense[idx]),
                # /*净利润*/
                "netProfit":
                to_float(netProfit[idx]),
                # 归属于母公司所有者的净利润
                "netProfitAttributedToParentCompanyOwner":
                to_float(netProfitAttributedToParentCompanyOwner[idx]),
                # 少数股东损益
                "minorityInterestIncome":
                to_float(minorityInterestIncome[idx]),
                # /*每股收益*/
                # 基本每股收益(元/股)
                "EPS":
                to_float(EPS[idx]),
                # 稀释每股收益(元/股)
                "dilutedEPS":
                to_float(dilutedEPS[idx]),
                # /*其他综合收益*/
                "otherComprehensiveIncome":
                to_float(otherComprehensiveIncome[idx]),
                # /*综合收益总额*/
                "accumulatedOtherComprehensiveIncome":
                to_float(accumulatedOtherComprehensiveIncome[idx]),
                # 归属于母公司所有者的综合收益总额
                "attributableToOwnersOfParentCompany":
                to_float(attributableToOwnersOfParentCompany[idx]),
                # 归属于少数股东的综合收益总额
                "attributableToMinorityShareholders":
                to_float(attributableToMinorityShareholders[idx])
            }

            the_data = the_json

            if return_type == 'doc':
                the_data = IncomeStatement(meta={'id': the_json['id']})
                fill_doc_type(the_data, the_json)

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_data

            result_list.append(the_data)

        if result_list:
            result_list = sorted(result_list,
                                 key=lambda x: pd.Timestamp(x['reportDate']))
        return result_list
Пример #26
0
def get_cash_flow_statement_items(security_item, start_date=None, report_period=None, report_event_date=None):
    path = get_cash_flow_statement_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = settings.DOWNLOAD_TXT_ENCODING if settings.DOWNLOAD_TXT_ENCODING else detect_encoding(
        url='file://' + os.path.abspath(path)).get('encoding')

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()
        # for idx, line in enumerate(lines):
        #     yield idx, line.split()
        reportDate = lines[0].split()[1:-1]
        # /*一、经营活动产生的现金流量*/
        # 销售商品、提供劳务收到的现金
        cashFromSellingCommoditiesOrOfferingLabor = lines[3].split()[1:-1]
        # 收到的税费返还
        refundOfTaxAndFeeReceived = lines[4].split()[1:-1]
        # 收到的其他与经营活动有关的现金
        cashReceivedRelatingToOtherOperatingActivities = lines[5].split()[1:-1]
        # 经营活动现金流入小计
        subTotalOfCashInflowsFromOperatingActivities = lines[6].split()[1:-1]
        # 购买商品、接受劳务支付的现金
        cashPaidForGoodsAndServices = lines[7].split()[1:-1]
        # 支付给职工以及为职工支付的现金
        cashPaidToAndOnBehalfOfemployees = lines[8].split()[1:-1]
        # 支付的各项税费
        paymentsOfTaxesAndSurcharges = lines[9].split()[1:-1]
        # 支付的其他与经营活动有关的现金
        cashPaidRelatingToOtherOperatingActivities = lines[10].split()[1:-1]
        # 经营活动现金流出小计
        subTotalOfCashOutflowsFromOperatingActivities = lines[11].split()[1:-1]
        # 经营活动产生的现金流量净额
        netCashFlowsFromOperatingActivities = lines[12].split()[1:-1]
        # /*二、投资活动产生的现金流量*/
        # 收回投资所收到的现金
        cashReceivedFromDisposalOfInvestments = lines[14].split()[1:-1]
        # 取得投资收益所收到的现金
        cashReceivedFromReturnsOnIvestments = lines[15].split()[1:-1]
        # 处置固定资产、无形资产和其他长期资产所收回的现金净额
        netCashReceivedFromDisposalAssets = lines[16].split()[1:-1]
        # 处置子公司及其他营业单位收到的现金净额
        netCashReceivedFromDisposalSubsidiaries = lines[17].split()[1:-1]
        # 收到的其他与投资活动有关的现金
        cashReceivedFromOtherInvesting = lines[18].split()[1:-1]
        # 投资活动现金流入小计
        subTotalOfCashInflowsFromInvesting = lines[19].split()[1:-1]
        # 购建固定资产、无形资产和其他长期资产所支付的现金
        cashPaidToAcquireFixedAssets = lines[20].split()[1:-1]
        # 投资所支付的现金
        cashPaidToAcquireInvestments = lines[21].split()[1:-1]
        # 取得子公司及其他营业单位支付的现金净额
        netCashPaidToAcquireSubsidiaries = lines[22].split()[1:-1]
        # 支付的其他与投资活动有关的现金
        cashPaidRelatingToOtherInvesting = lines[23].split()[1:-1]
        # 投资活动现金流出小计
        subTotalOfCashOutflowsFromInvesting = lines[24].split()[1:-1]
        # 投资活动产生的现金流量净额
        netCashFlowsFromInvesting = lines[25].split()[1:-1]
        # /*三、筹资活动产生的现金流量*/
        # 吸收投资收到的现金
        cashReceivedFromCapitalContributions = lines[27].split()[1:-1]
        # 其中:子公司吸收少数股东投资收到的现金
        cashReceivedFromMinorityShareholdersOfSubsidiaries = lines[28].split()[1:-1]
        # 取得借款收到的现金
        cashReceivedFromBorrowings = lines[29].split()[1:-1]
        # 发行债券收到的现金
        cashReceivedFromIssuingBonds = lines[30].split()[1:-1]
        # 收到其他与筹资活动有关的现金
        cashReceivedRelatingToOtherFinancingActivities = lines[31].split()[1:-1]
        # 筹资活动现金流入小计
        subTotalOfCashInflowsFromFinancingActivities = lines[32].split()[1:-1]
        # 偿还债务支付的现金
        cashRepaymentsOfBorrowings = lines[33].split()[1:-1]
        # 分配股利、利润或偿付利息所支付的现金
        cashPaymentsForInterestExpensesAndDistributionOfDividendsOrProfits = lines[34].split()[1:-1]
        # 其中:子公司支付给少数股东的股利、利润
        cashPaymentsForDividendsOrProfitToMinorityShareholders = lines[35].split()[1:-1]
        # 支付其他与筹资活动有关的现金
        cashPaymentsRelatingToOtherFinancingActivities = lines[36].split()[1:-1]
        # 筹资活动现金流出小计
        subTotalOfCashOutflowsFromFinancingActivities = lines[37].split()[1:-1]
        # 筹资活动产生的现金流量净额
        netCashFlowsFromFinancingActivities = lines[38].split()[1:-1]
        # /*四、汇率变动对现金及现金等价物的影响*/
        effectOfForeignExchangeRate = lines[39].split()[1:-1]
        # /*五、现金及现金等价物净增加额*/
        netIncreaseInCash = lines[40].split()[1:-1]
        # 加:期初现金及现金等价物余额
        cashAtBeginningOfyear = lines[41].split()[1:-1]
        # /*六、期末现金及现金等价物余额*/
        cashAtEndOfyear = lines[42].split()[1:-1]
        # /*附注*/
        # 净利润
        netProfit = lines[44].split()[1:-1]
        # 少数股东权益
        minorityBookValue = lines[45].split()[1:-1]
        # 未确认的投资损失
        unrealisedInvestmentLosses = lines[46].split()[1:-1]
        # 资产减值准备
        allowanceForAssetDevaluation = lines[47].split()[1:-1]
        # 固定资产折旧、油气资产折耗、生产性物资折旧
        depreciationOfFixedAssets = lines[48].split()[1:-1]
        # 无形资产摊销
        amorizationOfIntangibleAssets = lines[49].split()[1:-1]
        # 长期待摊费用摊销
        longTermDeferredExpenses = lines[50].split()[1:-1]
        # 待摊费用的减少
        decreaseOfDeferredExpenses = lines[51].split()[1:-1]
        # 预提费用的增加
        IncreaseOfwithholdingExpenses = lines[52].split()[1:-1]
        # 处置固定资产、无形资产和其他长期资产的损失
        lossOnDisposalOfFixedAssets = lines[53].split()[1:-1]
        # 固定资产报废损失
        lossOnFixedAssetsDamaged = lines[54].split()[1:-1]
        # 公允价值变动损失
        lossOnFairValueChange = lines[55].split()[1:-1]
        # 递延收益增加(减:减少)
        changeOnDeferredRevenue = lines[56].split()[1:-1]
        # 预计负债
        estimatedLiabilities = lines[57].split()[1:-1]
        # 财务费用
        financingExpenses = lines[58].split()[1:-1]
        # 投资损失
        investmentLoss = lines[59].split()[1:-1]
        # 递延所得税资产减少
        decreaseOnDeferredIncomeTaxAssets = lines[60].split()[1:-1]
        # 递延所得税负债增加
        increaseOnDeferredIncomeTaxLiabilities = lines[61].split()[1:-1]
        # 存货的减少
        decreaseInInventories = lines[62].split()[1:-1]
        # 经营性应收项目的减少
        decreaseInReceivablesUnderOperatingActivities = lines[63].split()[1:-1]
        # 经营性应付项目的增加
        increaseInReceivablesUnderOperatingActivities = lines[64].split()[1:-1]
        # 已完工尚未结算款的减少(减:增加)
        decreaseOnAmountDue = lines[65].split()[1:-1]
        # 已结算尚未完工款的增加(减:减少)
        increaseOnSettlementNotYetCompleted = lines[66].split()[1:-1]
        # 其他
        other = lines[67].split()[1:-1]
        # 经营活动产生现金流量净额
        netCashFlowFromOperatingActivities = lines[68].split()[1:-1]
        # 债务转为资本
        debtsTransferToCapital = lines[69].split()[1:-1]
        # 一年内到期的可转换公司债券
        oneYearDueConvertibleBonds = lines[70].split()[1:-1]
        # 融资租入固定资产
        financingRentToFixedAsset = lines[71].split()[1:-1]
        # 现金的期末余额
        cashAtTheEndOfPeriod = lines[72].split()[1:-1]
        # 现金的期初余额
        cashAtTheBeginningOfPeriod = lines[73].split()[1:-1]
        # 现金等价物的期末余额
        cashEquivalentsAtTheEndOfPeriod = lines[74].split()[1:-1]
        # 现金等价物的期初余额
        cashEquivalentsAtTheBeginningOfPeriod = lines[75].split()[1:-1]
        # 现金及现金等价物的净增加额
        netIncreaseInCashAndCashEquivalents = lines[76].split()[1:-1]
        result_json = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            if report_period and not is_same_date(report_period, reportDate[idx]):
                continue

            reportEventDate = get_report_event_date(security_item, report_date=reportDate[idx])

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id": '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate": to_time_str(reportDate[idx]),
                "reportEventDate": reportEventDate,
                "securityId": security_item["id"],
                "code": security_item["code"],
                # /*一、经营活动产生的现金流量*/
                # 销售商品、提供劳务收到的现金
                "cashFromSellingCommoditiesOrOfferingLabor": to_float(cashFromSellingCommoditiesOrOfferingLabor[idx]),
                # 收到的税费返还
                "refundOfTaxAndFeeReceived": to_float(refundOfTaxAndFeeReceived[idx]),
                # 收到的其他与经营活动有关的现金
                "cashReceivedRelatingToOtherOperatingActivities": to_float(
                    cashReceivedRelatingToOtherOperatingActivities[idx]),
                # 经营活动现金流入小计
                "subTotalOfCashInflowsFromOperatingActivities": to_float(
                    subTotalOfCashInflowsFromOperatingActivities[idx]),
                # 购买商品、接受劳务支付的现金
                "cashPaidForGoodsAndServices": to_float(cashPaidForGoodsAndServices[idx]),
                # 支付给职工以及为职工支付的现金
                "cashPaidToAndOnBehalfOfemployees": to_float(cashPaidToAndOnBehalfOfemployees[idx]),
                # 支付的各项税费
                "paymentsOfTaxesAndSurcharges": to_float(paymentsOfTaxesAndSurcharges[idx]),
                # 支付的其他与经营活动有关的现金
                "cashPaidRelatingToOtherOperatingActivities": to_float(cashPaidRelatingToOtherOperatingActivities[idx]),
                # 经营活动现金流出小计
                "subTotalOfCashOutflowsFromOperatingActivities": to_float(
                    subTotalOfCashOutflowsFromOperatingActivities[idx]),
                # 经营活动产生的现金流量净额
                "netCashFlowsFromOperatingActivities": to_float(netCashFlowsFromOperatingActivities[idx]),
                # /*二、投资活动产生的现金流量*/
                # 收回投资所收到的现金
                "cashReceivedFromDisposalOfInvestments": to_float(cashReceivedFromDisposalOfInvestments[idx]),
                # 取得投资收益所收到的现金
                "cashReceivedFromReturnsOnIvestments": to_float(cashReceivedFromReturnsOnIvestments[idx]),
                # 处置固定资产、无形资产和其他长期资产所收回的现金净额
                "netCashReceivedFromDisposalAssets": to_float(netCashReceivedFromDisposalAssets[idx]),
                # 处置子公司及其他营业单位收到的现金净额
                "netCashReceivedFromDisposalSubsidiaries": to_float(netCashReceivedFromDisposalSubsidiaries[idx]),
                # 收到的其他与投资活动有关的现金
                "cashReceivedFromOtherInvesting": to_float(cashReceivedFromOtherInvesting[idx]),
                # 投资活动现金流入小计
                "subTotalOfCashInflowsFromInvesting": to_float(subTotalOfCashInflowsFromInvesting[idx]),
                # 购建固定资产、无形资产和其他长期资产所支付的现金
                "cashPaidToAcquireFixedAssets": to_float(cashPaidToAcquireFixedAssets[idx]),
                # 投资所支付的现金
                "cashPaidToAcquireInvestments": to_float(cashPaidToAcquireInvestments[idx]),
                # 取得子公司及其他营业单位支付的现金净额
                "netCashPaidToAcquireSubsidiaries": to_float(netCashPaidToAcquireSubsidiaries[idx]),
                # 支付的其他与投资活动有关的现金
                "cashPaidRelatingToOtherInvesting": to_float(cashPaidRelatingToOtherInvesting[idx]),
                # 投资活动现金流出小计
                "subTotalOfCashOutflowsFromInvesting": to_float(subTotalOfCashOutflowsFromInvesting[idx]),
                # 投资活动产生的现金流量净额
                "netCashFlowsFromInvesting": to_float(netCashFlowsFromInvesting[idx]),
                # /*三、筹资活动产生的现金流量*/
                # 吸收投资收到的现金
                "cashReceivedFromCapitalContributions": to_float(cashReceivedFromCapitalContributions[idx]),
                # 其中:子公司吸收少数股东投资收到的现金
                "cashReceivedFromMinorityShareholdersOfSubsidiaries":
                    cashReceivedFromMinorityShareholdersOfSubsidiaries[
                        idx],
                # 取得借款收到的现金
                "cashReceivedFromBorrowings": to_float(cashReceivedFromBorrowings[idx]),
                # 发行债券收到的现金
                "cashReceivedFromIssuingBonds": to_float(cashReceivedFromIssuingBonds[idx]),
                # 收到其他与筹资活动有关的现金
                "cashReceivedRelatingToOtherFinancingActivities": to_float(
                    cashReceivedRelatingToOtherFinancingActivities[idx]),
                # 筹资活动现金流入小计
                "subTotalOfCashInflowsFromFinancingActivities": to_float(
                    subTotalOfCashInflowsFromFinancingActivities[idx]),
                # 偿还债务支付的现金
                "cashRepaymentsOfBorrowings": to_float(cashRepaymentsOfBorrowings[idx]),
                # 分配股利、利润或偿付利息所支付的现金
                "cashPaymentsForInterestExpensesAndDistributionOfDividendsOrProfits":
                    cashPaymentsForInterestExpensesAndDistributionOfDividendsOrProfits[idx],
                # 其中:子公司支付给少数股东的股利、利润
                "cashPaymentsForDividendsOrProfitToMinorityShareholders":
                    cashPaymentsForDividendsOrProfitToMinorityShareholders[idx],
                # 支付其他与筹资活动有关的现金
                "cashPaymentsRelatingToOtherFinancingActivities": to_float(
                    cashPaymentsRelatingToOtherFinancingActivities[idx]),
                # 筹资活动现金流出小计
                "subTotalOfCashOutflowsFromFinancingActivities": to_float(
                    subTotalOfCashOutflowsFromFinancingActivities[idx]),
                # 筹资活动产生的现金流量净额
                "netCashFlowsFromFinancingActivities": to_float(netCashFlowsFromFinancingActivities[idx]),
                # /*四、汇率变动对现金及现金等价物的影响*/
                "effectOfForeignExchangeRate": to_float(effectOfForeignExchangeRate[idx]),
                # /*五、现金及现金等价物净增加额*/
                "netIncreaseInCash": to_float(netIncreaseInCash[idx]),
                # 加:期初现金及现金等价物余额
                "cashAtBeginningOfyear": to_float(cashAtBeginningOfyear[idx]),
                # /*六、期末现金及现金等价物余额*/
                "cashAtEndOfyear": to_float(cashAtEndOfyear[idx]),
                # /*附注*/
                # 净利润
                "netProfit": to_float(netProfit[idx]),
                # 少数股东权益
                "minorityBookValue": to_float(minorityBookValue[idx]),
                # 未确认的投资损失
                "unrealisedInvestmentLosses": to_float(unrealisedInvestmentLosses[idx]),
                # 资产减值准备
                "allowanceForAssetDevaluation": to_float(allowanceForAssetDevaluation[idx]),
                # 固定资产折旧、油气资产折耗、生产性物资折旧
                "depreciationOfFixedAssets": to_float(depreciationOfFixedAssets[idx]),
                # 无形资产摊销
                "amorizationOfIntangibleAssets": to_float(amorizationOfIntangibleAssets[idx]),
                # 长期待摊费用摊销
                "longTermDeferredExpenses": to_float(longTermDeferredExpenses[idx]),
                # 待摊费用的减少
                "decreaseOfDeferredExpenses": to_float(decreaseOfDeferredExpenses[idx]),
                # 预提费用的增加
                "IncreaseOfwithholdingExpenses": to_float(IncreaseOfwithholdingExpenses[idx]),
                # 处置固定资产、无形资产和其他长期资产的损失
                "lossOnDisposalOfFixedAssets": to_float(lossOnDisposalOfFixedAssets[idx]),
                # 固定资产报废损失
                "lossOnFixedAssetsDamaged": to_float(lossOnFixedAssetsDamaged[idx]),
                # 公允价值变动损失
                "lossOnFairValueChange": to_float(lossOnFairValueChange[idx]),
                # 递延收益增加(减:减少)
                "changeOnDeferredRevenue": to_float(changeOnDeferredRevenue[idx]),
                # 预计负债
                "estimatedLiabilities": to_float(estimatedLiabilities[idx]),
                # 财务费用
                "financingExpenses": to_float(financingExpenses[idx]),
                # 投资损失
                "investmentLoss": to_float(investmentLoss[idx]),
                # 递延所得税资产减少
                "decreaseOnDeferredIncomeTaxAssets": to_float(decreaseOnDeferredIncomeTaxAssets[idx]),
                # 递延所得税负债增加
                "increaseOnDeferredIncomeTaxLiabilities": to_float(increaseOnDeferredIncomeTaxLiabilities[idx]),
                # 存货的减少
                "decreaseInInventories": to_float(decreaseInInventories[idx]),
                # 经营性应收项目的减少
                "decreaseInReceivablesUnderOperatingActivities": to_float(
                    decreaseInReceivablesUnderOperatingActivities[idx]),
                # 经营性应付项目的增加
                "increaseInReceivablesUnderOperatingActivities": to_float(
                    increaseInReceivablesUnderOperatingActivities[idx]),
                # 已完工尚未结算款的减少(减:增加)
                "decreaseOnAmountDue": to_float(decreaseOnAmountDue[idx]),
                # 已结算尚未完工款的增加(减:减少)
                "increaseOnSettlementNotYetCompleted": to_float(increaseOnSettlementNotYetCompleted[idx]),
                # 其他
                "other": to_float(other[idx]),
                # 经营活动产生现金流量净额
                "netCashFlowFromOperatingActivities": to_float(netCashFlowFromOperatingActivities[idx]),
                # 债务转为资本
                "debtsTransferToCapital": to_float(debtsTransferToCapital[idx]),
                # 一年内到期的可转换公司债券
                "oneYearDueConvertibleBonds": to_float(oneYearDueConvertibleBonds[idx]),
                # 融资租入固定资产
                "financingRentToFixedAsset": to_float(financingRentToFixedAsset[idx]),
                # 现金的期末余额
                "cashAtTheEndOfPeriod": to_float(cashAtTheEndOfPeriod[idx]),
                # 现金的期初余额
                "cashAtTheBeginningOfPeriod": to_float(cashAtTheBeginningOfPeriod[idx]),
                # 现金等价物的期末余额
                "cashEquivalentsAtTheEndOfPeriod": to_float(cashEquivalentsAtTheEndOfPeriod[idx]),
                # 现金等价物的期初余额
                "cashEquivalentsAtTheBeginningOfPeriod": to_float(cashEquivalentsAtTheBeginningOfPeriod[idx]),
                # 现金及现金等价物的净增加额
                "netIncreaseInCashAndCashEquivalents": to_float(netIncreaseInCashAndCashEquivalents[idx])
            }

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_json

            result_json.append(the_json)

        if result_json:
            result_json = sorted(result_json, key=lambda x: pd.Timestamp(x['reportDate']))

        return result_json
Пример #27
0
def get_income_statement_items(security_item, start_date=None, report_period=None, report_event_date=None):
    path = get_income_statement_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = settings.DOWNLOAD_TXT_ENCODING if settings.DOWNLOAD_TXT_ENCODING else detect_encoding(
        url='file://' + os.path.abspath(path)).get('encoding')

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()
        # for idx, line in enumerate(lines):
        #     yield idx, line.split()

        reportDate = lines[0].split()[1:-1]
        # /*营业总收入*/
        # 营业收入
        operatingRevenue = lines[2].split()[1:-1]
        # /*营业总成本*/
        OperatingTotalCosts = lines[4].split()[1:-1]
        # 营业成本
        OperatingCosts = lines[5].split()[1:-1]
        # 营业税金及附加
        businessTaxesAndSurcharges = lines[6].split()[1:-1]
        # 销售费用
        sellingExpenses = lines[7].split()[1:-1]
        # 管理费用
        ManagingCosts = lines[8].split()[1:-1]
        # 财务费用
        financingExpenses = lines[9].split()[1:-1]
        # 资产减值损失
        assetsDevaluation = lines[10].split()[1:-1]
        # 公允价值变动收益
        incomeFromChangesInFairValue = lines[11].split()[1:-1]
        # 投资收益
        investmentIncome = lines[12].split()[1:-1]
        # 其中:对联营企业和合营企业的投资收益
        investmentIncomeFromRelatedEnterpriseAndJointlyOperating = lines[13].split()[1:-1]
        # 汇兑收益
        exchangeGains = lines[14].split()[1:-1]
        # /*营业利润*/
        operatingProfit = lines[15].split()[1:-1]
        # 加:营业外收入
        nonOperatingIncome = lines[16].split()[1:-1]
        # 减:营业外支出
        nonOperatingExpenditure = lines[17].split()[1:-1]
        # 其中:非流动资产处置损失
        disposalLossOnNonCurrentLiability = lines[18].split()[1:-1]
        # /*利润总额*/
        totalProfits = lines[19].split()[1:-1]
        # 减:所得税费用
        incomeTaxExpense = lines[20].split()[1:-1]
        # /*净利润*/
        netProfit = lines[21].split()[1:-1]
        # 归属于母公司所有者的净利润
        netProfitAttributedToParentCompanyOwner = lines[22].split()[1:-1]
        # 少数股东损益
        minorityInterestIncome = lines[23].split()[1:-1]
        # /*每股收益*/
        # 基本每股收益(元/股)
        EPS = lines[25].split()[1:-1]
        # 稀释每股收益(元/股)
        dilutedEPS = lines[26].split()[1:-1]
        # /*其他综合收益*/
        otherComprehensiveIncome = lines[27].split()[1:-1]
        # /*综合收益总额*/
        accumulatedOtherComprehensiveIncome = lines[28].split()[1:-1]
        # 归属于母公司所有者的综合收益总额
        attributableToOwnersOfParentCompany = lines[29].split()[1:-1]
        # 归属于少数股东的综合收益总额
        attributableToMinorityShareholders = lines[30].split()[1:-1]

        result_json = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            if report_period and not is_same_date(report_period, reportDate[idx]):
                continue

            reportEventDate = get_report_event_date(security_item, report_date=reportDate[idx])

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id": '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate": to_time_str(reportDate[idx]),
                "reportEventDate": reportEventDate,
                "securityId": security_item["id"],
                "code": security_item["code"],
                # /*营业总收入*/
                # 营业收入
                "operatingRevenue": to_float(operatingRevenue[idx]),
                # /*营业总成本*/
                "OperatingTotalCosts": to_float(OperatingTotalCosts[idx]),
                # 营业成本
                "OperatingCosts": to_float(OperatingCosts[idx]),
                # 营业税金及附加
                "businessTaxesAndSurcharges": to_float(businessTaxesAndSurcharges[idx]),
                # 销售费用
                "sellingExpenses": to_float(sellingExpenses[idx]),
                # 管理费用
                "ManagingCosts": to_float(ManagingCosts[idx]),
                # 财务费用
                "financingExpenses": to_float(financingExpenses[idx]),
                # 资产减值损失
                "assetsDevaluation": to_float(assetsDevaluation[idx]),
                # 公允价值变动收益
                "incomeFromChangesInFairValue": to_float(incomeFromChangesInFairValue[idx]),
                # 投资收益
                "investmentIncome": to_float(investmentIncome[idx]),
                # 其中:对联营企业和合营企业的投资收益
                "investmentIncomeFromRelatedEnterpriseAndJointlyOperating":
                    investmentIncomeFromRelatedEnterpriseAndJointlyOperating[idx],
                # 汇兑收益
                "exchangeGains": to_float(exchangeGains[idx]),
                # /*营业利润*/
                "operatingProfit": to_float(operatingProfit[idx]),
                # 加:营业外收入
                "nonOperatingIncome": to_float(nonOperatingIncome[idx]),
                # 减:营业外支出
                "nonOperatingExpenditure": to_float(nonOperatingExpenditure[idx]),
                # 其中:非流动资产处置损失
                "disposalLossOnNonCurrentLiability": to_float(disposalLossOnNonCurrentLiability[idx]),
                # /*利润总额*/
                "totalProfits": to_float(totalProfits[idx]),
                # 减:所得税费用
                "incomeTaxExpense": to_float(incomeTaxExpense[idx]),
                # /*净利润*/
                "netProfit": to_float(netProfit[idx]),
                # 归属于母公司所有者的净利润
                "netProfitAttributedToParentCompanyOwner": to_float(netProfitAttributedToParentCompanyOwner[idx]),
                # 少数股东损益
                "minorityInterestIncome": to_float(minorityInterestIncome[idx]),
                # /*每股收益*/
                # 基本每股收益(元/股)
                "EPS": to_float(EPS[idx]),
                # 稀释每股收益(元/股)
                "dilutedEPS": to_float(dilutedEPS[idx]),
                # /*其他综合收益*/
                "otherComprehensiveIncome": to_float(otherComprehensiveIncome[idx]),
                # /*综合收益总额*/
                "accumulatedOtherComprehensiveIncome": to_float(accumulatedOtherComprehensiveIncome[idx]),
                # 归属于母公司所有者的综合收益总额
                "attributableToOwnersOfParentCompany": to_float(attributableToOwnersOfParentCompany[idx]),
                # 归属于少数股东的综合收益总额
                "attributableToMinorityShareholders": to_float(attributableToMinorityShareholders[idx])
            }

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_json

            result_json.append(the_json)

        if result_json:
            result_json = sorted(result_json, key=lambda x: pd.Timestamp(x['reportDate']))
        return result_json
Пример #28
0
def get_balance_sheet_items(security_item, start_date=None, report_period=None, report_event_date=None):
    path = get_balance_sheet_path(security_item)
    if not os.path.exists(path):
        return []
    encoding = settings.DOWNLOAD_TXT_ENCODING if settings.DOWNLOAD_TXT_ENCODING else detect_encoding(
        url='file://' + os.path.abspath(path)).get('encoding')

    with open(path, encoding=encoding) as fr:
        lines = fr.readlines()

        # for idx, line in enumerate(lines):
        #     yield idx, line.split()

        reportDate = lines[0].split()[1:-1]
        # 货币资金
        moneyFunds = lines[3].split()[1:-1]
        # 交易性金融资产
        heldForTradingFinancialAssets = lines[4].split()[1:-1]
        # 衍生金融资产
        derivative = lines[5].split()[1:-1]
        # 应收票据
        billsReceivable = lines[6].split()[1:-1]
        # 应收账款
        accountsReceivable = lines[7].split()[1:-1]
        # 预付款项
        prepaidAccounts = lines[8].split()[1:-1]
        # 应收利息
        interestReceivable = lines[9].split()[1:-1]
        # 应收股利
        dividendReceivable = lines[10].split()[1:-1]
        # 其他应收款
        otherReceivables = lines[11].split()[1:-1]

        # 买入返售金融资产
        buyingBackTheSaleOfFinancialAssets = lines[12].split()[1:-1]
        # 存货
        inventory = lines[13].split()[1:-1]
        # 划分为持有待售的资产
        assetsForSale = lines[14].split()[1:-1]
        # 一年内到期的非流动资产
        nonCurrentAssetsDueWithinOneYear = lines[15].split()[1:-1]

        # 待摊费用
        unamortizedExpenditures = lines[16].split()[1:-1]
        # 待处理流动资产损益
        waitDealIntangibleAssetsLossOrIncome = lines[17].split()[1:-1]

        # 其他流动资产
        otherCurrentAssets = lines[18].split()[1:-1]
        # 流动资产合计
        totalCurrentAssets = lines[19].split()[1:-1]

        # 非流动资产

        # 发放贷款及垫款
        loansAndPaymentsOnBehalf = lines[21].split()[1:-1]

        # 可供出售金融资产
        availableForSaleFinancialAssets = lines[22].split()[1:-1]
        # 持有至到期投资
        heldToMaturityInvestment = lines[23].split()[1:-1]
        # 长期应收款
        longTermReceivables = lines[24].split()[1:-1]
        # 长期股权投资
        longTermEquityInvestment = lines[25].split()[1:-1]
        # 投资性房地产
        investmentRealEstate = lines[26].split()[1:-1]
        # 固定资产净额
        NetfixedAssets = lines[27].split()[1:-1]
        # 在建工程
        constructionInProcess = lines[28].split()[1:-1]
        # 工程物资
        engineerMaterial = lines[29].split()[1:-1]
        # 固定资产清理
        fixedAssetsInLiquidation = lines[30].split()[1:-1]
        # 生产性生物资产
        productiveBiologicalAssets = lines[31].split()[1:-1]
        # 公益性生物资产
        nonProfitLivingAssets = lines[32].split()[1:-1]
        # 油气资产
        oilAndGasAssets = lines[33].split()[1:-1]
        # 无形资产
        intangibleAssets = lines[34].split()[1:-1]
        # 开发支出
        developmentExpenditure = lines[35].split()[1:-1]
        # 商誉
        goodwill = lines[36].split()[1:-1]
        # 长期待摊费用
        longTermDeferredExpenses = lines[37].split()[1:-1]
        # 递延所得税资产
        deferredIncomeTaxAssets = lines[38].split()[1:-1]
        # 其他非流动资产
        OtherNonCurrentAssets = lines[39].split()[1:-1]
        # 非流动资产合计
        nonCurrentAssets = lines[40].split()[1:-1]
        # 资产总计
        totalAssets = lines[41].split()[1:-1]

        # / *流动负债 * /
        # 短期借款
        shortTermBorrowing = lines[43].split()[1:-1]
        # 交易性金融负债
        transactionFinancialLiabilities = lines[44].split()[1:-1]
        # 应付票据
        billsPayable = lines[45].split()[1:-1]
        # 应付账款
        accountsPayable = lines[46].split()[1:-1]
        # 预收款项
        accountsReceivedInAdvance = lines[47].split()[1:-1]
        # 应付手续费及佣金
        handlingChargesAndCommissionsPayable = lines[48].split()[1:-1]
        # 应付职工薪酬
        employeeBenefitsPayable = lines[49].split()[1:-1]
        # 应交税费
        taxesAndSurchargesPayable = lines[50].split()[1:-1]
        # 应付利息
        interestPayable = lines[51].split()[1:-1]
        # 应付股利
        dividendpayable = lines[52].split()[1:-1]
        # 其他应付款
        otherPayables = lines[53].split()[1:-1]
        # 预提费用
        withholdingExpenses = lines[54].split()[1:-1]
        # 一年内的递延收益
        deferredIncomeWithinOneYear = lines[55].split()[1:-1]
        # 应付短期债券
        shortTermDebenturesPayable = lines[56].split()[1:-1]
        # 一年内到期的非流动负债
        nonCurrentLiabilitiesMaturingWithinOneYear = lines[57].split()[1:-1]
        # 其他流动负债
        otherCurrentLiability = lines[58].split()[1:-1]
        # 流动负债合计
        totalCurrentLiabilities = lines[59].split()[1:-1]

        # / *非流动负债 * /
        # 长期借款
        LongTermBorrowing = lines[61].split()[1:-1]
        # 应付债券
        bondPayable = lines[62].split()[1:-1]
        # 长期应付款
        longTermPayables = lines[63].split()[1:-1]
        # 长期应付职工薪酬
        longTermEmployeeBenefitsPayable = lines[64].split()[1:-1]
        # 专项应付款
        specialPayable = lines[65].split()[1:-1]
        # 预计非流动负债
        expectedNonCurrentLiabilities = lines[66].split()[1:-1]
        # 递延所得税负债
        deferredIncomeTaxLiabilities = lines[67].split()[1:-1]
        # 长期递延收益
        longTermDeferredRevenue = lines[68].split()[1:-1]
        # 其他非流动负债
        otherNonCurrentLiabilities = lines[69].split()[1:-1]
        # 非流动负债合计
        totalNonCurrentLiabilities = lines[70].split()[1:-1]
        # 负债合计
        totalLiabilities = lines[71].split()[1:-1]

        # / *所有者权益 * /
        # 实收资本(或股本)
        totalShareCapital = lines[73].split()[1:-1]

        # 资本公积
        capitalSurplus = lines[74].split()[1:-1]
        # 减:库存股
        treasuryStock = lines[75].split()[1:-1]
        # 其他综合收益
        otherComprehensiveIncome = lines[76].split()[1:-1]
        # 专项储备
        theSpecialReserve = lines[77].split()[1:-1]

        # 盈余公积
        surplusReserves = lines[78].split()[1:-1]
        # 一般风险准备
        generalRiskPreparation = lines[79].split()[1:-1]
        # 未分配利润
        undistributedProfits = lines[80].split()[1:-1]
        # 归属于母公司股东权益合计(净资产)
        bookValue = lines[81].split()[1:-1]

        # 少数股东权益
        minorityBookValue = lines[82].split()[1:-1]

        # 所有者权益(或股东权益)合计
        totalBookValue = lines[83].split()[1:-1]

        # 负债和所有者权益(或股东权益)总计
        totalLiabilitiesAndOwnersEquity = lines[84].split()[1:-1]

        result_json = []
        for idx, _ in enumerate(reportDate):
            if start_date:
                if pd.Timestamp(reportDate[idx]) < pd.Timestamp(start_date):
                    continue

            reportEventDate = get_report_event_date(security_item, report_date=reportDate[idx])

            if report_period and not is_same_date(report_period, reportDate[idx]):
                continue

            # use report_event_date to filter the reportEventDate before it for not getting future data
            if report_event_date and pd.Timestamp(report_event_date) < pd.Timestamp(reportEventDate):
                continue

            the_json = {
                "id": '{}_{}'.format(security_item["id"], reportDate[idx]),
                "reportDate": to_time_str(reportDate[idx]),
                "reportEventDate": reportEventDate,
                "securityId": security_item["id"],
                "code": security_item["code"],
                # 货币资金
                "moneyFunds": to_float(moneyFunds[idx]),
                # 交易性金融资产
                "heldForTradingFinancialAssets": to_float(heldForTradingFinancialAssets[idx]),
                # 衍生金融资产
                "derivative": to_float(derivative[idx]),
                # 应收票据
                "billsReceivable": to_float(billsReceivable[idx]),
                # 应收账款
                "accountsReceivable": to_float(accountsReceivable[idx]),
                # 预付款项
                "prepaidAccounts": to_float(prepaidAccounts[idx]),
                # 应收利息
                "interestReceivable": to_float(interestReceivable[idx]),
                # 应收股利
                "dividendReceivable": to_float(dividendReceivable[idx]),
                # 其他应收款
                "otherReceivables": to_float(otherReceivables[idx]),

                # 买入返售金融资产
                "buyingBackTheSaleOfFinancialAssets": to_float(buyingBackTheSaleOfFinancialAssets[idx]),
                # 存货
                "inventory": to_float(inventory[idx]),
                # 划分为持有待售的资产
                "assetsForSale": to_float(assetsForSale[idx]),
                # 一年内到期的非流动资产
                "nonCurrentAssetsDueWithinOneYear": to_float(nonCurrentAssetsDueWithinOneYear[idx]),

                # 待摊费用
                "unamortizedExpenditures": to_float(unamortizedExpenditures[idx]),
                # 待处理流动资产损益
                "waitDealIntangibleAssetsLossOrIncome": to_float(waitDealIntangibleAssetsLossOrIncome[idx]),

                # 其他流动资产
                "otherCurrentAssets": to_float(otherCurrentAssets[idx]),
                # 流动资产合计
                "totalCurrentAssets": to_float(totalCurrentAssets[idx]),

                # 非流动资产

                # 发放贷款及垫款
                "loansAndPaymentsOnBehalf": to_float(loansAndPaymentsOnBehalf[idx]),

                # 可供出售金融资产
                "availableForSaleFinancialAssets": to_float(availableForSaleFinancialAssets[idx]),
                # 持有至到期投资
                "heldToMaturityInvestment": to_float(heldToMaturityInvestment[idx]),
                # 长期应收款
                "longTermReceivables": to_float(longTermReceivables[idx]),
                # 长期股权投资
                "longTermEquityInvestment": to_float(longTermEquityInvestment[idx]),
                # 投资性房地产
                "investmentRealEstate": to_float(investmentRealEstate[idx]),
                # 固定资产净额
                "NetfixedAssets": to_float(NetfixedAssets[idx]),
                # 在建工程
                "constructionInProcess": to_float(constructionInProcess[idx]),
                # 工程物资
                "engineerMaterial": to_float(engineerMaterial[idx]),
                # 固定资产清理
                "fixedAssetsInLiquidation": to_float(fixedAssetsInLiquidation[idx]),
                # 生产性生物资产
                "productiveBiologicalAssets": to_float(productiveBiologicalAssets[idx]),
                # 公益性生物资产
                "nonProfitLivingAssets": to_float(nonProfitLivingAssets[idx]),
                # 油气资产
                "oilAndGasAssets": to_float(oilAndGasAssets[idx]),
                # 无形资产
                "intangibleAssets": to_float(intangibleAssets[idx]),
                # 开发支出
                "developmentExpenditure": to_float(developmentExpenditure[idx]),
                # 商誉
                "goodwill": to_float(goodwill[idx]),
                # 长期待摊费用
                "longTermDeferredExpenses": to_float(longTermDeferredExpenses[idx]),
                # 递延所得税资产
                "deferredIncomeTaxAssets": to_float(deferredIncomeTaxAssets[idx]),
                # 其他非流动资产
                "OtherNonCurrentAssets": to_float(OtherNonCurrentAssets[idx]),
                # 非流动资产合计
                "nonCurrentAssets": to_float(nonCurrentAssets[idx]),
                # 资产总计
                "totalAssets": to_float(totalAssets[idx]),

                # / *流动负债 * /
                # 短期借款
                "shortTermBorrowing": to_float(shortTermBorrowing[idx]),
                # 交易性金融负债
                "transactionFinancialLiabilities": to_float(transactionFinancialLiabilities[idx]),
                # 应付票据
                "billsPayable": to_float(billsPayable[idx]),
                # 应付账款
                "accountsPayable": to_float(accountsPayable[idx]),
                # 预收款项
                "accountsReceivedInAdvance": to_float(accountsReceivedInAdvance[idx]),
                # 应付手续费及佣金
                "handlingChargesAndCommissionsPayable": to_float(handlingChargesAndCommissionsPayable[idx]),
                # 应付职工薪酬
                "employeeBenefitsPayable": to_float(employeeBenefitsPayable[idx]),
                # 应交税费
                "taxesAndSurchargesPayable": to_float(taxesAndSurchargesPayable[idx]),
                # 应付利息
                "interestPayable": to_float(interestPayable[idx]),
                # 应付股利
                "dividendpayable": to_float(dividendpayable[idx]),
                # 其他应付款
                "otherPayables": to_float(otherPayables[idx]),
                # 预提费用
                "withholdingExpenses": to_float(withholdingExpenses[idx]),
                # 一年内的递延收益
                "deferredIncomeWithinOneYear": to_float(deferredIncomeWithinOneYear[idx]),
                # 应付短期债券
                "shortTermDebenturesPayable": to_float(shortTermDebenturesPayable[idx]),
                # 一年内到期的非流动负债
                "nonCurrentLiabilitiesMaturingWithinOneYear": to_float(nonCurrentLiabilitiesMaturingWithinOneYear[idx]),
                # 其他流动负债
                "otherCurrentLiability": to_float(otherCurrentLiability[idx]),
                # 流动负债合计
                "totalCurrentLiabilities": to_float(totalCurrentLiabilities[idx]),

                # / *非流动负债 * /
                # 长期借款
                "LongTermBorrowing": to_float(LongTermBorrowing[idx]),
                # 应付债券
                "bondPayable": to_float(bondPayable[idx]),
                # 长期应付款
                "longTermPayables": to_float(longTermPayables[idx]),
                # 长期应付职工薪酬
                "longTermEmployeeBenefitsPayable": to_float(longTermEmployeeBenefitsPayable[idx]),
                # 专项应付款
                "specialPayable": to_float(specialPayable[idx]),
                # 预计非流动负债
                "expectedNonCurrentLiabilities": to_float(expectedNonCurrentLiabilities[idx]),
                # 递延所得税负债
                "deferredIncomeTaxLiabilities": to_float(deferredIncomeTaxLiabilities[idx]),
                # 长期递延收益
                "longTermDeferredRevenue": to_float(longTermDeferredRevenue[idx]),
                # 其他非流动负债
                "otherNonCurrentLiabilities": to_float(otherNonCurrentLiabilities[idx]),
                # 非流动负债合计
                "totalNonCurrentLiabilities": to_float(totalNonCurrentLiabilities[idx]),
                # 负债合计
                "totalLiabilities": to_float(totalLiabilities[idx]),

                # / *所有者权益 * /
                # 实收资本(或股本)
                "totalShareCapital": to_float(totalShareCapital[idx]),

                # 资本公积
                "capitalSurplus": to_float(capitalSurplus[idx]),
                # 减:库存股
                "treasuryStock": to_float(treasuryStock[idx]),
                # 其他综合收益
                "otherComprehensiveIncome": to_float(otherComprehensiveIncome[idx]),
                # 专项储备
                "theSpecialReserve": to_float(theSpecialReserve[idx]),

                # 盈余公积
                "surplusReserves": to_float(surplusReserves[idx]),
                # 一般风险准备
                "generalRiskPreparation": to_float(generalRiskPreparation[idx]),
                # 未分配利润
                "undistributedProfits": to_float(undistributedProfits[idx]),
                # 归属于母公司股东权益合计(净资产)
                "bookValue": to_float(bookValue[idx]),

                # 少数股东权益
                "minorityBookValue": to_float(minorityBookValue[idx]),

                # 所有者权益(或股东权益)合计
                "totalBookValue": to_float(totalBookValue[idx]),

                # 负债和所有者权益(或股东权益)总计
                "totalLiabilitiesAndOwnersEquity": to_float(totalLiabilitiesAndOwnersEquity[idx])
            }

            if report_period and is_same_date(report_period, reportDate[idx]):
                return the_json

            result_json.append(the_json)

        if (result_json):
            result_json = sorted(result_json, key=lambda x: pd.Timestamp(x['reportDate']))
        return result_json