本文整理汇总了Python中tushare.get_stock_basics方法的典型用法代码示例。如果您正苦于以下问题:Python tushare.get_stock_basics方法的具体用法?Python tushare.get_stock_basics怎么用?Python tushare.get_stock_basics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tushare
的用法示例。
在下文中一共展示了tushare.get_stock_basics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stock_select_to_sql
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def stock_select_to_sql(PE,TotalAssists):
create_stock_select_table()
df=ts.get_stock_basics()
#df.to_excel('c:/python/all_stock_list.xlsx')
df= df[df['pe'] < PE]
df= df[df['pe'] > 0]
print(df)
#df.to_excel('c:/python/all_stock_pe50.xlsx')
df= df[df['totalAssets'] >= TotalAssists]
df= df[df['rev'] >= 0]
df= df[df['profit'] >= 0]
#df.to_excel('c:/python/all_stock_assets100.xlsx')
print(df)
print('...........................before')
#df=df.iloc[1:]
#df.to_excel('c:/python/all_stock_assets100head.xlsx')
#sql.df_to_mysql('all_stock_select',df)
df_to_mysql('all_stock_select',df)
print('...........................after')
示例2: QA_save_stock_day_all
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def QA_save_stock_day_all(client=DATABASE):
df = ts.get_stock_basics()
__coll = client.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, start='1990-01-01')
__coll.insert_many(data_json)
except Exception as e:
print(e)
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')
示例3: __init__
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def __init__(self):
super().__init__()
self.frequence = FREQUENCE.DAY
self.market_type = MARKET_TYPE.STOCK_CN
# self.stock_basics = QATs.get_stock_basics()
# self.time_to_Market_300439 = self.stock_basics.loc['300439', 'timeToMarket']
# self.time_to_Market_300439 = QA.QA_util_date_int2str(self.time_to_Market_300439)
# self.time_to_day = QA_util_datetime_to_strdate(QA.QA_util_date_today())
# print(self.time_to_Market_300439)
# print(self.time_to_day)
self.time_to_Market_300439 = '2015-04-22'
self.time_to_day = '2018-05-01'
self.df_from_Tdx = QA_fetch_stock_day(
'300439', self.time_to_Market_300439, self.time_to_day, 'pd')
# print(self.df_from_Tdx)
self.ma05 = QA_indicator_MA(self.df_from_Tdx, 5)
self.ma10 = QA_indicator_MA(self.df_from_Tdx, 10)
self.ma15 = QA_indicator_MA(self.df_from_Tdx, 15)
self.ma20 = QA_indicator_MA(self.df_from_Tdx, 20)
# print(self.df5)
示例4: run_daybacktest
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def run_daybacktest(self):
#import QUANTAXIS as QA
# print(QA.QA_fetch_stock_block_adv().code[0:5])
# self.stock_basics = QATs.get_stock_basics()
# self.time_to_Market_300439 = self.stock_basics.loc['300439', 'timeToMarket']
# self.time_to_Market_300439 = QA.QA_util_date_int2str(self.time_to_Market_300439)
# self.time_to_day = QA_util_datetime_to_strdate(QA.QA_util_date_today())
# print(self.time_to_Market_300439)
# print(self.time_to_day)
# QA.QA_util_time_now()
self.time_to_Market_300439 = '2015-04-22'
self.time_to_day = '2018-05-01'
backtest = Backtest(market_type=MARKET_TYPE.STOCK_CN,
frequence=FREQUENCE.DAY,
start=self.time_to_Market_300439,
end=self.time_to_day,
code_list=['300439'],
commission_fee=0.00015)
backtest.start_market()
backtest.run()
backtest.stop()
print("结束回测!")
示例5: getStocksList_CHN
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
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
示例6: processing_sector_cashflow_count
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
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")
示例7: QA_SU_save_stock_info_tushare
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def QA_SU_save_stock_info_tushare(client=DATABASE):
'''
获取 股票的 基本信息,包含股票的如下信息
code,代码
name,名称
industry,所属行业
area,地区
pe,市盈率
outstanding,流通股本(亿)
totals,总股本(亿)
totalAssets,总资产(万)
liquidAssets,流动资产
fixedAssets,固定资产
reserved,公积金
reservedPerShare,每股公积金
esp,每股收益
bvps,每股净资
pb,市净率
timeToMarket,上市日期
undp,未分利润
perundp, 每股未分配
rev,收入同比(%)
profit,利润同比(%)
gpr,毛利率(%)
npr,净利润率(%)
holders,股东人数
add by tauruswang
在命令行工具 quantaxis 中输入 save stock_info_tushare 中的命令
:param client:
:return:
'''
df = QATs.get_stock_basics()
print(" Get stock info from tushare,stock count is %d" % len(df))
coll = client.stock_info_tushare
client.drop_collection(coll)
json_data = json.loads(df.reset_index().to_json(orient='records'))
coll.insert(json_data)
print(" Save data to stock_info_tushare collection, OK")
示例8: QA_save_stock_day_all_bfq
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def QA_save_stock_day_all_bfq(client=DATABASE):
df = ts.get_stock_basics()
__coll = client.stock_day_bfq
__coll.ensure_index('code')
def saving_work(i):
QA_util_log_info('Now Saving ==== %s' % (i))
try:
df = QA_fetch_get_stock_day(i, start='1990-01-01', if_fq='bfq')
__coll.insert_many(json.loads(df.to_json(orient='records')))
except Exception as e:
print(e)
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')
示例9: QA_save_stock_day_with_fqfactor
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def QA_save_stock_day_with_fqfactor(client=DATABASE):
df = ts.get_stock_basics()
__coll = client.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,
start='1990-01-01',
if_fq='02',
type_='pd'
)
data_json = QA_util_to_json_from_pandas(data_hfq)
__coll.insert_many(data_json)
except Exception as e:
print(e)
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
示例10: QA_fetch_get_stock_info
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def QA_fetch_get_stock_info(name):
data = ts.get_stock_basics()
try:
return data if name == '' else data.loc[name]
except:
return None
示例11: getStockBasicFromTushare
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def getStockBasicFromTushare(self,dbName,colName):
db = self._Conn[dbName]
collection = db.get_collection(colName)
stock_basic_info = ts.get_stock_basics()
for i in range(len(stock_basic_info)):
data = {stock_basic_info.index.name : stock_basic_info.index[i]}
data.update({'name' : stock_basic_info['name'][i]})
data.update({'industry' : stock_basic_info['industry'][i]})
data.update({'area' : stock_basic_info['area'][i]})
data.update({'pe' : stock_basic_info['pe'][i]})
data.update({'outstanding' : stock_basic_info['outstanding'][i]})
data.update({'totals' : stock_basic_info['totals'][i]})
data.update({'totalAssets' : stock_basic_info['totalAssets'][i]})
data.update({'liquidAssets' : stock_basic_info['liquidAssets'][i]})
data.update({'fixedAssets' : stock_basic_info['fixedAssets'][i]})
data.update({'reserved' : stock_basic_info['reserved'][i]})
data.update({'reservedPerShare' : stock_basic_info['reservedPerShare'][i]})
data.update({'esp' : stock_basic_info['esp'][i]})
data.update({'bvps' : stock_basic_info['bvps'][i]})
data.update({'pb' : stock_basic_info['pb'][i]})
data.update({'undp' : stock_basic_info['undp'][i]})
data.update({'perundp' : stock_basic_info['perundp'][i]})
data.update({'rev' : stock_basic_info['rev'][i]})
data.update({'profit' : stock_basic_info['profit'][i]})
data.update({'gpr' : stock_basic_info['gpr'][i]})
data.update({'npr' : stock_basic_info['npr'][i]})
data.update({'holders' : stock_basic_info['holders'][i]})
#detail = dict(zip(stock_basic_info.columns, [stock_basic_info[j][i] for j in stock_basic_info.columns]))
collection.insert_one(data)
示例12: calcu_all_stocks_3year_roe_and_average_profit
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def calcu_all_stocks_3year_roe_and_average_profit(year): # 生成3年平均利润列表
path = os.path.join(current_folder, 'stock_list%s.csv' % today)
if not os.path.exists(path):
data = ts.get_stock_basics()
lie = [
'名字', '行业', '地区', '市盈率', '流通股本', '总股本', '总资产(万)', '流动资产', '固定资产',
'公积金', '每股公积金', '每股收益', '每股净资', '市净率', '上市日期', '未分利润', '每股未分配',
'收入同比(%)', '利润同比(%)', '毛利率(%)', '净利润率(%)', '股东人数'
]
data.columns = lie
data.index.names = ['代码']
data = data[data['上市日期'] < three_year_ago()] # 排除上市不满3年的公司
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
data.loc[index, '上4年roe'], data.loc[index, '上3年roe'], data.loc[index, '上2年roe'], \
data.loc[index, '上1年roe'], data.loc[index, '当年roe'] = last_5_year_roe('%06d' % index, year)
print('完成%s' % index)
data.to_csv(
os.path.join(current_folder, '3年平均利润及其他财务指标%s.csv' % today),
encoding='utf-8')
示例13: Get_all_industry_average_data
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def Get_all_industry_average_data():
a = ts.get_stock_basics()
for i in range(0,len(a)):
print('industry:',a.iloc[i,1])
test=Estimation(dbconn,a.iloc[i,1],2017)
# App示例代码,用完删掉
#Estimation(dbconn,'家电行业')
#print(GetIndustryName('福耀玻璃'))
#CreateTable()
#Estimation(dbconn,GetIndustryName('宁沪高速'),2017)
#Estimation(dbconn,GetIndustryName('格力电器'),2017)
#Estimation(dbconn,GetIndustryName('福耀玻璃'),2017)
#Estimation(dbconn,GetIndustryName('隆基股份'),2017)
#def get_interest_list():
# '''
# 解析"感兴趣的个股列表.txt",返回list类型的数据供其他模块使用
# '''
# list_id = []
# with open('../SQL/感兴趣的个股列表.txt','r') as fh:
# s = fh.readline() #获取更新时间
# s = fh.readline() #获取目标长度
#
# lines = fh.readlines() #获取目标内容
# for s in lines:
# code = s[:6]
# list_id.append(code)
# list_id.sort()
# return list_id
#
#for s in get_interest_list():
# Estimation(dbconn,GetIndustryName(s),2017)
示例14: Estimation
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def Estimation():
result_df = pd.DataFrame(ts.get_stock_basics().values,columns = ts.get_stock_basics().columns)
df_to_mysql('industry_estimation_detail',result_df)
return result_df
#作用:查看行业平均值统计
#输入:行业名称
#输出:行业平均统计数
示例15: industry_stat
# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_stock_basics [as 别名]
def industry_stat(industry):
df = pd.DataFrame(ts.get_stock_basics().values,columns = ts.get_stock_basics().columns)
pe_stat = df[df.industry == industry].drop(['name','industry','area'], axis = 1).astype('float')
# =============================================================================
# print(pe_stat.dtypes)
# =============================================================================
result_df = pe_stat.describe()
print(result_df)
return result_df
#作用:查看行业平均值统计
#输出:所有行业平均统计数(筛选条件:PE <100,pb <10,1000>rev>-1000,1000>profit>-1000,,1000>gpr>-1000,,1000>npr>-1000)