def test_merge_down_2(self): k1 = KBar(0, "20181209", 0.4, 3, 3, 0.4, 1000, Level.L_DAY) k2 = KBar(1, "20181210", 0.5, 2.5, 2.5, 0.5, 1000, Level.L_DAY) k3 = k1.merge(k2, Direction.DOWN) assert (k3.isMerged()) assert (k3.top == k2.top and k3.bottom == k1.bottom) assert (k3.no == k1.no and k3.time == k1.time)
def test_merge_up_4(self): k1 = KBar(0, "20181209", 0.4, 3, 3, 0.4, 1000, Level.L_DAY) k2 = KBar(1, "20181210", 0.5, 2.5, 2.5, 0.5, 1000, Level.L_DAY) k3 = KBar(2, "20181211", 0.3, 4, 4, 0.3, 1000, Level.L_DAY) k4 = k1.merge(k2, Direction.UP).merge(k3, Direction.UP) assert (k4.isMerged()) assert (k4.top == k3.top and k4.bottom == k2.bottom) assert (k4.no == k3.no and k4.time == k3.time)
def test_merge_down_3(self): k1 = KBar(0, "20181209", 0.4, 3, 3, 0.4, 1000, Level.L_DAY) k2 = KBar(1, "20181210", 0.5, 2.5, 2.5, 0.5, 1000, Level.L_DAY) k3 = KBar(2, "20181211", 0.6, 2.3, 2.3, 0.6, 1000, Level.L_DAY) k4 = k1.merge(k2, Direction.DOWN).merge(k3, Direction.DOWN) assert (k4.isMerged()) assert (k4.top == k3.top and k4.bottom == k1.bottom) assert (k4.no == k1.no and k4.time == k1.time)
def test_first_stroke_rise_broken_2(self): kseries = [ KBar(0, "20181209", 1, 3, 3, 1, 1000, Level.L_DAY), KBar(1, "20181210", 2, 4, 4, 2, 1000, Level.L_DAY), KBar(2, "20181211", 3, 5, 5, 3, 1000, Level.L_DAY), KBar(3, "20181212", 4, 6, 6, 4, 1000, Level.L_DAY), KBar(4, "20181213", 5, 7, 7, 5, 1000, Level.L_DAY), KBar(5, "20181214", 8, 0.8, 8, 0.8, 1000, Level.L_DAY), KBar(6, "20181215", 3, 0.7, 3, 0.7, 1000, Level.L_DAY), KBar(7, "20181216", 2, 0.6, 2, 0.6, 1000, Level.L_DAY), KBar(8, "20181217", 1, 0.5, 1, 0.5, 1000, Level.L_DAY), KBar(9, "20181218", 0.6, 2, 2, 0.6, 1000, Level.L_DAY) ] strokes = Stroke.split_stroke(kseries) assert (len(strokes) == 0)
def test_first_stroke_rise_broken(self): kseries = [ KBar(0, "20181209", 1, 3, 3, 1, 1000, Level.L_DAY), KBar(1, "20181210", 2, 4, 4, 2, 1000, Level.L_DAY), KBar(2, "20181211", 3, 5, 5, 3, 1000, Level.L_DAY), KBar(3, "20181212", 4, 6, 6, 4, 1000, Level.L_DAY), KBar(4, "20181213", 5, 7, 7, 5, 1000, Level.L_DAY), KBar(5, "20181214", 4, 0.8, 4, 0.8, 1000, Level.L_DAY), KBar(6, "20181215", 3, 0.7, 3, 0.7, 1000, Level.L_DAY), KBar(7, "20181216", 2, 0.6, 2, 0.6, 1000, Level.L_DAY), KBar(8, "20181217", 1, 0.5, 1, 0.5, 1000, Level.L_DAY), KBar(9, "20181218", 0.6, 2, 2, 0.6, 1000, Level.L_DAY) ] strokes = Stroke.split_stroke(kseries) assert (strokes and len(strokes) == 1 and strokes[0].direction == Direction.DOWN) assert (strokes[0].k_from.no == 4 and strokes[0].k_to.no == 8) assert (strokes[0].lowest == 0.5 and strokes[0].highest == 7)
def test_first_stroke_rise_leftinclusion(self): kseries = [ KBar(0, "20181209", 1, 3, 3, 1, 1000, Level.L_DAY), KBar(1, "20181210", 2, 4, 4, 2, 1000, Level.L_DAY), KBar(2, "20181211", 3, 5, 5, 3, 1000, Level.L_DAY), KBar(3, "20181212", 4, 6, 6, 4, 1000, Level.L_DAY), KBar(4, "20181213", 5, 7, 7, 5, 1000, Level.L_DAY), KBar(5, "20181214", 5.5, 6, 6, 5.5, 1000, Level.L_DAY), KBar(6, "20181215", 3, 5, 5, 3, 1000, Level.L_DAY) ] strokes = Stroke.split_stroke(kseries) assert (len(strokes) == 1 and strokes[0].direction == Direction.UP) assert (strokes[0].k_from.no == 0 and strokes[0].k_to.no == 4) assert (strokes[0].lowest == 1 and strokes[0].highest == 7) assert (strokes[0].kseries[-1].bottom == 5.5)
def test_first_stroke_strait_fall(self): kseries = [ KBar(0, "20181209", 7, 5, 7, 5, 1000, Level.L_DAY), KBar(1, "20181210", 6, 4, 6, 4, 1000, Level.L_DAY), KBar(2, "20181211", 5, 3, 5, 3, 1000, Level.L_DAY), KBar(3, "20181212", 4, 2, 4, 2, 1000, Level.L_DAY), KBar(4, "20181213", 3, 1, 3, 1, 1000, Level.L_DAY), KBar(5, "20181214", 4, 2, 4, 2, 1000, Level.L_DAY) ] strokes = Stroke.split_stroke(kseries) assert (strokes and len(strokes) == 1 and strokes[0].direction == Direction.DOWN) assert (strokes[0].k_from.no == 0 and strokes[0].k_to.no == 4) assert (strokes[0].lowest == 1 and strokes[0].highest == 7)
def test_inclued_by(self): k1 = KBar(0, "20181209", 1, 2, 2.5, 0.5, 1000, Level.L_DAY) k2 = KBar(1, "20181210", 0.4, 4, 4, 0.4, 1000, Level.L_DAY) assert (k1.includedBy(k2)) assert (not k2.includedBy(k1)) assert (k1.inclusion(k2) and k2.inclusion(k1))
def test_merge_0(self): k1 = KBar(0, "20181209", 0.5, 2.5, 2.5, 0.5, 1000, Level.L_DAY) assert (not k1.isMerged())
def test_rise_and_fall(self): k1 = KBar(0, "20181209", 0.5, 2.5, 2.5, 0.5, 1000, Level.L_DAY) k2 = KBar(1, "20181210", 1, 3, 3, 1, 1000, Level.L_DAY) assert (k1.rise(k2)) assert (k2.fall(k1))
def test_create(self): kseries = [KBar(0, "20181209", 1, 2, 2.5, 0.5, 1000, Level.L_DAY)]