1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > tushare获取当天涨停的股票代码

tushare获取当天涨停的股票代码

时间:2023-05-27 14:24:03

相关推荐

tushare获取当天涨停的股票代码

由于tushare返回的数据格式是pandas库中的dataFrame,所以有必要研究一下dataFrame这种数据结构,参考/pandas-docs/stable/reference/api/pandas.DataFrame.html

>>> df = ts.get_stock_basics()

>>>df.index

Index([u'601698', u'600744', u'300224', u'603648', u'000544', u'300140',

u'603867', u'002463', u'300243', u'603863',

...

u'688003', u'688002', u'688001', u'603983', u'603687', u'603530',

u'603256', u'603236', u'601236', u'600074'],

dtype='object', name=u'code', length=3641)

>>>df.dtypes

name object

industry object

area object

pe float64

outstandingfloat64

totals float64

totalAssetsfloat64

liquidAssets float64

fixedAssetsfloat64

reservedfloat64

reservedPerShare float64

esp float64

bvps float64

pb float64

timeToMarketint64

undp float64

perundp float64

rev float64

profit float64

gpr float64

npr float64

holders float64

dtype: object

df = ts.get_hist_data('xxx')

>>> df.columns

Index([u'open', u'high', u'close', u'low', u'volume', u'price_change',

u'p_change', u'ma5', u'ma10', u'ma20', u'v_ma5', u'v_ma10', u'v_ma20'],

dtype='object')

每只股票的振幅=df.price_change/df.open

源码:

#coding=utf-8

import tushare as ts

#获取当日所有股票代码

df = ts.get_stock_basics()

codes = df.index

#对每一只股票计算涨幅,提取出涨幅大于5的全部股票

for i in range(0, len(codes)):

try:

df1 = ts.get_hist_data(codes[i])

filename = './result/-06-30.txt'

fp = open(filename, 'a')

val = df1.p_change[0]#price_change[0]/df1.open[0]

if val > 5:

print('%s %s %s' %(codes[i], df.name[i], val))

fp.write('%s %s %s' %(codes[i], df.name[i], val))

fp.close()

except:

pass

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。