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

  由于tushare返回的数据格式是pandas库中的dataFrame,所以有必要研究一下dataFrame这种数据结构,参考http://pandas.pydata.org/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
outstanding         float64
totals              float64
totalAssets         float64
liquidAssets        float64
fixedAssets         float64
reserved            float64
reservedPerShare    float64
esp                 float64
bvps                float64
pb                  float64
timeToMarket          int64
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/2019-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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值