def add_wave_prediction_data_to_wave_records(self, symbol='', ts_start=0, ts_end=0, scheduled_job=False): """ This job calculates the prediction data for all kind of waves (daily and intraday """ print('Add prediction data to wave records..') access_layer_wave = AccessLayer4Wave(self.db_stock) df_wave_to_process = access_layer_wave.get_wave_data_without_prediction_data( symbol, ts_start, ts_end) update_counter = 0 for wave_index, wave_row in df_wave_to_process.iterrows(): wave_entity = WaveEntity(wave_row) x_data = wave_entity.data_list_for_prediction_x_data prediction_dict = self.sys_config.fibonacci_predictor.get_prediction_as_dict( x_data) data_dict = {} FibonacciWave.update_dict_by_prediction_dict( prediction_dict, data_dict) access_layer_wave.update_record(wave_entity.row_id, data_dict) update_counter += 1 if scheduled_job: self.sys_config.file_log.log_scheduler_process( log_message='Updated: {}/{}'.format( update_counter, df_wave_to_process.shape[0]), process='Update wave records', process_step='add_wave_prediction')
def __plot_single_fibonacci_wave__(self, fib_wave: FibonacciWave, color: str, suffix: str = ''): if self.sys_config.config.fibonacci_detail_print: fib_wave.print(suffix) xy = fib_wave.get_xy_parameter() xy = PlotterInterface.get_xy_from_timestamp_to_date_number(xy) fib_polygon = Polygon(np.array(xy), closed=False, fill=False) fib_polygon.set_visible(True) fib_polygon.set_color(color) fib_polygon.set_linewidth(1) self.axes_for_candlesticks.add_patch(fib_polygon) fib_wave_patch = FibonacciWavePatch(fib_wave, fib_polygon) self.fibonacci_patch_container.add_patch(fib_wave_patch) fib_wave_patch.add_retracement_patch_list_to_axis(self.axes_for_candlesticks)
def add_predictions_to_wave(self, fib_wave: FibonacciWave, print_prediction=False): if not fib_wave.is_wave_ready_for_wave_table(): return data_dict = fib_wave.data_dict_obj.get_data_dict_for_target_table() data_dict_series = pd.Series(data_dict) wave_entity = WaveEntity(data_dict_series) x_data = wave_entity.data_list_for_prediction_x_data prediction_dict = self.get_prediction_as_dict(x_data) fib_wave.update_prediction_data_by_dict(prediction_dict) if print_prediction: fib_wave.print_predictions()
def __handle_forecasts__(self, wave: FibonacciWave): if len(wave.comp_forecast_parameter_list) > 0: for parameter in wave.comp_forecast_parameter_list: # [0.382, 207.46, 110] = fib, value, after_ticks value = parameter[1] position = self.position_last if parameter[ 2] > self.position_last else parameter[2] tick_forecast = self.__get_wave_tick_for_forecast__( wave, value, position) reg_comp = self.__get_regression_component__( wave, wave.w_4.tick_end, tick_forecast, 'w_5') wave.calculate_regression_values_for_component(reg_comp) if wave.can_regression_component_be_added(reg_comp): wave.add_regression(reg_comp) self.__process_forecast_wave__(wave) del wave.comp_dic[ 'w_5'] # we need this component for the next forecast wave wave.comp_forecast_parameter_list = [] # we are through...
def __add_next_ret_comp__(self, wave: FibonacciWave, ret_comp_id: str, tick_previous: WaveTick): possible_next_tick_list = self.__get_possible_next_tick_list__( tick_previous, wave, False) for tick_next in possible_next_tick_list: if wave.is_wave_ready_for_next_retracement(tick_next, ret_comp_id): ret_comp = self.__get_retracement_component__( wave, tick_previous, tick_next, ret_comp_id) wave.calculate_retracement_values_for_component(ret_comp) if wave.can_retracement_component_be_added(ret_comp): wave.add_retracement(ret_comp) if wave.is_wave_unfinished(self.position_last): self.fibonacci_unfinished_wave_list.append( wave.clone()) print('Forecast w_5-{} (position_last={}: {} -> {}'. format(wave.wave_type, self.position_last, wave.comp_position_list, wave.comp_forecast_parameter_list)) # Forecast w_5 (position_last=299: [[1.781, 3595.51, 337], [2.219, 3634.49, 348]] ret_comp_id_next = wave.reg_comp_id_next if ret_comp_id_next != '': self.__add_next_reg_comp__(wave, ret_comp_id_next, tick_next) self.__delete_component_from_dic__(wave, ret_comp_id)
def __add_next_reg_comp__(self, wave: FibonacciWave, reg_comp_id: str, tick_previous: WaveTick): possible_next_tick_list = self.__get_possible_next_tick_list__( tick_previous, wave, True) for tick_next in possible_next_tick_list: if wave.is_wave_ready_for_next_regression(tick_next, reg_comp_id): reg_comp = self.__get_regression_component__( wave, tick_previous, tick_next, reg_comp_id) wave.calculate_regression_values_for_component(reg_comp) if wave.can_regression_component_be_added(reg_comp): wave.add_regression(reg_comp) if wave.is_wave_complete(): self.__process_completed_wave__(wave) self.__delete_component_from_dic__(wave, reg_comp_id) self.__handle_forecasts__(wave) else: ret_comp_id_next = wave.ret_comp_id_next if ret_comp_id_next != '': self.__add_next_ret_comp__(wave, ret_comp_id_next, tick_next) self.__delete_component_from_dic__(wave, reg_comp_id)
def __process_forecast_wave__(self, wave: FibonacciWave): if wave.is_wave_fibonacci_wave(True): self.fibonacci_wave_forecast_collector.add_forecast_wave( wave.clone())
def __process_completed_wave__(self, wave: FibonacciWave): if wave.is_wave_fibonacci_wave(): wave_clone = wave.clone() self.__add_wave_after_check_to_list__(self.fibonacci_wave_list, wave_clone)
def get_fibonacci_wave_shape(sys_config: SystemConfiguration, fib_wave: FibonacciWave, color: str): x, y = DashInterface.get_xy_separated_from_timestamp( sys_config, fib_wave.get_xy_parameter()) return MyPolygonLineShape(x, y, color)