这是一个滑动窗口的计算问题。我们使用高阶函数moving来解决问题。对于每一个窗口的处理,写一个自定义函数rangeTest来处理,返回true或false。
def rangeTest(close, downlimit, uplimit){
size = close.size() - 1
return between(close.subarray(0, size), downlimit.last() : uplimit.last()).sum() >= size*0.75
}
update t set signal = moving(rangeTest, [close, downAvgPrice, upAvgPrice], 21)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…