Python tushare 模块,get_growth_data() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用tushare.get_growth_data()

项目:silverstrategy    作者:silverhandy    | 项目源码 | 文件源码
def __init__(self):
        self.name = "base"
        self.fundaLib = {}
        self.fundaLib[fundaType.performance] = funda_cell(ts.get_report_data, "performance_report")
        self.fundaLib[fundaType.profit] = funda_cell(ts.get_profit_data, "profit_report")
        self.fundaLib[fundaType.operation] = funda_cell(ts.get_operation_data, "operation_report")
        self.fundaLib[fundaType.growth] = funda_cell(ts.get_growth_data, "growth_report")
        self.fundaLib[fundaType.debtpaying] = funda_cell(ts.get_debtpaying_data, "debtpaying_report")
        self.fundaLib[fundaType.cashflow] = funda_cell(ts.get_cashflow_data, "cashflow_report")
项目:Python-Quant    作者:saberxxy    | 项目源码 | 文件源码
def getGrowth(cursor):
    for i in range(1992, 2017+1):
        for j in range(1, 4+1):
            try:
                print(i, j)
                df = ts.get_growth_data(i, j)

                # ?????
                df = df.fillna(0)

                dfLen = len(df)
                # print(dfLen)
                uuidList = []  # ??uuid
                yearList = []  # ????
                quarterList = []  # ????
                for l in range(0, dfLen):
                    uuidList.append(uuid.uuid1())
                    yearList.append(str(i))
                    quarterList.append(str(j))
                df['uuid'] = uuidList
                df['year'] = yearList
                df['quarter'] = quarterList

                for k in range(0, dfLen):
                    df2 = df[k:k+1]

                    cursor.execute("insert into stock_growth(uuid, code, name, mbrg, nprg, nav, "
                               "targ, epsg, seg, year, quarter) "
                               "values(:uuid, :code, :name, :mbrg, :nprg, :nav, "
                               ":targ, :epsg, :seg,  :year, :quarter)",
                               (str(list(df2['uuid'])[0]), str(list(df2['code'])[0]), str(list(df2['name'])[0]), round(float(df2['mbrg']), 4),
                                round(float(df2['nprg']), 4), round(float(df2['nav']), 4),
                                round(float(df2['targ']), 4), round(float(df2['epsg']), 4), round(float(df2['seg']), 4),
                                str(list(df2['year'])[0]), str(list(df2['quarter'])[0])) )
                cursor.execute("commit")
            except Exception:
                pass
项目:Python-Quant    作者:saberxxy    | 项目源码 | 文件源码
def getGrowth(cursor):
    for i in range(1992, 2017+1):
        for j in range(1, 4+1):
            try:
                print(i, j)
                df = ts.get_growth_data(i, j)

                # ?????
                df = df.fillna(0)

                dfLen = len(df)
                # print(dfLen)
                uuidList = []  # ??uuid
                yearList = []  # ????
                quarterList = []  # ????
                for l in range(0, dfLen):
                    uuidList.append(uuid.uuid1())
                    yearList.append(str(i))
                    quarterList.append(str(j))
                df['uuid'] = uuidList
                df['year'] = yearList
                df['quarter'] = quarterList

                for k in range(0, dfLen):
                    df2 = df[k:k+1]

                    cursor.execute("insert into stock_growth(uuid, code, name, mbrg, nprg, nav, "
                               "targ, epsg, seg, year, quarter) "
                               "values('%s', '%s', '%s', '%.4f', '%.4f', '%.4f', "
                               "'%.4f', '%.4f', '%.4f',  '%s', '%s')"  % (str(list(df2['uuid'])[0]),
                                   str(list(df2['code'])[0]), str(list(df2['name'])[0]), round(float(df2['mbrg']), 4),
                                round(float(df2['nprg']), 4), round(float(df2['nav']), 4),
                                round(float(df2['targ']), 4), round(float(df2['epsg']), 4), round(float(df2['seg']), 4),
                                str(list(df2['year'])[0]), str(list(df2['quarter'])[0])) )
                cursor.execute("commit")
            except Exception as e:
                pass
                print(e)
项目:flats    作者:librae8226    | 项目源码 | 文件源码
def get_report_data(year, quarter):
    ''' invoke tushare get_report_data() with csv output
    brief: to improve data integrality, we repeatedly do these actions in a row,
           call API -> append to file -> drop duplicates
    args: year, quarter
    returns: csv format data containing the whole martket report in specific year, quarter
    json fomat, df.to_json(year+'q'+quarter+'.json', orient='index')
    '''

    # profit
    print "[%s] profit %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter)
    filename = PREFIX + '/' + year + 'q' + quarter + '.profit.csv'
    df = ts.get_profit_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates()
    print "\n"
    save_to_file(filename, df)

    # operation
    print "[%s] operation %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter)
    filename = PREFIX + '/' + year + 'q' + quarter + '.operation.csv'
    df = ts.get_operation_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates()
    print "\n"
    save_to_file(filename, df)

    # growth
    print "[%s] growth %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter)
    filename = PREFIX + '/' + year + 'q' + quarter + '.growth.csv'
    df = ts.get_growth_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates()
    print "\n"
    save_to_file(filename, df)

    # debtpaying
    print "[%s] debtpaying %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter)
    filename = PREFIX + '/' + year + 'q' + quarter + '.debtpaying.csv'
    df = ts.get_debtpaying_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates()
    print "\n"
    save_to_file(filename, df)

    # cashflow
    print "[%s] cashflow %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter)
    filename = PREFIX + '/' + year + 'q' + quarter + '.cashflow.csv'
    df = ts.get_cashflow_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates()
    print "\n"
    save_to_file(filename, df)

    # main report
    print "[%s] main %sq%s" %(datetime.now().strftime("%H:%M:%S.%f"), year, quarter)
    filename = PREFIX + '/' + year + 'q' + quarter + '.csv'
    df = ts.get_report_data(int(year), int(quarter)).sort_values(by='code').drop_duplicates()
    print "\n"
    return save_to_file(filename, df)