原帖: http://www.30daydo.com/article/70
股市有句话,新高后有新高。
因为新高后说明消化了前面的套牢盘。 所以这个时候的阻力很小。
下面使用一个例子来用代码获取当天创新高的股票。
使用的是tushare
#-*-coding=utf-8-*-
__author__ = 'rocky'
#获取破指定天数内的新高 比如破60日新高
import tushare as ts
import datetime
info=ts.get_stock_basics()
def loop_all_stocks():
for EachStockID in info.index:
if is_break_high(EachStockID,60):
print "High price on",
print EachStockID,
print info.ix[EachStockID]['name'].decode('utf-8')
def is_break_high(stockID,days):
end_day=datetime.date(datetime.date.today().year,datetime.date.today().month,datetime.date.today().day)
days=days*7/5
#考虑到周六日非交易
start_day=end_day-datetime.timedelta(days)
start_day=start_day.strftime("%Y-%m-%d")
end_day=end_day.strftime("%Y-%m-%d")
df=ts.get_h_data(stockID,start=start_day,end=end_day)
period_high=df['high'].max()
#print period_high
today_high=df.iloc[0]['high']
#这里不能直接用 .values
#如果用的df【:1】 就需要用.values
#print today_high
if today_high>=period_high:
return True
else:
return False
loop_all_stocks()
可以修改 函数 is_break_high(EachStockID,60) 中的60 为破多少天内的新高。
上一篇:30天学会量化交易模型 Day03
http://www.30daydo.com/article/15
下一篇: 30天学会量化交易模型 Day05 (tushare数据写入SQLite)
http://www.30daydo.com/article/73
更多文章: