Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于分形确认时机提前到K线包含处理之后马上进行的建议 #91

Open
chzhshch-new opened this issue Jun 13, 2022 · 3 comments

Comments

@chzhshch-new
Copy link

    # 去除包含关系
    bars_ubi = self.bars_ubi
    for bar in last_bars:
        if len(bars_ubi) < 2:
            bars_ubi.append(NewBar(symbol=bar.symbol, id=bar.id, freq=bar.freq, dt=bar.dt,
                                   open=bar.open, close=bar.close,
                                   high=bar.high, low=bar.low, vol=bar.vol, elements=[bar]))
        else:
            k1, k2 = bars_ubi[-2:]
            has_include, k3 = remove_include(k1, k2, bar)
            if has_include:
                bars_ubi[-1] = k3
            else:
                bars_ubi.append(k3)
    self.bars_ubi = bars_ubi
    **check_fx(k1: NewBar, k2: NewBar, k3: NewBar)**#在此处理确认分形,分形的确认不存被破坏的情况,该周期的K交易结束,是否分形就确认了,不会再改变了。
  如果是无分形是中间K线,就可直接返回.....
  在后面check_bi(bars_ubi),把未完成对应的分形传过去,直接判断,不必每次都要对bars_ubi重新判断一下分形。这个计算量其实非常大,特别未完成笔的无包含K线序列很多时。


    # 更新笔
    self.__update_bi()

本人刚自学python,暂无法给出具体的代码。只是有这样优化的想法。

@zengbin93
Copy link
Member

@chzhshch-new 这个建议挺好的。后续版本改一下。方便的话,加微信 zengbin93 交流

@chzhshch-new
Copy link
Author

chzhshch-new commented Aug 29, 2022

昨晚全市场跑一次,这样改不能减少时间。不知问题所在。

@zengbin93 我尝试做和验证部份标的,没发现问题。
check_bi,__update_bi 两个中改动下就可以。check_fxs这个可以不用调用。隐含的BUG也自动解决了。

第1个改动处
def check_bi(bars: List[NewBar], fxs_ubi: List[FX] = None, benchmark: float = None):
"""输入一串无包含关系K线,查找其中的一笔

:param bars: 无包含关系K线列表
:param fxs_ubi:未完成笔对应的分型列表
:param benchmark: 当下笔能量的比较基准
:return:
"""
min_bi_len = envs.get_min_bi_len()

# 增改*接收处理
if not fxs_ubi:
    fxs = check_fxs(bars)
else:
    #fxs = fxs_ubi
    fxs = check_fxs(bars)
    if fxs_ubi != fxs:
        print(fxs[-1].dt,fxs_ubi[-1].dt)

第2个改动
def __update_bi(self):
bars_ubi = self.bars_ubi
if len(bars_ubi) < 3:
return

    # 增改*分型确认
    fx: FX = check_fx(bars_ubi[- 3], bars_ubi[- 2], bars_ubi[- 1])
    if isinstance(fx, FX):
        if not self.fx_list or fx.dt != self.fx_list[-1].dt:     # 第一个分型的确认
            self.fx_list.append(fx)
        else:
            self.fx_list[-1] = fx    # 分型右侧存在包含,更新

第3-4个改动
if not self.bi_list:
# 第一个笔的查找
# fxs = check_fxs(bars_ubi)
# if not fxs:
if not self.fx_list:
return
# 增改*直接取分fx来
fxs = self.fx_list

        fx_a = fxs[0]
        fxs_a = [x for x in fxs if x.mark == fx_a.mark]
        for fx in fxs_a:
            if (fx_a.mark == Mark.D and fx.low <= fx_a.low) \
                    or (fx_a.mark == Mark.G and fx.high >= fx_a.high):
                fx_a = fx
        bars_ubi = [x for x in bars_ubi if x.dt >= fx_a.elements[0].dt]

        # 增改*直接传fxs来
        fxs_ubi = [x for x in self.fx_list if x.dt >= bars_ubi[0].dt]
        bi, bars_ubi_ = check_bi(bars_ubi,fxs_ubi)

第5个改动
# 增改*直接传分fx来
fxs_ubi = [x for x in self.fx_list if x.dt > bars_ubi_a[0].dt]

    bi, bars_ubi_ = check_bi(bars_ubi_a,fxs_ubi, benchmark)
    self.bars_ubi = bars_ubi_
    if isinstance(bi, BI):
        self.bi_list.append(bi)

@zengbin93
Copy link
Member

@chzhshch-new 对于程序来说,重复算部分结果,可能对整体的时间性能影响不大。你把改完之后的完整 analyze.py 文件发给我看看。我对比一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants