def __simulate_trading__(self, detector: PatternDetector):
     pattern_list = detector.get_pattern_list_for_back_testing()
     for pattern in pattern_list:
         # we need for each pattern a new pattern trade handler...
         detector.trade_handler = PatternTradeHandler(self.sys_config)
         detector.trade_handler.add_pattern_list_for_trade([pattern])
         detector.trade_handler.simulate_trading_for_one_pattern(pattern)
    def __handle_statistics__(self, detector: PatternDetector):
        for pattern in detector.pattern_list:
            self.pattern_statistics.add_entry(pattern)

        if self.sys_config.config.show_final_statistics:
            self.detector_statistics.add_entry(detector.get_statistics_api())
        else:
            detector.print_statistics()
 def get_detector_for_pattern_id(sys_config: SystemConfiguration,
                                 pattern_id_str: str) -> PatternDetector:
     sys_config.init_by_pattern_id_str(pattern_id_str)
     ticker = sys_config.runtime_config.actual_ticker
     and_clause = sys_config.runtime_config.actual_and_clause
     print('\nDetector_for_pattern_id - processing {} ({}) for {} ...\n'.
           format(ticker, sys_config.runtime_config.actual_ticker_name,
                  and_clause))
     sys_config.init_pattern_data_handler_for_ticker_id(
         ticker, and_clause, 200)
     sys_config.init_predictors_without_condition_list()
     detector = PatternDetector(sys_config)
     detector.parse_for_pattern()
     return detector
 def get_detector_for_fibonacci(sys_config: SystemConfiguration,
                                ticker: str,
                                and_clause='',
                                limit=300,
                                offset: int = 0) -> PatternDetector:
     print('\nProcessing for Fibonacci: {} ({})\n'.format(
         ticker, sys_config.runtime_config.actual_ticker_name))
     sys_config.init_pattern_data_handler_for_ticker_id(ticker,
                                                        and_clause,
                                                        limit,
                                                        offset=offset)
     detector = PatternDetector(sys_config)
     detector.parse_for_fibonacci_waves()
     return detector
 def get_detector_for_dash(sys_config: SystemConfiguration,
                           ticker: str,
                           and_clause='',
                           limit=300) -> PatternDetector:
     sys_config.init_pattern_data_handler_for_ticker_id(
         ticker, and_clause, limit)
     print('\nProcessing {} ({}){}...\n'.format(
         ticker, sys_config.runtime_config.actual_ticker_name,
         '' if and_clause == '' else ' for {}'.format(and_clause)))
     sys_config.init_predictors_without_condition_list()
     detector = PatternDetector(sys_config)
     detector.parse_for_fibonacci_waves()
     detector.add_prediction_data_to_wave()
     detector.parse_for_pattern()
     detector.save_pattern_data()
     return detector
 def get_detector_for_bollinger_band(sys_config: SystemConfiguration,
                                     ticker: str,
                                     and_clause='',
                                     limit=300) -> PatternDetector:
     sys_config.init_pattern_data_handler_for_ticker_id(
         ticker, and_clause, limit)
     print('\nProcessing for Bollinger Band: {} ({})\n'.format(
         ticker, sys_config.runtime_config.actual_ticker_name))
     detector = PatternDetector(sys_config)
     return detector
 def get_detector_for_fibonacci_and_pattern(sys_config: SystemConfiguration,
                                            ticker: str,
                                            and_clause='',
                                            limit=300) -> PatternDetector:
     sys_config.init_pattern_data_handler_for_ticker_id(
         ticker, and_clause, limit)
     sys_config.config.pattern_type_list = FT.get_all()
     sys_config.init_predictors_without_condition_list()
     # sys_config.config.save_wave_data
     print('\nProcessing for Fib & Pattern: {} ({})\n'.format(
         ticker, sys_config.runtime_config.actual_ticker_name))
     detector = PatternDetector(sys_config)
     detector.parse_for_fibonacci_waves()
     detector.add_prediction_data_to_wave()
     detector.parse_for_pattern()
     return detector
 def __run_pattern_detector__(self):
     self.sys_config.data_provider.init_and_clause()
     self.__init_loop_list_for_ticker__()
     limit = self.sys_config.data_provider.limit
     self.sys_config.fibonacci_wave_data_handler.load_data(
         self.period, self.period_aggregation)
     for value_dic in self._loop_list_ticker.value_list:
         ticker = value_dic[LL.TICKER]
         and_clause = value_dic[LL.AND_CLAUSE]
         self.sys_config.init_pattern_data_handler_for_ticker_id(
             ticker, and_clause, limit=limit)
         if self.sys_config.pdh is None:
             print('No data available for: {} and {}'.format(
                 ticker, and_clause))
             continue
         print('\nProcessing {} ({})...\n'.format(
             ticker, self.sys_config.runtime_config.actual_ticker_name))
         self.sys_config.init_predictors_without_condition_list()
         detector = PatternDetector(self.sys_config)
         detector.parse_for_fibonacci_waves()
         detector.add_prediction_data_to_wave()
         detector.save_wave_data()
         detector.parse_for_pattern()
         bollinger_bound_break_direction = detector.pdh.get_bollinger_band_boundary_break_direction(
         )
         if bollinger_bound_break_direction != '':
             print('Caution: Bollinger Band {} broken'.format(
                 bollinger_bound_break_direction))
         if self.sys_config.config.detection_process == PDP.UPDATE_TRADE_DATA:
             if len(detector.pattern_list) == 0:
                 self.__delete_pattern_without_actual_pattern_from_database__(
                 )
             else:
                 self.__simulate_trading__(detector)
         else:
             # self.check_for_optimal_trading_strategy(detector)  # ToDo error with deepcopy in the called module
             detector.check_for_intersections_and_endings()
             detector.save_pattern_data()
             if self.sys_config.config.with_trading:
                 self.__simulate_trading__(detector)
             self.__handle_statistics__(detector)
             self._number_pattern_total += len(detector.pattern_list)
             if self.sys_config.config.plot_data:
                 if len(
                         detector.pattern_list
                 ) == 0 and False:  # and not detector.possible_pattern_ranges_available:
                     print('...no formations found.')
                 else:
                     plotter = PatternPlotter(self.sys_config, detector)
                     plotter.plot_data_frame()
             elif self.sys_config.period == PRD.INTRADAY:
                 sleep(15)