VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 1
声望: 0

在2.2.0版本原有的逻辑上增加了日线合成,独立的函数合成日线,避免耦合,实测2.3.0版本有效

下图中增加了日线合成的入口
description

    def update_bar_day_window(self, bar: BarData) -> None:
        if not self.day_bar:
            dt = bar.datetime.replace(hour=0, minute=0, second=0, microsecond=0)  # 日计算,替换掉小时,分钟,秒,毫秒
            self.day_bar = BarData(
                symbol=bar.symbol,
                exchange=bar.exchange,
                datetime=dt,
                gateway_name=bar.gateway_name,
                open_price=bar.open_price,
                high_price=bar.high_price,
                low_price=bar.low_price,
                volume=bar.volume
            )
            return

        finished_bar = None
        # 14:59收盘
        if bar.datetime.hour == 14 and bar.datetime.minute == 59:
            self.day_bar.high_price = max(
                self.day_bar.high_price,
                bar.high_price
            )
            self.day_bar.low_price = min(
                self.day_bar.low_price,
                bar.low_price
            )

            self.day_bar.close_price = bar.close_price
            self.day_bar.volume += int(bar.volume)
            self.day_bar.open_interest = bar.open_interest

            finished_bar = self.day_bar
            finished_bar.datetime = bar.datetime.replace(hour=0, minute=0, second=0, microsecond=0)
            self.day_bar = None

        # 未收盘则比价
        else:
            self.day_bar.high_price = max(
                self.day_bar.high_price,
                bar.high_price
            )
            self.day_bar.low_price = min(
                self.day_bar.low_price,
                bar.low_price
            )

            self.day_bar.close_price = bar.close_price
            self.day_bar.volume += int(bar.volume)
            self.day_bar.open_interest = bar.open_interest

        # Push finished window bar
        if finished_bar:
            self.on_day_bar(finished_bar)
            # print("finished_bar", finished_bar.datetime, finished_bar.close_price)

        # Cache last bar object
        self.last_bar = bar

    def on_day_bar(self, bar: BarData) -> None:
        """"""
        if self.window == 1:
            self.on_window_bar(bar)
        else:
            if not self.window_bar:
                self.window_bar = BarData(
                    symbol=bar.symbol,
                    exchange=bar.exchange,
                    datetime=bar.datetime,
                    gateway_name=bar.gateway_name,
                    open_price=bar.open_price,
                    high_price=bar.high_price,
                    low_price=bar.low_price
                )
            else:
                self.window_bar.high_price = max(
                    self.window_bar.high_price,
                    bar.high_price
                )
                self.window_bar.low_price = min(
                    self.window_bar.low_price,
                    bar.low_price
                )

                self.window_bar.close_price = bar.close_price
                self.window_bar.volume += int(bar.volume)
                self.window_bar.open_interest = bar.open_interest

            self.interval_count += 1
            if not self.interval_count % self.window:
                self.interval_count = 0
                self.on_window_bar(self.window_bar)
                self.window_bar = None
Member
avatar
加入于:
帖子: 126
声望: 14

先支持,再mark

Member
avatar
加入于:
帖子: 69
声望: 0

mark

Member
avatar
加入于:
帖子: 69
声望: 0

请查看收件箱,给你留言了

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】