def test_continuous_count(self): arr1 = nparr([False, True, True, False, True, False]) assert numpy.array_equal( ArrayIndicator.consecutive_count_of_True(arr1), [0, 1, 2, 0, 1, 0]) arr1 = nparr([True, True, True, False, True, True]) assert numpy.array_equal( ArrayIndicator.consecutive_count_of_True(arr1), [1, 2, 3, 0, 1, 2])
def plot_df_with_min_max(df): fig, ax = plt.subplots() val = StockAxisPlot((fig, ax), df) is_min = ArrayIndicator.is_min_poses(df.low.values, 5) is_max = ArrayIndicator.is_max_poses(df.high.values, 5) pos_shift = (max(df.high) - min(df.low)) / 30 is_min_sr = df.low[is_min] is_max_sr = df.high[is_max] val.add_scatter_point('test', is_min_sr - pos_shift, color='b', marker='^') val.add_scatter_point('test', is_max_sr + pos_shift, color='b', marker='v') val.plot() plt.show()
def test_min_poses(self): arr = numpy.arange(4) arr[0] = 10 arr = numpy.concatenate((arr, arr[::-1])) max_arr = ArrayIndicator.is_max_poses(arr, 5) assert numpy.all( max_arr == [False, False, False, True, True, False, False, False])
def test_len_and_slope(self): arr1 = nparr([1, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4], dtype=numpy.float64) val2 = ArrayIndicator.trend_len_and_slope(arr1, window_len=5) assert numpy.array_equal(val2[0], [0, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 3]) assert numpy.allclose( val2[1], [0., 1., 0., -0.33333333, 1., 1., 1., -1., -1., 1., 1., 1.])
def test_even_count(self): val = ArrayIndicator.even_count(numpy.asarray([1, 1, 1, 0, 0])) numpy.array_equal(val, [0, 1, 2, 0, 1])
def test_drop_count(self): val = ArrayIndicator.rise_count(numpy.asarray([3, 2, 1, 2, 1])) numpy.array_equal(val, [0, 1, 2, 0, 1])
def test_mdd_poses(self): arr1 = nparr([1, 2, 1, 1.5, 0, 1, 2]) poses = ArrayIndicator.mdd_poses(arr1) assert poses == (1, 4)
def even_count_of_previous_days(df): arr = df.close.values is_even = (arr == np_shift(arr, 1, 0)) count = ArrayIndicator.consecutive_count_of_True(is_even) return np_shift(count, 1, 0)
def down_count_of_previous_days(df): arr = df.close.values is_up = arr - np_shift(arr, 1, 0) < 0 count = ArrayIndicator.consecutive_count_of_True(is_up) return np_shift(count, 1, 0)
def _support_high_low_strength(df, window_len): is_max = ArrayIndicator.is_max_poses(df.high, window_len) is_min = ArrayIndicator.is_min_poses(df.low, window_len) pass