VeighNa量化社区
你的开源社区量化交易平台 | vn.py | vnpy
Member
avatar
加入于:
帖子: 4
声望: 0

不是新的一分钟的情况下,更新K线的最高价和最低价,代码如下:

        self.bar.high_price = max(self.bar.high_price, tick.last_price)
        if tick.high_price > self.last_tick.high_price:
            self.bar.high_price = max(self.bar.high_price, tick.high_price)

        self.bar.low_price = min(self.bar.low_price, tick.last_price)
        if tick.low_price < self.last_tick.low_price:
            self.bar.low_price = min(self.bar.low_price, tick.low_price)

疑问:
为什么要先与tick.last_price比较一下,然后再在价格走高/走低的条件下再与tick.high_price/tick.low_price进行比较?
将代码更改如下:

       self.bar.high_price = max(self.bar.high_price, tick.high_price)
       self.bar.low_price = min(self.bar.low_price, tick.low_price)

与原代码有什么区别?

Member
avatar
加入于:
帖子: 5434
声望: 329

tick.high_price是涨停价,有时候不包含在500毫秒一个的切片tick的last_price里,在更高频的行情里

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

tick.high_price不是最高价吗?

xiaohe wrote:

tick.high_price是涨停价,有时候不包含在500毫秒一个的切片tick的last_price里,在更高频的行情里

Member
avatar
加入于:
帖子: 1841
声望: 140

于凯 wrote:

tick.high_price不是最高价吗?

xiaohe wrote:

tick.high_price是涨停价,有时候不包含在500毫秒一个的切片tick的last_price里,在更高频的行情里

楼上应该写错了,tick.high_price是当日日内出现过的最高价,有时会在两个tick.last_price之间出现(也就是无法反映在last_price中),所以合成Bar的时候需要做下特殊处理判断。

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

沪公网安备 31011502017034号

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