量化選股的常用python模塊悠夯,介紹tushare使用中,總結(jié)的一些短代碼
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