Python tushare.get_hs300s() Examples

The following are 5 code examples of tushare.get_hs300s(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tushare , or try the search function .
Example #1
Source File: mongodb.py    From zipline-chinese with Apache License 2.0 6 votes vote down vote up
def storagepool(self):
        #storage zz500
        df=ts.get_zz500s()
        self.pool['zz500'].insert_many(json.loads(df.to_json(orient='records')))
        #hs300
        df=ts.get_hs300s()
        self.pool['hz300'].insert_many(json.loads(df.to_json(orient='records')))
        #zh50
        df=ts.get_sz50s()
        self.pool['sz'].insert_many(json.loads(df.to_json(orient='records')))
        #st
        df=ts.get_st_classified()
        self.pool['st'].insert_many(json.loads(df.to_json(orient='records')))
        
        
    
        
    #get the particular stock list from data base 
Example #2
Source File: spyder_tushare.py    From quantproject with Apache License 2.0 5 votes vote down vote up
def get_hs300s_classified(self):
        """
        'hs300s',##是否是沪深300当前成份股及所占权重
        """
        hs300 = ts.get_hs300s()
        hs300['hs300sName'] = 1
        hs300 = hs300[['code','hs300sName','date', 'weight']]
        
        hs300.columns = ['code','hs300sName','hs300sDate', 'hs300sWeight']
        self.data = pd.merge(self.data,hs300,on=['code'],how='outer') 
Example #3
Source File: classify_to_sql.py    From anack with GNU General Public License v3.0 5 votes vote down vote up
def classify_info_to_sql():
    create_classify_table()    
    
    a = ts.get_industry_classified()
    a.columns = ['code', 'name', 'industry']
    b = ts.get_area_classified()
    c = ts.get_sz50s()
    c = c.iloc[:,1::]
    c['sz50'] = '1'
    d = ts.get_hs300s()
    d = d.iloc[:,1::]
    d.columns = ['code','name','hs300_weight']
    e = ts.get_zz500s()
    e = e.iloc[:,1::]
    e.columns = ['code','name','zz500_weight']
    result = pd.merge(a, b, how='left', on=None, left_on=None, right_on=None,
             left_index=False, right_index=False, sort=True,
             suffixes=('_x', '_y'), copy=True, indicator=False)
    result = pd.merge(result, c, how='left', on=None, left_on=None, right_on=None,
             left_index=False, right_index=False, sort=True,
             suffixes=('_x', '_y'), copy=True, indicator=False)
    result = pd.merge(result, d, how='left', on=None, left_on=None, right_on=None,
             left_index=False, right_index=False, sort=True,
             suffixes=('_x', '_y'), copy=True, indicator=False)
    result = pd.merge(result, e, how='left', on=None, left_on=None, right_on=None,
             left_index=False, right_index=False, sort=True,
             suffixes=('_x', '_y'), copy=True, indicator=False)
    df_to_mysql('anack_classify',result)
    
#    ------------------------------------------------------------- 
Example #4
Source File: classify.py    From anack with GNU General Public License v3.0 5 votes vote down vote up
def hs300():
    return ts.get_hs300s() 
Example #5
Source File: data_fetch.py    From factorset with MIT License 4 votes vote down vote up
def data_fetch():
    """
    从config中读取配置,爬取行情,基本面,及其他数据。
    """
    gc = GetConfig()
    if gc.target == 'all':
        target = pd.read_csv(data.__file__.strip(data.__file__.split('\\')[-1])+'allAShare.csv')
        target = target['0']
    elif gc.target == 'hs300':
        hs300 = ts.get_hs300s()
        hs300.code = hs300.code.apply(code_to_symbol)
        target = hs300.code.tolist()
    else:
        if isinstance(gc.target, str):
            target = gc.target.split(', ')
        assert isinstance(target, list)

    # Arctic Start
    if gc.MONGO:
        from arctic import Arctic
        a = Arctic(gc.ahost)
        a.initialize_library('Ashare')
        lib_stock = a['Ashare']
    else:
        lib_stock = None

    # Stock & index
    print("Start Fetching Stock & Index Data!")
    StockSaver.write_all_stock(target, lib_stock)
    try:
        StockSaver.save_index('000905')
        time.sleep(0.1)
        StockSaver.save_index('000300')
    except IOError as e:
        print(e)
    print("Finish Fetching Stock & Index Data!")

    # Other data
    print("Start Fetching Other Data!")
    OtherData.write_all_date(OtherData.tradecal())
    OtherData.write_new_stocks()
    print("Finish Fetching Other Data!")

    # Fundamental data
    while 1:
        print("Start Fetching Fundamental Data!")
        if len(get_all_proxy(gc.proxypool)) >= gc.proxymin:
            a = FundCrawler('BS')
            a.main(target, num=5)
            b = FundCrawler('IS')
            b.main(target, num=5)
            c = FundCrawler('CF')
            c.main(target, num=5)
            print("Finish Fetching Fundamental Data!")

            break
        else:
            print("Proxy pool is not ready! We only have {} proxies!".format(len(get_all_proxy(gc.proxypool))))
            time.sleep(5)