def __calculate_values__(self):
     self.tick_list = [self.pdh.pattern_data.tick_list[k] for k in range(self.function_cont.position_first,
                                                                         self.function_cont.position_last + 1)]
     self.tick_first = self.tick_list[0]
     self.tick_last = self.tick_list[-1]
     self.tick_high = WaveTick(self.df.loc[self.df[CN.HIGH].idxmax(axis=0)])
     self.tick_low = WaveTick(self.df.loc[self.df[CN.LOW].idxmin(axis=0)])
     tick_breakout = self.function_cont.tick_for_breakout
     f_upper_first = self.function_cont.get_upper_value(self.tick_first.f_var, True)
     f_lower_first = self.function_cont.get_lower_value(self.tick_first.f_var, True)
     self.height_at_first_position = f_upper_first - f_lower_first
     if tick_breakout is None:
         f_upper_last = self.function_cont.get_upper_value(self.tick_last.f_var, True)
         f_lower_last = self.function_cont.get_lower_value(self.tick_last.f_var, True)
     else:
         f_upper_last = self.function_cont.get_upper_value(tick_breakout.f_var, True)
         f_lower_last = self.function_cont.get_lower_value(tick_breakout.f_var, True)
     self.height_at_last_position = f_upper_last - f_lower_last
     self.bound_upper = f_upper_last
     self.bound_lower = f_lower_last
     if self.pattern_type in [FT.TKE_BOTTOM, FT.TKE_TOP, FT.FIBONACCI_ASC, FT.FIBONACCI_DESC]:
         self.height = self.bound_upper - self.bound_lower
     else:
         self.distance_min = min(abs(f_upper_first - f_lower_first), abs(f_upper_last - f_lower_last))
         self.distance_max = max(abs(f_upper_first - f_lower_first), abs(f_upper_last - f_lower_last))
         self.height = (self.distance_min + self.distance_max) / 2
 def __init__(self, sys_config: SystemConfiguration, df: pd.DataFrame,
              f_lower: np.poly1d, f_upper: np.poly1d):
     self.sys_config = sys_config
     self.pdh = self.sys_config.pdh
     self.df = df
     self._tick_for_helper = None
     self._tick_for_breakout = None
     self._tick_first = WaveTick(self.df.iloc[0])
     self._tick_last = WaveTick(self.df.iloc[-1])
     self._df_part = self.df[np.logical_and(
         self.df[CN.POSITION] >= self.tick_first.position,
         self.df[CN.POSITION] <= self.tick_last.position)]
     self._slope_offset_value = self._df_part[CN.HIGH].mean()
     self._f_lower = f_lower
     self._f_upper = f_upper
     self._h_lower = f_lower
     self._h_upper = f_upper
     self._f_breakout = None
     self._forecast_f_breakout = None
     self._f_regression = self.__get_f_regression__()
     self._f_upper_percentage = 0
     self._f_lower_percentage = 0
     self._f_regression_percentage = 0
     self._f_var_cross_f_upper_f_lower = 0
     self._position_cross_f_upper_f_lower = 0
     self._max_positions_after_tick_for_helper = 0
     if self.is_valid():
         self.__init_tick_for_helper__()
         self.__set_f_var_cross_f_upper_f_lower__()
         self.__init_percentage_values__()
Esempio n. 3
0
 def get_slope(self, pos_start: int, pos_end: int, df_col: str = CN.CLOSE):
     df_part = self.df.iloc[pos_start:pos_end + 1]
     # print('get_slope: pos_start={}, pos_end={}, df_col={}, df_part.shape[0]={}'.format(
     #     pos_start, pos_end, df_col, df_part.shape[0]))
     tick_first = WaveTick(df_part.iloc[0])
     tick_last = WaveTick(df_part.iloc[-1])
     stock_df = PatternDataFrame(df_part)
     func = stock_df.get_f_regression(df_col)
     offset_value = df_part[df_col].mean()
     return MyMath.get_change_in_percentage(func(tick_first.f_var), func(tick_last.f_var), offset_value=offset_value)
 def __get_wave_tick_for_forecast__(self, wave: FibonacciWave, value: float,
                                    position: int):
     df = self.df_source[self.df_source[CN.POSITION] == position]
     row = deepcopy(df.iloc[0])
     row.High, row.Low, row.Open, row.Close = value, value, value, value
     tick = WaveTick(row)
     return tick
Esempio n. 5
0
 def __can_pattern_be_added_to_list_after_checking_next_ticks__(
         self, pattern: Pattern):
     tick_last = pattern.function_cont.tick_last
     pos_start = tick_last.position + 1
     number_of_positions = pattern.function_cont.number_of_positions
     counter = 0
     can_pattern_be_added = True
     for pos in range(pos_start, self.df_length):
         counter += 1
         next_tick = WaveTick(self.df.loc[pos])
         break_loop = self.__check_for_loop_break__(pattern, counter,
                                                    number_of_positions,
                                                    next_tick)
         if break_loop:
             can_pattern_be_added = False
             if pattern.breakout is None:  # we want to have the last tick before breakout
                 tick_last = next_tick
             break
         if pattern.breakout is None:
             pattern.function_cont.adjust_functions_when_required(next_tick)
             if pattern.function_cont.is_tick_breakout(
                     next_tick):  # online we have other checks... ToDo...
                 pattern_breakout = pattern.get_pattern_breakout(
                     tick_last, next_tick, False)
                 if pattern_breakout.is_breakout_a_signal(
                 ) or pattern_breakout.breakout_direction == FD.DESC:
                     pattern.function_cont.tick_for_breakout = next_tick
                     pattern.breakout = pattern_breakout
         if pattern.breakout is None:  # we want to have the last tick before breakout
             tick_last = next_tick
     pattern.function_cont.add_tick_from_main_df_to_df(self.df, tick_last)
     return can_pattern_be_added
 def __add_distance_columns__(self):
     self.tick_list = [WaveTick(rows) for ind, rows in self.df.iterrows()]
     for pos, high, before in itertools.product(range(0, self.df_length),
                                                (False, True),
                                                (False, True)):
         value = self.__get_distance__(pos, high, before)
         if high and before:
             self.df.loc[pos, CN.TICKS_BREAK_HIGH_BEFORE] = value
         elif high and not before:
             self.df.loc[pos, CN.TICKS_BREAK_HIGH_AFTER] = value
         elif not high and before:
             self.df.loc[pos, CN.TICKS_BREAK_LOW_BEFORE] = value
         elif not high and not before:
             self.df.loc[pos, CN.TICKS_BREAK_LOW_AFTER] = value
 def __get_linear_f_params__(self, tick_i: WaveTick,
                             tick_k: WaveTick) -> np.poly1d:
     return tick_i.get_linear_f_params_for_low(tick_k)
Esempio n. 8
0
 def get_parallel_to_function_by_high(self, func: np.poly1d) -> np.poly1d:
     pos = self.df[CN.HIGH].idxmax()
     tick = WaveTick(self.df.loc[pos])
     diff = func(tick.f_var) - tick.high
     return np.poly1d([func[1], func[0] - diff])
Esempio n. 9
0
 def get_parallel_to_function_by_low(self, func: np.poly1d) -> np.poly1d:
     pos = self.df[CN.LOW].idxmin()
     tick = WaveTick(self.df.loc[pos])
     diff = func(tick.f_var) - tick.low
     return np.poly1d([func[1], func[0] - diff])
Esempio n. 10
0
 def get_nearest_tick_to_f_var(self, f_var: int):
     df = self.df.assign(Distance=(abs(self.df.Timestamp - f_var)))
     df = df[df["Distance"] == df["Distance"].min()]
     return WaveTick(df.iloc[0])
Esempio n. 11
0
 def __init__(self, df: pd.DataFrame):
     self.df = df
     self.tick_first = WaveTick(self.df.iloc[0])
     self.tick_last = WaveTick(self.df.iloc[-1])
 def __set_buy_limits_to_wave_tick__(self, wave_tick: WaveTick):
     wave_tick.breakout_value = self._buy_limit_upper
     wave_tick.wrong_breakout_value = self._buy_limit_lower
 def __init_tick_for_helper__(self):
     pos = self.df[CN.LOW].idxmin(axis=0)
     tick = WaveTick(self.df.loc[pos])
     self.__set_tick_for_helper__(tick)
Esempio n. 14
0
 def __fill_tick_list__(self):
     for index, row in self.df.iterrows():
         self._tick_list.append(WaveTick(row))