waditu / czsc

缠中说禅技术分析工具;缠论;股票;期货;Quant;量化交易
Other
2.88k stars 977 forks source link

jq_check_acc使用传入rawbars的疑问,用日线收盘价作为触发信号 #75

Closed ylrh3 closed 2 years ago

ylrh3 commented 2 years ago

1.生成的信号如下 我的基础bars 是60分钟的,生成日线的数据,我信号时想用日线的收盘价作为触发信号。

生成信号的函数

def get_signals(c: CZSC) -> OrderedDict:

c就是那基础bars 生成的高一级别的bars

s = OrderedDict({"symbol": c.symbol, "dt": c.bars_raw[-1].dt, "close": c.bars_raw[-1].close})
#print(s)
if c.freq == Freq.D:

    s.update(get_s_shunxu(c, di=1))
return s

2.ta.py里写的信号如下 def get_s_shunxu(c: analyze.CZSC, di: int = 1) -> OrderedDict: """倒数第i根K线的三K形态信号

:param c: CZSC 对象
:param di: 最近一根K线为倒数第i根
:return: 信号字典
"""

global guancha
global shaixq
assert di >= 1
freq: Freq = c.freq
k1 = str(freq.value)
k2 = f"倒{di}K"
s = OrderedDict()
v = Signal(k1=k1, k2=k2, k3="shunxu", v1="其他", v2='其他', v3='其他')
s[v.key] = v.value  #i['日线_倒1K_结束']=='是_任意_任意_0'
#tri1=c.bars_raw[-len(c.bars_raw):-1]  #因为最后一根是未完成的,由4根60分钟走完后,才形成一根完整的日线,不能要这句代码,因为这样生产的信号,实际生产的信号是11.16日,但是系统记录的时间是最新那一根,也就是最后一根的日期,11.17日
tri1 = c.bars_raw
print('传入数量%s' % (len(tri1)))
print('传入数据1%s' % (tri1[-1]))
if len(tri1) < 20:
    return s

3.但是打印的出来传入数量,发生了疑问。 3-1.102、103 最后一根都是日线一根一根传入,这个符合我日线收盘价触发信号的数据,但是到了105,最后一根就变成了60分钟,60分钟,60分钟,60分钟,其中最后一根的60分钟就是合成的日线数据。 传入数量102 传入数据1RawBar(symbol='sz.002771', id=123, dt=Timestamp('2015-12-28 00:00:00'), freq=<Freq.D: '日线'>, open=50.63, close=51.75, high=53.21, low=50.18, vol=3992600, amount=None, pctChg=None) 传入数量103 传入数据1RawBar(symbol='sz.002771', id=124, dt=Timestamp('2015-12-29 00:00:00'), freq=<Freq.D: '日线'>, open=49.75, close=47.23, high=51.01, low=46.58, vol=3154500, amount=None, pctChg=None) 传入数量104 传入数据1RawBar(symbol='sz.002771', id=125, dt=Timestamp('2015-12-30 00:00:00'), freq=<Freq.D: '日线'>, open=47.26, close=47.85, high=48.19, low=45.47, vol=1508000, amount=None, pctChg=None) generate snapshots of sz.002771: 0%| | 0/5642 [00:00<?, ?it/s]传入数量104 传入数据1RawBar(symbol='sz.002771', id=125, dt=Timestamp('2015-12-30 00:00:00'), freq=<Freq.D: '日线'>, open=47.26, close=46.97, high=48.19, low=45.47, vol=1809800, amount=None, pctChg=None) 传入数量105 传入数据1RawBar(symbol='sz.002771', id=126, dt=Timestamp('2015-12-31 00:00:00'), freq=<Freq.D: '日线'>, open=46.62, close=46.49, high=46.97, low=45.27, vol=643100, amount=None, pctChg=None) 传入数量105 传入数据1RawBar(symbol='sz.002771', id=126, dt=Timestamp('2015-12-31 00:00:00'), freq=<Freq.D: '日线'>, open=46.62, close=45.32, high=46.97, low=45.27, vol=975400, amount=None, pctChg=None) 传入数量105 传入数据1RawBar(symbol='sz.002771', id=126, dt=Timestamp('2015-12-31 00:00:00'), freq=<Freq.D: '日线'>, open=46.62, close=45.04, high=46.97, low=44.18, vol=1319500, amount=None, pctChg=None) 传入数量105 3-2 像109这时候才传入2根60分钟 传入数量108 传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=43.73, high=45.76, low=41.21, vol=1432200, amount=None, pctChg=None) 传入数量108 传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=44.02, high=45.76, low=41.21, vol=1833700, amount=None, pctChg=None) 传入数量108 传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=44.09, high=45.76, low=41.21, vol=2005700, amount=None, pctChg=None) 传入数量108 传入数据1RawBar(symbol='sz.002771', id=129, dt=Timestamp('2016-01-06 00:00:00'), freq=<Freq.D: '日线'>, open=41.67, close=44.73, high=45.76, low=41.21, vol=2331700, amount=None, pctChg=None) 传入数量109 传入数据1RawBar(symbol='sz.002771', id=130, dt=Timestamp('2016-01-07 00:00:00'), freq=<Freq.D: '日线'>, open=43.19, close=40.26, high=43.36, low=40.26, vol=446000, amount=None, pctChg=None) 传入数量109 传入数据1RawBar(symbol='sz.002771', id=130, dt=Timestamp('2016-01-07 00:00:00'), freq=<Freq.D: '日线'>, open=43.19, close=40.28, high=43.36, low=40.26, vol=461300, amount=None, pctChg=None) 传入数量110 传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=41.8, high=42.19, low=37.5, vol=807100, amount=None, pctChg=None) 传入数量110 传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=40.54, high=42.19, low=36.38, vol=1344100, amount=None, pctChg=None) 传入数量110 传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=41.18, high=42.19, low=36.38, vol=1504100, amount=None, pctChg=None) 传入数量110 传入数据1RawBar(symbol='sz.002771', id=131, dt=Timestamp('2016-01-08 00:00:00'), freq=<Freq.D: '日线'>, open=40.85, close=39.69, high=42.19, low=36.38, vol=1775300, amount=None, pctChg=None) 传入数量111

求老大解疑答惑

ylrh3 commented 2 years ago

就是我用basebar是60分钟的,然后生成日线的信号,我如何让它传入的时候,只取最后一根完成的日线rawbars,求大佬们指教一二。

zengbin93 commented 2 years ago

请参考:https://github.com/waditu/czsc/blob/d96a9b6294f627f1b89c713259170ee7c37645a3/examples/gm_utils.py#L124

ylrh3 commented 2 years ago

没看太明白这个案例,这个是生成高级别的?我是指传入信号里边的时候,取最后一根。因为我后边想多级别联立,比如用5分钟的生成,然后多级别,然后日线结束收盘价那里有个触发的条件,这样。