コード例 #1
0
ファイル: __init__.py プロジェクト: SYSU-Momojie/MoQuant
    def fetch_daily_basic(self, ts_code: str = None, end_date: str = None, start_date: str = None,
                          trade_date: str = None) -> DataFrame:
        """
        https://tushare.pro/document/2?doc_id=32
        :param ts_code: 股票编码
        :param end_date: 起始日期
        :param start_date: 结束日期
        :param trade_date: 交易日期
        :return:
        """
        df: DataFrame = self.__pro.daily_basic(ts_code=ts_code, start_date=start_date, end_date=end_date,
                                               trade_date=trade_date)
        if not df.empty:
            # 按日期升序
            df = df.sort_values(by='trade_date')
            df.loc[:, 'turnover_rate'] = df.apply(lambda row: decimal_utils.none_to_zero(row.turnover_rate), axis=1)
            df.loc[:, 'volume_ratio'] = df.apply(lambda row: decimal_utils.none_to_zero(row.volume_ratio), axis=1)

            # 替换掉所有需要是0的之后,取最近的值填充
            df = df.ffill()
            df.loc[:, 'total_share'] = df.apply(lambda row:
                                                decimal_utils.mul(row.total_share, 10000, err_default=None), axis=1)
            df.loc[:, 'float_share'] = df.apply(lambda row:
                                                decimal_utils.mul(row.float_share, 10000, err_default=None), axis=1)
            df.loc[:, 'free_share'] = df.apply(lambda row:
                                               decimal_utils.mul(row.free_share, 10000, err_default=None), axis=1)
            df.loc[:, 'free_share'] = df.apply(lambda row:
                                               row.float_share if row.free_share is None or math.isnan(row.free_share)
                                               else row.free_share, axis=1)
            df.loc[:, 'total_mv'] = df.apply(lambda row:
                                             decimal_utils.mul(row.total_mv, 10000, err_default=None), axis=1)

        return df
コード例 #2
0
ファイル: __init__.py プロジェクト: SYSU-Momojie/MoQuant
 def fetch_cash_flow(self, ts_code: str = None, end_date: str = None, start_date: str = None,
                     ann_date: str = None, period: str = None) -> DataFrame:
     """
     https://tushare.pro/document/2?doc_id=44
     :param ts_code: 股票编码
     :param end_date: 起始日期
     :param start_date: 结束日期
     :param ann_date: 公告日期
     :param period: 报告期
     :return:
     """
     df1 = self.__pro.cashflow_vip(report_type=1, ts_code=ts_code, period=period,
                                   start_date=start_date, end_date=end_date, ann_date=ann_date)
     df2 = self.__pro.cashflow_vip(report_type=4, ts_code=ts_code, period=period,
                                   start_date=start_date, end_date=end_date, ann_date=ann_date)
     df = df1.append(df2)
     if not df.empty:
         self.fix_ann_date_with_list_date(df, 'ann_date')
         self.fix_ann_date_with_list_date(df, 'f_ann_date')
         df.loc[:, 'mq_ann_date'] = df.apply(lambda row: mini(row.ann_date, row.f_ann_date), axis=1)
         df.loc[:, 'prov_depr_assets'] = df.apply(lambda row: decimal_utils.none_to_zero(row.prov_depr_assets),
                                                  axis=1)
         df.loc[:, 'depr_fa_coga_dpba'] = df.apply(lambda row: decimal_utils.none_to_zero(row.depr_fa_coga_dpba),
                                                   axis=1)
         df.loc[:, 'amort_intang_assets'] = df.apply(lambda row: decimal_utils.none_to_zero(row.amort_intang_assets),
                                                     axis=1)
         df.loc[:, 'lt_amort_deferred_exp'] = df.apply(
             lambda row: decimal_utils.none_to_zero(row.lt_amort_deferred_exp), axis=1)
         df.loc[:, 'loss_scr_fa'] = df.apply(lambda row: decimal_utils.none_to_zero(row.loss_scr_fa), axis=1)
     return df
コード例 #3
0
    def cal_dcf(self, fcf: Decimal, year: int, date: str) -> Decimal:
        fcf = decimal_utils.none_to_zero(fcf)
        if fcf <= 0:
            return Decimal(0), Decimal(0)

        inc_map: list = self._get_arr_by_name('inc_rate', date)
        dr_map: list = self._get_arr_by_name('discount_rate', date)

        mv = fcf
        inc_rate = 0.07
        discount_rate = 0.1

        # 计算10年的
        for i in range(0, 10):
            y = year + i + 1
            if y in inc_map:
                inc_rate = inc_map[y].value
            if y in dr_map:
                discount_rate = dr_map[y].value
            fcf = decimal_utils.div(decimal_utils.mul(fcf, (1 + inc_rate)), (1 + discount_rate))
            if fcf < 0:
                fcf = 0
            mv = decimal_utils.add(mv, fcf)

        inc_rate = inc_map[9999].value
        discount_rate = dr_map[9999].value

        mv_forever = decimal_utils.add(mv, decimal_utils.div(
            decimal_utils.mul(fcf, (1 + inc_rate)),
            (discount_rate - inc_rate)))

        return mv, mv_forever
コード例 #4
0
ファイル: __init__.py プロジェクト: SYSU-Momojie/MoQuant
 def fetch_income(self, ts_code: str = None, end_date: str = None, start_date: str = None,
                  ann_date: str = None, period: str = None) -> DataFrame:
     """
     https://tushare.pro/document/2?doc_id=33
     :param ts_code: 股票编码
     :param end_date: 起始日期
     :param start_date: 结束日期
     :param ann_date: 公告日期
     :param period: 报告期
     :return:
     """
     qpm = 30
     if not self.__rt.get('fetch_income', seconds_per_minute / qpm, qpm, 2):
         raise Exception('fetch_income %d per minute, waiting' % qpm)
     df1: DataFrame = self.__pro.income_vip(report_type=1, ts_code=ts_code, period=period,
                                            start_date=start_date, end_date=end_date, ann_date=ann_date)
     df2: DataFrame = self.__pro.income_vip(report_type=4, ts_code=ts_code, period=period,
                                            start_date=start_date, end_date=end_date, ann_date=ann_date)
     df: DataFrame = df1.append(df2)
     if not df.empty:
         self.fix_ann_date_with_list_date(df, 'ann_date')
         self.fix_ann_date_with_list_date(df, 'f_ann_date')
         df.loc[:, 'mq_ann_date'] = df.apply(lambda row: mini(row.ann_date, row.f_ann_date), axis=1)
         # 资产减值损失 - 2019Q2开始计入其他收益,应该为负数,不可转回。2019Q2之前为成本,所以需要取反
         df.loc[:, 'assets_impair_loss'] = df.apply(lambda row: decimal_utils.none_to_zero(row.assets_impair_loss),
                                                    axis=1)
         df.loc[:, 'assets_impair_loss'] = df.apply(
             lambda row: decimal_utils.negative(row.assets_impair_loss)
             if row.end_date < '20190630' or (row.end_date >= '20190630' and row.assets_impair_loss > 0)
             else row.assets_impair_loss,
             axis=1)
     return df
コード例 #5
0
ファイル: __init__.py プロジェクト: SYSU-Momojie/MoQuant
 def fetch_balance_sheet(self, ts_code: str = None, end_date: str = None, start_date: str = None,
                         ann_date: str = None, period: str = None) -> DataFrame:
     """
     https://tushare.pro/document/2?doc_id=36
     :param ts_code: 股票编码
     :param end_date: 起始日期
     :param start_date: 结束日期
     :param ann_date: 公告日期
     :param period: 报告期
     :return:
     """
     df1 = self.__pro.balancesheet_vip(report_type=1, ts_code=ts_code, period=period,
                                       start_date=start_date, end_date=end_date, ann_date=ann_date)
     df2 = self.__pro.balancesheet_vip(report_type=4, ts_code=ts_code, period=period,
                                       start_date=start_date, end_date=end_date, ann_date=ann_date)
     df = df1.append(df2)
     if not df.empty:
         self.fix_ann_date_with_list_date(df, 'ann_date')
         self.fix_ann_date_with_list_date(df, 'f_ann_date')
         df.loc[:, 'mq_ann_date'] = df.apply(lambda row: mini(row.ann_date, row.f_ann_date), axis=1)
         df.loc[:, 'notes_receiv'] = df.apply(lambda row: decimal_utils.none_to_zero(row.notes_receiv), axis=1)
         df.loc[:, 'accounts_receiv'] = df.apply(lambda row: decimal_utils.none_to_zero(row.accounts_receiv), axis=1)
         df.loc[:, 'lt_rec'] = df.apply(lambda row: decimal_utils.none_to_zero(row.lt_rec), axis=1)
         df.loc[:, 'oth_receiv'] = df.apply(lambda row: decimal_utils.none_to_zero(row.oth_receiv), axis=1)
         df.loc[:, 'div_receiv'] = df.apply(lambda row: decimal_utils.none_to_zero(row.div_receiv), axis=1)
         df.loc[:, 'int_receiv'] = df.apply(lambda row: decimal_utils.none_to_zero(row.int_receiv), axis=1)
         df.loc[:, 'notes_payable'] = df.apply(lambda row: decimal_utils.none_to_zero(row.notes_payable), axis=1)
         df.loc[:, 'acct_payable'] = df.apply(lambda row: decimal_utils.none_to_zero(row.acct_payable), axis=1)
         df.loc[:, 'total_nca'] = df.apply(lambda row: decimal_utils.none_to_zero(row.total_nca), axis=1)
         df.loc[:, 'fa_avail_for_sale'] = df.apply(lambda row: decimal_utils.none_to_zero(row.fa_avail_for_sale),
                                                   axis=1)
         df.loc[:, 'total_cur_liab'] = df.apply(lambda row: decimal_utils.none_to_zero(row.total_cur_liab), axis=1)
         df.loc[:, 'total_cur_assets'] = df.apply(lambda row: decimal_utils.none_to_zero(row.total_cur_assets),
                                                  axis=1)
         df.loc[:, 'lt_borr'] = df.apply(lambda row: decimal_utils.none_to_zero(row.lt_borr), axis=1)
         df.loc[:, 'st_borr'] = df.apply(lambda row: decimal_utils.none_to_zero(row.st_borr), axis=1)
         df.loc[:, 'money_cap'] = df.apply(lambda row: decimal_utils.none_to_zero(row.money_cap), axis=1)
         df.loc[:, 'oth_cur_assets'] = df.apply(lambda row: decimal_utils.none_to_zero(row.oth_cur_assets), axis=1)
         # 待摊费用(新会计准则取消) -> 长期待摊费用
         df.loc[:, 'lt_amor_exp'] = df.apply(lambda row: decimal_utils.add(row.amor_exp, row.lt_amor_exp), axis=1)
     return df