python类get_stock_basics()的实例源码

save_tushare.py 文件源码 项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def QA_save_stock_day_all(client=QA_Setting.client):
    df = ts.get_stock_basics()
    __coll = client.quantaxis.stock_day
    __coll.ensure_index('code')

    def saving_work(i):
        QA_util_log_info('Now Saving ==== %s' % (i))
        try:
            data_json = QA_fetch_get_stock_day(
                i, startDate='1990-01-01')

            __coll.insert_many(data_json)
        except:
            QA_util_log_info('error in saving ==== %s' % str(i))

    for i_ in range(len(df.index)):
        QA_util_log_info('The %s of Total %s' % (i_, len(df.index)))
        QA_util_log_info('DOWNLOAD PROGRESS %s ' % str(
            float(i_ / len(df.index) * 100))[0:4] + '%')
        saving_work(df.index[i_])

    saving_work('hs300')
    saving_work('sz50')
save_tushare.py 文件源码 项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def QA_save_stock_day_all_bfq(client=QA_Setting.client):
    df = ts.get_stock_basics()

    __coll = client.quantaxis.stock_day_bfq
    __coll.ensure_index('code')

    def saving_work(i):
        QA_util_log_info('Now Saving ==== %s' % (i))
        try:
            data_json = QA_fetch_get_stock_day(
                i, startDate='1990-01-01', if_fq='00')

            __coll.insert_many(data_json)
        except:
            QA_util_log_info('error in saving ==== %s' % str(i))

    for i_ in range(len(df.index)):
        QA_util_log_info('The %s of Total %s' % (i_, len(df.index)))
        QA_util_log_info('DOWNLOAD PROGRESS %s ' % str(
            float(i_ / len(df.index) * 100))[0:4] + '%')
        saving_work(df.index[i_])

    saving_work('hs300')
    saving_work('sz50')
calcu_3year_average_pe.py 文件源码 项目:chinese-stock-Financial-Index 作者: lfh2016 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def calcu_all_stocks_3year_average_profit(year):  # ??3???????
    path = os.path.join(current_folder, '????%s.csv' % today)
    if not os.path.exists(path):
        data = ts.get_stock_basics()
        lie = ['??', '??', '??', '???', '????', '???',
               '???(?)', '????', '????', '???', '?????', '????', '????',
               '???', '????', '????', '?????', '????(%)', '????(%)',
               '???(%)', '????(%)', '????']
        data.columns = lie
        data.index.names = ['??']
        data.to_csv(path, encoding='utf-8')

    data = pd.read_csv(path, encoding='utf-8', index_col=0)
    # print(data)
    data['????'] = 0
    for index, row in data.iterrows():
        try:
            data.loc[index, '????'] = calcu_3year_average_profit('%06d' % index, year)
        except Exception as e:
            print(e)
            data.loc[index, '????'] = 0

        print('??%s' % index)
    data.to_csv(os.path.join(current_folder, '3????????????%s.csv' % today), encoding='utf-8')
meta.py 文件源码 项目:strategy 作者: kanghua309 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def load_tushare_df(df_type):
    file = 'ts.' + df_type + '.dat'
    try:
        obj = pickle.load(open(file,"rb"))
    except:
        #print("---load in the fly",df_type)
        if df_type == "basic":
           obj = ts.get_stock_basics()
        elif df_type == "sme":
           obj = ts.get_sme_classified()
        elif df_type == "gem":
           obj=ts.get_gem_classified()
        elif df_type == "industry":
           #print(ts, pickle)
           obj = ts.get_industry_classified() #?????,??2800??,?????3326,??????? get_stock_basics
        elif df_type == "st":
           obj = ts.get_st_classified()
        else:
            raise Exception("Error TSshare Type!!!")
        pickle.dump(obj,open(file,"wb",0))
    else:
        #print("***Read from file %s" % df_type)
        pass
    return obj
new_stock_break.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self):
        #??????????????data????????
        current = os.getcwd()
        folder = os.path.join(current, 'data')
        if os.path.exists(folder) == False:
            os.mkdir(folder)
        os.chdir(folder)
        #??tushare?????A???
        #df0=ts.get_stock_basics()
        df0=pd.read_csv('bases.csv',dtype={'code':np.str})
        self.bases=df0.sort_values('timeToMarket',ascending=False)

        #????? ????????????

        self.cxg=self.bases[(self.bases['timeToMarket']>20170101) & (self.bases['timeToMarket']<20170401)]
        self.codes= self.cxg['code'].values
stock_check.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_name(self):
        #self.all=ts.get_stock_basics()
        #self.bases_save=ts.get_stock_basics()

        #self.bases_save.to_csv('bases.csv')

        stock_list=self.multi_thread()
        for st in stock_list:

            print "code: ",st[0]
            name=self.base[self.base['code']==st[0]]['name'].values[0]
            print 'name: ',name
            print "ratio: ",st[1]
            if st[1]>30:
                print "WOW, more than 30"
            print '\n'
tushare_case.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def main():
    # ?????? ?3????
    history = ts.get_hist_data(id)

    print u"??3????"

    print history.head(10)

    history_all = ts.get_h_data(id, '20015101', '20160101')

    print u'???????'
    print history_all



    # print type(stockInfo)
    # print stockInfo.head()
    # print stockInfo.dtypes
    # df = ts.get_stock_basics()
    #data = df.ix[id]['timeToMarket']
    #print data
    #ts.get_today_all()
k_line.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def add_code_redis():
    rds = redis.StrictRedis(REDIS_HOST, 6379, db=0)
    rds_1 = redis.StrictRedis(REDIS_HOST, 6379, db=1)
    df = ts.get_stock_basics()
    df = df.reset_index()

    # ?????
    if rds.dbsize() != 0:
        rds.flushdb()
    if rds_1.dbsize() != 0:
        rds_1.flushdb()

    for i in range(len(df)):
        code, name, timeToMarket = df.loc[i]['code'], df.loc[i]['name'], df.loc[i]['timeToMarket']
        # print str(timeToMarket)
        d = dict({code: ':'.join([name, str(timeToMarket)])})
        # print d
        rds.set(code, name)
        rds_1.lpush('codes', d)
save_tushare.py 文件源码 项目:quant 作者: yutiansut 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def QA_save_stock_day_all():
    df = ts.get_stock_basics()
    __setting = QA_Setting()
    __coll = __setting.client.quantaxis.stock_day
    __coll.ensure_index('code')

    def saving_work(i):
        print('Now Saving ==== %s' % (i))
        try:
            data_json = QATushare.QA_fetch_get_stock_day(i)

            __coll.insert_many(data_json)
        except:
            print('error in saving ==== %s' % str(i))
    for item in df.index:
        saving_work(item)

    saving_work('hs300')
    saving_work('sz50')
get_stocks_historical_data.py 文件源码 项目:stock_cn 作者: QuantFisher 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_stocks_basics_info():
    file = infoFilePath + "stk_basics_" + today + ".csv"
    if os.path.exists(file) is not True:
        try:
            raw_data = ts.get_stock_basics()
        except IOError:
            raise Exception('Can not read stocks basic info through tushare interface!')

        raw_data = raw_data.sort_index()

        try:
            raw_data.to_csv(file, index=True, encoding='gbk')
        except Exception:
            print('Write stocks basic info to csv file error!')

    try:
        raw_data = pd.read_csv(file, encoding='gbk')
    except IOError:
        print('Read stocks basic info from csv file error!')

    return raw_data
save_tushare.py 文件源码 项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def QA_save_stock_day_with_fqfactor(client=QA_Setting.client):
    df = ts.get_stock_basics()

    __coll = client.quantaxis.stock_day
    __coll.ensure_index('code')

    def saving_work(i):
        QA_util_log_info('Now Saving ==== %s' % (i))
        try:
            data_hfq = QA_fetch_get_stock_day(
                i, startDate='1990-01-01', if_fq='02', type_='pd')
            data_json = QA_util_to_json_from_pandas(data_hfq)
            __coll.insert_many(data_json)
        except:
            QA_util_log_info('error in saving ==== %s' % str(i))
    for i_ in range(len(df.index)):
        QA_util_log_info('The %s of Total %s' % (i_, len(df.index)))
        QA_util_log_info('DOWNLOAD PROGRESS %s ' % str(
            float(i_ / len(df.index) * 100))[0:4] + '%')
        saving_work(df.index[i_])

    saving_work('hs300')
    saving_work('sz50')

    QA_util_log_info('Saving Process has been done !')
    return 0
QATushare.py 文件源码 项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def QA_fetch_get_stock_info(name):
    data = QATs.get_stock_basics()
    data_json = QA_util_to_json_from_pandas(data)

    for i in range(0, len(data_json) - 1, 1):
        data_json[i]['code'] = data.index[i]
    return data_json
QATushare.py 文件源码 项目:QUANTAXIS 作者: yutiansut 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def QA_fetch_get_stock_list():
    df = QATs.get_stock_basics()
    return list(df.index)
database.py 文件源码 项目:timeTrader 作者: orxg 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_symbols_save_into_db(mode = 'replace'):
    '''
    ?????????????.

    Parameters
    -----------
        mode
            ??,replace????,append???????
    '''
    now = dt.datetime.now()

    data = ts.get_stock_basics()

    con = pymysql.connect(
            host = db_host,
            user = db_user,
            passwd = db_pass,
            db = db_name,
            charset = 'utf8')

    data['created_time'] = now
    data['last_updated_time'] = now
    data['id'] = range(1,len(data) + 1)
    data['ticker'] = data.index
    data['timeToMarket'] = data['timeToMarket'].apply(date_time_str_convertor)
    data.to_sql('symbols',con,if_exists = 'replace',
                index = False,flavor = 'mysql')

    sql = '''
    ALTER TABLE symbols
    ADD PRIMARY KEY (id);
    '''

    cur = con.cursor()
    cur.execute(sql)
    con.close()
    print('????symbols?(??????)')
tushare_function.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def code_issue():
    base = ts.get_stock_basics()
    base.to_excel('111.xls')
stocktodb.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_stock_basics():
    """
    ????????
    Return
    --------
    DataFrame
    """
    basics = ts.get_stock_basics()
    return basics
stocktodb.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main():
    #    reload(sys)
    #    sys.setdefaultencoding('utf8')

    stock_codes = get_stock_basics()
    threads = []
    try:
        """
        ????????????
        """
        stocks = Queue.Queue(len(stock_codes))
        for code in stock_codes.index:
            code = str(code)
            if (len(code) != 6):
                code = (6 - len(code)) * '0' + code
            stocks.put(code)

        """
        ???????
        """
        for n in range(THREADS_NUM):
            thread = GetStockData(n, stocks)
            thread.start()
            threads.append(thread)

        while not stocks.empty():
            pass
        print u'??????'
        THREADS_EXITFLAG = 1

        for t in threads:
            t.join()
    except BaseException as e:
        print ('Error', e)
    return
worker.py 文件源码 项目:flats 作者: librae8226 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_stock_basics():
    ''' invoke tushare get_stock_basics() with csv output
    args:
    returns: csv format data containing the whole martket information
    json fomat, df.to_json('basics.json', orient='index')
    '''

    filename = PREFIX + '/' + 'basics.csv'
    df = ts.get_stock_basics()
    df.sort_index(inplace=True)
    return df.to_csv(filename, encoding='UTF-8')
m_load_update_data.py 文件源码 项目:Stock 作者: liuguoyaolgy 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_all_stick_inf(self):
        try:
            df = ts.get_stock_basics()
        except Exception as e:
            print('Err:',e)
            return

        cnt = 0;
        print('begin====== ??????? ????????????? ===============')
        while cnt < 3:
            try:
                self.cur.execute("select count(*) from t_all_stickcode; ")
                rs = self.cur.fetchall()
                print('rs:',rs[0][0],len(df))
                if rs[0][0] == len(df) :
                    break
                print('delete')
                self.cur.execute("delete from t_all_stickcode; ")
                self.sqlconn.commit()
                print('insert')
                df.to_sql('t_all_stickcode',self.engine,if_exists='append')
            except:
                print('err')
                df.to_sql('t_all_stickcode',self.engine,if_exists='append')
            cnt += 1;

        #df = ts.get_
        self.sqlconn.commit()
        return
strategy.py 文件源码 项目:silverstrategy 作者: silverhandy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_stock_basics(self, saveFile):
        info = ts.get_stock_basics()
        if saveFile:
            info.to_csv("./output/stock_basics.csv")
        return info
fetch_each_day.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self):
        #self.baseinfo=ts.get_stock_basics()

        self.getDate()
store_sql.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def save_baseinfo():
    df = ts.get_stock_basics()
    #print df
    df = df.reset_index()
    df.to_sql('baseinfo',engine)

#?????????????
tushare_case.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def main():
    now = time.strftime("%Y-%m-%d")
    # print now
    token = '60517739976b768e07823056c6f9cb0fee33ed55a1709b3eaa14a76c6a1b7a56'
    sb = StockBox()
    # sb.looper(id)
    id = '300333'
    # sb.realtime(id)
    sb.base_function("300333")
    # pandas_test=Pandas_test()
    # pandas_test.test_function()
    # sb.longhuban('2016-04-05')
    # sb.getNews()
    # sb.fund()
    #sb.get_stock_chengfeng()
    #sb.date_store()
    #sb.profit_test()
    #sb.daily_longhu()


    # ?????? ?3????
    history = ts.get_hist_data(id)

    print u"??3????"

    print history.head(10)

    history_all = ts.get_h_data(id, '20015101', '20160101')

    print u'???????'
    print history_all



    # print type(stockInfo)
    # print stockInfo.head()
    # print stockInfo.dtypes
    #df = ts.get_stock_basics()
    #data = df.ix[id]['timeToMarket']
    #print data
    #ts.get_today_all()
tushare_case.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_info(self, id):
    # ???????????
    df = ts.get_stock_basics()
    print df.ix['300333']['timeToMarket']
tushare_case.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_info(self, id):
    # ???????????
    df = ts.get_stock_basics()
    print df.ix['300333']['timeToMarket']
select_stock.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):
        self.bases_save=ts.get_stock_basics()

        self.bases_save.to_csv('bases.csv')

        # ??????????????
        self.today = time.strftime("%Y-%m-%d", time.localtime())
        self.base = pd.read_csv('bases.csv', dtype={'code': np.str})
        self.all_code = self.base['code'].values
        self.working_count=0
        self.mystocklist = Toolkit.read_stock('mystock.csv')

    # ???excel ?? ????csv ??,excel??.
k_line.py 文件源码 项目:stock 作者: Rockyzsu 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def store_base_data(self, target):
        self.all_info = ts.get_stock_basics()
        self.all_info = self.all_info.reset_index()
        print self.all_info
        if target == 'sql':
            self.all_info.to_sql('tb_baseinfo', engine,if_exists='replace')

        elif target == 'csv':
            self.all_info.to_csv('baseInfo.csv')
        else:
            logging.info('sql or csv option. Not get right argument')

    # ?????????
Fetch_Data_Stock_CHN_StockList.py 文件源码 项目:StockRecommendSystem 作者: doncat99 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def getStocksList_CHN(root_path):
    try:
        df = queryStockList(root_path, "DB_STOCK", "SHEET_CHN")
        df.index = df.index.astype(str).str.zfill(6)
    except Exception as e:
        df = pd.DataFrame()

    if df.empty == False: return df

    stock_info = ts.get_stock_basics()
    listData = pd.DataFrame(stock_info)
    listData['daily_update'] = '1970-07-01'
    listData['weekly_update'] = '1970-07-01'
    listData['monthly_update'] = '1970-07-01'
    listData['news_update'] = '1970-07-01'
    listData.index.name = 'symbol'
    listData = listData.reset_index()

    #listData.index.name = 'symbol'
    #listData.index = listData.index.astype(str).str.zfill(6) #[str(symbol).zfill(6) for symbol in listData.index] #listData.index.astype(str).str.zfill(6)
    #print(listData.index)
    #listData['symbol'] = listData['symbol'].str.strip()

    storeStockList(root_path, "DB_STOCK", "SHEET_CHN", listData)
    df = queryStockList(root_path, "DB_STOCK", "SHEET_CHN")

    if df.empty == False: df.index = df.index.astype(str).str.zfill(6)
    return df
Filter_Stock_Cashflow_CHN.py 文件源码 项目:StockRecommendSystem 作者: doncat99 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def processing_sector_cashflow_count(root_path, symbols, dates):
    stock_info = ts.get_stock_basics()

    sector_columns = list(set(stock_info['industry'].values.tolist()))

    sector_count = pd.DataFrame(columns=sector_columns, index=dates)
    sector_count.index.name = 'date'
    sector_count = sector_count.fillna(0)

    pbar = tqdm(total=len(symbols))

    for symbol in symbols:
        startTime = time.time()
        out_file = root_path + "/Data/CSV/cashflow/" + symbol + ".csv"
        column = stock_info[stock_info.index == symbol]["industry"][0]

        if os.path.exists(out_file) == False:
            pbar.update(1)
            #print(symbol, column)
            continue

        df_symbol = pd.read_csv(out_file, index_col=["date"])
        df = df_symbol['buy_amount'] - df_symbol["sell_amount"]
        sector_count[column] = sector_count[column].add(df, fill_value=0)

        outMessage = '%-*s processed in:  %.4s seconds' % (6, symbol, (time.time() - startTime))
        pbar.set_description(outMessage)
        pbar.update(1)

    pbar.close()

    sector_count = sector_count.sort_index(ascending=False)
    sector_count.to_csv("cashflow_sector.csv")
tushare69ds.py 文件源码 项目:zStock 作者: superxhy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, name):
        super(TsDatasrc, self).__init__(name)
        print 'security init begin ...'
        self.__initFlag__()
        self.__df_allsecurities__ = ts.get_stock_basics().sort_index()
        print 'security init end ...'


问题


面经


文章

微信
公众号

扫码关注公众号