# talib实现聚宽选股所有的形态指标

导入函数库
import jqdata
import warnings
import numpy as np
from kuanke.wizard import *

# 初始化函数，设定基准等等
def initialize(context):

security = '000001.XSHE'
st = attribute_history('000001.XSHE', 5)
print(st['close'].mean())
security_list = list(get_all_securities('stock', context.current_dt).index)
print(len(security_list))
list0 = [security for security in security_list if CDLMORNINGSTAR_judge0(security)]
print(len(list0))
# list1 = [security for security in security_list if CDLSHOOTINGSTAR_judge0(security)]
# print(len(list1))

#红三兵
def CDL3WHITESOLDIERS_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDL3WHITESOLDIERS(o, hi, l, c)
rs = i[-1] > 0
except:
traceback.print_exc()
finally:
return rs
#锤子
def CDLHAMMER_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDLHAMMER(o, hi, l, c)
rs = i[-1] > 0
except:
traceback.print_exc()
finally:
return rs
#倒锤
def CDLINVERTEDHAMMER_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDLINVERTEDHAMMER(o, hi, l, c)
rs = i[-1] > 0
except:
traceback.print_exc()
finally:
return rs
##两只乌鸦
def CDL2CROWS_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDL2CROWS(o, hi, l, c)
#print(i)
rs = i[-1] == -100
except:
traceback.print_exc()
finally:
return rs
##三只乌鸦
def CDL3BLACKCROWS_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDL3BLACKCROWS(o, hi, l, c)
rs = i[-1] > 0
except:
traceback.print_exc()
finally:
return rs
##早晨之星
def CDLMORNINGSTAR_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDLMORNINGSTAR(o, hi, l, c)
rs = i[-1] > 0
except:
traceback.print_exc()
finally:
if rs == True:
print(security)
return rs
##黄昏之星
def CDLEVENINGSTAR_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDLEVENINGSTAR(o, hi, l, c)
rs = i[-1] == -100
except:
traceback.print_exc()
finally:
return rs
##乌云盖顶
def CDLDARKCLOUDCOVER_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDLDARKCLOUDCOVER(o, hi, l, c)
rs = i[-1] < 0
except:
traceback.print_exc()
finally:
return rs
##流星线
def CDLSHOOTINGSTAR_judge0(security):
try:
rs = False
h = attribute_history(security, 100)
#print(security,h)
o, hi, l, c = map((lambda x : np.array(h[x])),['open','high','low','close'])
i = talib.CDLSHOOTINGSTAR(o, hi, l, c)
rs = i[-1] < 0
except Exception, e:
traceback.print_exc()
finally:
if rs == True:
print(security,h)
return rs

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120