Exemplo n.º 1
0
def QA_fetch_financial_report_adv(code, start, end=None, ltype='EN'):
    """高级财务查询接口
    Arguments:
        code {[type]} -- [description]
        start {[type]} -- [description]
    Keyword Arguments:
        end {[type]} -- [description] (default: {None})
    """

    if end is None:

        return QA_DataStruct_Financial(
            QA_fetch_financial_report(code,
                                      start,
                                      ltype=ltype)
        )
    else:
        series = pd.Series(
            data=month_data,
            index=pd.to_datetime(month_data, utc=False),
            name='date'
        )
        timerange = series.loc[start:end].tolist()
        return QA_DataStruct_Financial(
            QA_fetch_financial_report(code,
                                      timerange,
                                      ltype=ltype)
        )
Exemplo n.º 2
0
def QA_fetch_financial_report_adv(code, start='all', type='report', end=None):
    """高级财务查询接口

    Arguments:
        code {[type]} -- [description]
        start {[type]} -- [description]

    Keyword Arguments:
        end {[type]} -- [description] (default: {None})
    """
    end = start if end is None else end
    start = str(start)[0:10]
    end = str(end)[0:10]

    if start == 'all':
        start = '1990-01-01'
        end = str(datetime.date.today())

    if end is None:
        end = str(datetime.date.today())
        date_list = list(
            pd.DataFrame.from_dict(
                QA_util_getBetweenQuarter(
                    start,
                    QA_util_datetime_to_strdate(QA_util_add_months(
                        end, -3)))).T.iloc[:, 1])
        if type == 'report':
            return QA_DataStruct_Financial(
                QA_fetch_financial_report(code, date_list))
        elif type == 'date':
            return QA_DataStruct_Financial(
                QA_fetch_financial_report(code, date_list, type='date'))
    else:
        daterange = pd.date_range(start, end)
        timerange = [item.strftime('%Y-%m-%d') for item in list(daterange)]
        if type == 'report':
            return QA_DataStruct_Financial(
                QA_fetch_financial_report(code, timerange))
        elif type == 'date':
            return QA_DataStruct_Financial(
                QA_fetch_financial_report(code, timerange, type='date'))
Exemplo n.º 3
0
 def get(self):
     code = self.get_argument('code', default='000001')
     start_year = self.get_argument('start_year', default='2002')
     res = QA_fetch_financial_report([code], report_dates(int(start_year)))
     temp = pd.DataFrame({
         'report_date':
         res.report_date,
         'code':
         res.code,
         'cashPaymentsForDistrbutionOfDividendsOrProfits':
         res.cashPaymentsForDistrbutionOfDividendsOrProfits
     })
     temp['report_date'].apply(format_ts_date)
     data = QA_util_to_json_from_pandas(temp)
     return self.write({'result': data})
Exemplo n.º 4
0
    def get(self):
        code = self.get_argument('code', default='000001')
        start_year = self.get_argument('start_year', default='2002')
        res = QA_fetch_financial_report([code], report_dates(int(start_year)))

        temp = pd.DataFrame({
            'report_date': res.report_date,
            'code': res.code,
            'ROE': res.ROE
        })

        temp['report_date_str'] = temp['report_date'].apply(format_ts_date)
        temp['ROE'] = temp['ROE'].apply(format_number)
        temp['ROE_str'] = temp['ROE'].apply(format_percent)
        data = QA_util_to_json_from_pandas(temp)
        return self.write({'result': data})
Exemplo n.º 5
0
    def get(self):
        code = self.get_argument('code', default='000001')
        start_date = self.get_argument('start_date', default='2018-01-01')
        end_date = self.get_argument('end_date', default='2018-12-31')
        start_year = self.get_argument('start_year', default='2017')

        stock_prices = QA_fetch_stock_day(code,
                                          start_date,
                                          end_date,
                                          format='pandas')

        financial_reports = QA_fetch_financial_report([code],
                                                      report_dates(
                                                          int(start_year)))

        # PE= 股价/每股收益
        # PB= 股价/每股净资产
        # PEG=PE/(企业年盈利增长率*100)
        price_pd = pd.DataFrame({
            'code': stock_prices.code,
            'date': stock_prices.date,
            'close': stock_prices.close
        })

        reports_pd = pd.DataFrame({
            'code':
            financial_reports.code,
            'report_date':
            financial_reports.report_date,
            'EPS':
            financial_reports.EPS,
            'netAssetsPerShare':
            financial_reports.netAssetsPerShare,
            'netProfitGrowthRate':
            financial_reports.netProfitGrowthRate
        })

        reports_pd['report_date_str'] = reports_pd['report_date'].apply(
            format_ts_date)

        eps_sum = reports_pd.loc[reports_pd["report_date_str"] ==
                                 "2017-12-31"].EPS.sum()
        aps_sum = reports_pd.loc[reports_pd["report_date_str"] ==
                                 "2017-12-31"].netAssetsPerShare.sum()
        pgr_sum = reports_pd.loc[reports_pd["report_date_str"] ==
                                 "2017-12-31"].netProfitGrowthRate.sum()

        price_pd['date_str'] = price_pd['date'].apply(
            lambda x: x.strftime("%Y-%m-%d"))
        price_pd['eps_sum'] = price_pd['close'].apply(
            lambda x: round(eps_sum, 2))
        price_pd['aps_sum'] = price_pd['close'].apply(
            lambda x: round(aps_sum, 2))
        price_pd['pgr_sum'] = price_pd['close'].apply(
            lambda x: round(pgr_sum, 2))
        price_pd['pe'] = price_pd['close'].apply(
            lambda x: round(x / eps_sum, 2))
        price_pd['pb'] = price_pd['close'].apply(
            lambda x: round(x / aps_sum, 2))
        price_pd['peg'] = price_pd['pe'].apply(lambda x: round(x / pgr_sum, 2))

        return self.write({
            'stock_prices':
            QA_util_to_json_from_pandas(price_pd),
            'financial_reports':
            QA_util_to_json_from_pandas(reports_pd)
        })