def is_third_buy(symbol): """判断一个股票现在是否有日线三买""" bars = get_kline(symbol, freq="D", end_date=datetime.now(), count=1000) c = CZSC(bars, get_signals=get_default_signals) factor_ = Factor( name="类三买选股因子", signals_any=[ Signal("日线_倒1笔_基础形态_类三买_任意_任意_0"), Signal("日线_倒1笔_类买卖点_类三买_任意_任意_0"), ], signals_all=[ Signal("日线_倒1笔_拟合优度_小于0.2_任意_任意_0") ] ) if factor_.is_match(c.signals): return True else: return False
def test_factor(): freq = Freq.F15 s = OrderedDict() default_signals = [ Signal(k1=str(freq.value), k2="倒0笔", k3="方向", v1="向上", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒0笔", k3="长度", v1="大于5", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒0笔", k3="三K形态", v1="顶分型", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒1笔", k3="表里关系", v1="其他", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒1笔", k3="RSQ状态", v1="小于0.2", v2='其他', v3='其他'), ] for signal in default_signals: s[signal.key] = signal.value factor = Factor(name="单测", signals_all=[ Signal(k1=str(freq.value), k2="倒0笔", k3="方向", v1="向上", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒0笔", k3="长度", v1="大于5", v2='其他', v3='其他') ]) assert factor.is_match(s) factor = Factor(name="单测", signals_all=[ Signal(k1=str(freq.value), k2="倒0笔", k3="方向", v1="向上", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒0笔", k3="长度", v1="大于5", v2='其他', v3='其他') ], signals_any=[ Signal(k1=str(freq.value), k2="倒1笔", k3="RSQ状态", v1="小于0.2", v2='其他', v3='其他') ]) assert factor.is_match(s) factor = Factor(name="单测", signals_all=[ Signal(k1=str(freq.value), k2="倒0笔", k3="方向", v1="向上", v2='其他', v3='其他'), Signal(k1=str(freq.value), k2="倒0笔", k3="长度", v1="大于5", v2='其他', v3='其他') ], signals_any=[ Signal(k1=str(freq.value), k2="倒1笔", k3="RSQ状态", v1="小于0.8", v2='其他', v3='其他') ]) assert not factor.is_match(s)