量化选股的常用python模块,介绍tushare使用中,总结的一些短代码
import tushare as ts
symbols = ts.get_stock_basics()
st = ts.get_st_classified()
lv_price_1 = 50
def isSt(stockID):
for sti in st.code:
if sti == stockID:
return True
return False
for inx in range(len(symbols)):
symbol = symbols.index[inx]
df = ts.get_k_data(symbol, ktype='60', start=start_day)
1,过滤停牌
xn = len(df.index)-1
if type(df) != type(None) and xn >= 0 and df.ix[xn]['date'] != endToday:
continue
2,过滤高价股
if type(df) != type(None) and xn >= 0 and df.ix[xn]['close'] > lv_price_1 ):
continue
3,过滤PE
pe = symbols.ix[inx]['pe']
if pe < 20:
continue
4,过滤ST
if isSt(symbol):
continue
更多见开源项目 https://gitee.com/yquant/YKQuantPublisher
本文介绍了一个基于Python的量化选股策略实现案例,利用tushare模块获取股票基本信息,并通过定义筛选条件来过滤停牌、高价股、市盈率过低及ST股。文章提供了具体的代码示例并链接了开源项目。

323

被折叠的 条评论
为什么被折叠?



