def fill_wave_type_number_dict_for_ticks_in_wave_tick_list(
         self, wave_tick_list: WaveTickList, index: str, period: str):
     for wave_peak_date_type in WPDT.get_types_for_period(
             period, self._aggregation):
         self._fibonacci_wave_data_dict[wave_peak_date_type].\
             fill_wave_type_number_dict_for_ticks_in_wave_tick_list(wave_tick_list, index)
     wave_tick_list.fill_wave_type_number_dicts(
     )  # we need some min max values for the wave numbers
 def fill_wave_type_number_dict_for_ticks_in_wave_tick_list(
         self, wave_tick_list: WaveTickList, index: str, period: str):
     for wave_type in self._wave_types:
         key = '{}_{}'.format(index, wave_type)
         index_wave_type_number_dict = self.__get_index_wave_type_number_dict_for_period__(period)
         if key in index_wave_type_number_dict:
             number_dict = index_wave_type_number_dict[key]
             for wave_tick in wave_tick_list.tick_list:
                 wave_tick_key = wave_tick.time_stamp if period == PRD.INTRADAY else wave_tick.date_str
                 if wave_tick_key in number_dict:
                     number = number_dict[wave_tick_key]
                     if number > 0:
                         wave_tick.add_to_wave_type_number_dict(wave_type, number)
     wave_tick_list.fill_wave_type_number_dicts()  # we need some min max values for the wave numbers
 def __plot_wave_peaks__(self):
     index = self.sys_config.index_config.get_index_for_symbol(self.symbol)
     period = self.sys_config.period
     aggregation = self.sys_config.period_aggregation
     wave_tick_list = WaveTickList(self.pdh.pattern_data.df)
     wave_data_handler = self.sys_config.fibonacci_wave_data_handler
     wave_data_handler.fill_wave_type_number_dict_for_ticks_in_wave_tick_list(wave_tick_list, index, period)
     for tick in wave_tick_list.tick_list:
         for wave_type in WAVEST.get_waves_types_for_processing([period]):
             color = wave_data_handler.get_color_for_wave_type_and_period(wave_type, period)
             # if tick.date_str == '2019-03-07':
             #     print(color)
             number_waves = tick.get_wave_number_for_wave_type(wave_type)
             if number_waves >= 1:  # thresholds were calculated in a pre-process
                 xy = wave_tick_list.get_xy_parameters_for_wave_peak(tick, wave_type, period, aggregation)
                 self.__add_xy_values_as_polygon__(xy, color, closed=True, fill=False, alpha=1, line_width=1)
 def __init__(self, config: PatternConfiguration, df: pd.DataFrame):
     self.config = config
     self.__length_for_global = self.config.length_for_global_min_max
     self.__length_for_local = self.config.length_for_local_min_max
     self.df = self.__get_adjusted_df_for_wave_simulation__(df)
     self.df_length = self.df.shape[0]
     self.max_value = self.df[CN.HIGH].max()
     self.min_value = self.df[CN.LOW].min()
     self.height = self.max_value - self.min_value
     self.__add_columns__()
     self.__init_columns_for_ticks_distance__()
     self.df_min_max = self.df[np.logical_or(self.df[CN.IS_MIN],
                                             self.df[CN.IS_MAX])]
     self.tick_by_date_num_ext_dic = ExtendedDictionary4WaveTicks(self.df)
     self.tick_list = [
         self.tick_by_date_num_ext_dic.dic[index]
         for index in self.tick_by_date_num_ext_dic.index
     ]
     self.tick_first = self.tick_list[0]
     self.tick_last = self.tick_list[-1]
     self.tick_f_var_distance = self.__get_tick_f_var_distance__()
     self.wave_tick_list_min_max = WaveTickList(self.df_min_max)
     self.tick_list_min = []
     self.tick_list_max = []
     self.__fill_tick_list_min_max__()
     self.tick_list_min_without_hidden_ticks = self.__get_hidden_tick_list__(
         self.tick_list_min, False)
     self.tick_list_max_without_hidden_ticks = self.__get_hidden_tick_list__(
         self.tick_list_max, True)
     self.tick_list_min_max_for_head_shoulder = self.__get_tick_list_min_max_for_head_shoulder__(
     )
 def get_wave_tick_list_for_time_stamp_interval(self, symbol: str,
                                                ts_from: int, ts_to: int):
     df = self.select_data_by_query(
         "SELECT * from {} WHERE symbol = '{}' AND {} BETWEEN {} and {} ORDER BY {}"
         .format(self._table.name, symbol, DC.TIMESTAMP, ts_from, ts_to,
                 DC.TIMESTAMP))
     return WaveTickList(df)
 def get_latest_tickers_as_wave_tick_list(self,
                                          symbol: str,
                                          period: str,
                                          aggregation: int,
                                          limit=2) -> WaveTickList:
     df = self.get_candles(symbol, period, aggregation, 'hist', limit)
     df[CN.TIMESTAMP] = df.index
     df[CN.POSITION] = 0
     return WaveTickList(df)
 def fill_wave_type_number_dict_for_ticks_in_wave_tick_list(
         self, wave_tick_list: WaveTickList, index: str):
     for wave_type in self._wave_types:
         key = '{}_{}'.format(index, wave_type)
         if key in self._index_wave_type_number_dict and len(
                 self._index_wave_type_number_dict[key]) > 0:
             number_dict = self._index_wave_type_number_dict[key]
             threshold = self.__get_threshold_for_index_and_wave_type_number_dict__(
                 number_dict)
             for wave_tick in wave_tick_list.tick_list:
                 wave_tick_key = self.__get_wave_tick_key_for_number_dict__(
                     wave_tick)
                 if wave_tick_key in number_dict:
                     number = number_dict[wave_tick_key]
                     if number > threshold:
                         wave_tick.add_to_wave_type_number_dict(
                             wave_type, number)
     wave_tick_list.fill_wave_type_number_dicts(
     )  # we need some min max values for the wave numbers
 def get_wave_peak_shape(sys_config: SystemConfiguration,
                         wave_tick_list: WaveTickList, wave_tick: WaveTick,
                         wave_type: str, color: str):
     # x, y, r = wave_tick_list.get_circle_shape_parameters_for_wave_peak(wave_tick, wave_type)
     # print('get_wave_peak_shape: x={}, y={}, r={}'.format(x, y, r))
     # return MyCircleShape(x, y, r, color)
     period = sys_config.period
     aggregation = sys_config.period_aggregation
     x, y = DashInterface.get_xy_separated_from_timestamp(
         sys_config,
         wave_tick_list.get_xy_parameters_for_wave_peak(
             wave_tick, wave_type, period, aggregation))
     return MyPolygonLineShape(x, y, color)
 def __plot_min_max__(self):
     wave_tick_list = WaveTickList(self.pdh.pattern_data.df_min_max)
     width, height = PlotterInterface.get_ellipse_width_height_for_plot_min_max(self.sys_config, wave_tick_list)
     for ticks in wave_tick_list.tick_list:
         x = MyDate.get_date_as_number_from_epoch_seconds(ticks.f_var)
         if ticks.is_min:
             self.axes_for_candlesticks.add_patch(Ellipse((x, ticks.low), width, height, color='r'))
         else:
             self.axes_for_candlesticks.add_patch(Ellipse((x, ticks.high), width, height, color='g'))
     # fill some ellipses with color white
     width, height =  width/2, height/2
     for ticks in self.pdh.pattern_data.tick_list_min_without_hidden_ticks:
         self.axes_for_candlesticks.add_patch(Ellipse((ticks.f_var, ticks.low), width, height, color='w'))
     for ticks in self.pdh.pattern_data.tick_list_max_without_hidden_ticks:
         self.axes_for_candlesticks.add_patch(Ellipse((ticks.f_var, ticks.high), width, height, color='w'))
 def get_wave_tick_lists_for_time_stamp_intervals(self, symbol: str,
                                                  ts_list: list) -> list:
     # this is used for a faster access to several consequetive timestames (before_pattern, pattern, after_pattern)
     wave_tick_list_return = []
     ts_from = ts_list[0]
     ts_to = ts_list[-1]
     df = self.select_data_by_query(
         "SELECT * from {} WHERE symbol = '{}' AND {} BETWEEN {} and {} ORDER BY {}"
         .format(self._table.name, symbol, DC.TIMESTAMP, ts_from, ts_to,
                 DC.TIMESTAMP))
     for k in range(0, len(ts_list) - 1):
         df_part = df[np.logical_and(df[DC.TIMESTAMP] >= ts_list[k],
                                     df[DC.TIMESTAMP] < ts_list[k + 1])]
         wave_tick_list_return.append(WaveTickList(df_part))
     return wave_tick_list_return
 def __get_wave_peak_shape_list__(self, detector: PatternDetector):
     return_list = []
     symbol = detector.sys_config.runtime_config.actual_ticker
     index = detector.sys_config.index_config.get_index_for_symbol(symbol)
     period = detector.sys_config.period
     # print('__get_wave_peak_shape_list__: symbol={}, index={}'.format(symbol, index))
     wave_tick_list = WaveTickList(detector.pdh.pattern_data.df)
     self._fibonacci_wave_data_handler.fill_wave_type_number_dict_for_ticks_in_wave_tick_list(
         wave_tick_list, index, period)
     for tick in wave_tick_list.tick_list:
         for wave_type in WAVEST.get_waves_types_for_processing([PRD.DAILY
                                                                 ]):
             number_waves = tick.get_wave_number_for_wave_type(wave_type)
             if number_waves >= 1:  # in the pre-process we have already used thresholds
                 color = self._fibonacci_wave_data_handler.get_color_for_wave_type_and_period(
                     wave_type, period)
                 shape = DashInterface.get_wave_peak_shape(
                     detector.sys_config, wave_tick_list, tick, wave_type,
                     color)
                 if shape is not None:
                     return_list.append(shape)
     return return_list
Ejemplo n.º 12
0
 def __fill_f_param_list__(self):
     wave_tick_list = WaveTickList(
         self.df_min_max_final[self.df_min_max_final[CN.IS_MAX]])
     self._f_param_list = wave_tick_list.get_boundary_f_param_list(
         self.f_param, True)
 def __get_hidden_tick_list__(input_list: list, for_high: bool):
     wave_tick_list = WaveTickList(input_list)
     return wave_tick_list.get_list_without_hidden_ticks(for_high, 0.03)