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 __get_pattern_type_pos_neg_result_relation_as_dict__(self): pattern_type_pos_neg_relation_dict = {} for pattern_type in FT.get_all(): pattern_type_pos_neg_relation_dict[pattern_type] = 1 # default df_pos = self.df_trades.loc[np.logical_and( self.df_trades[DC.PATTERN_TYPE] == pattern_type, self.df_trades[DC.TRADE_RESULT_PCT] > 1)] df_neg = self.df_trades.loc[np.logical_and( self.df_trades[DC.PATTERN_TYPE] == pattern_type, self.df_trades[DC.TRADE_RESULT_PCT] < -1)] if df_neg.shape[0] < 10: # not enough data if df_pos.shape[0] > 20: pattern_type_pos_neg_relation_dict[pattern_type] = 3 else: pattern_type_pos_neg_relation_dict[pattern_type] = round( df_pos.shape[0] / df_neg.shape[0], 1) return pattern_type_pos_neg_relation_dict
def init_detection_process_for_automated_pattern_update(self): date_now = MyDate.get_date_from_datetime() date_from = MyDate.adjust_by_days(date_now, -180) self.data_provider.and_clause = "Date BETWEEN '{}' AND '{}'".format( str(date_from), str(date_now)) self.data_provider.from_db = True self.data_provider.period = PRD.DAILY self.config.pattern_type_list = FT.get_all() self.config.detection_process = PDP.UPDATE_PATTERN_DATA self.config.plot_data = False self.config.with_trading = False self.config.save_pattern_data = True self.config.save_trade_data = False self.config.save_wave_data = False self.config.plot_only_pattern_with_fibonacci_waves = False self.config.plot_min_max = False self.config.plot_volume = False self.config.length_for_local_min_max = 2 self.config.length_for_local_min_max_fibonacci = 1 self.config.bound_upper_value = CN.CLOSE self.config.bound_lower_value = CN.CLOSE
def __get_length_pattern_type__(self) -> int: pattern_to_check = '{}_{}'.format( self._components_underscore[self._idx_pattern], self._components_underscore[self._idx_pattern + 1]) return 2 if pattern_to_check in FT.get_all() else 1
def get_constraints_as_dict(sys_config: SystemConfiguration): return_dict = {} for pattern_type in FT.get_all(): return_dict[pattern_type] = ConstraintsFactory.get_constraints_by_pattern_type(pattern_type, sys_config) return return_dict
sys_config.exchange_config.deactivate_automatic_trading() sys_config.exchange_config.trade_strategy_dict = { BT.BREAKOUT: [ TSTR.LIMIT, TSTR.LIMIT_FIX, TSTR.TRAILING_STEPPED_STOP, TSTR.TRAILING_STOP ], # BT.FC_TICKS: [TSTR.TRAILING_STOP] } sys_config.exchange_config.delete_vanished_patterns_from_trade_dict = False sys_config.exchange_config.massive_breakout_pct = 5 sys_config.config.simple_moving_average_number = 20 sys_config.config.trading_last_price_mean_aggregation = 4 # debugger.pattern_range_position_list = [217, 224, 242] sys_config.config.pattern_type_list = FT.get_all() sys_config.config.with_trading = True sys_config.config.save_pattern_data = True sys_config.config.save_trade_data = True sys_config.config.save_wave_data = False # they are saved within other threads # sys_config.config.pattern_type_list = [FT.TRIANGLE] sys_config.config.pattern_type_list = FT.get_all() sys_config.config.plot_data = True sys_config.config.plot_only_pattern_with_fibonacci_waves = False sys_config.config.plot_min_max = True sys_config.config.plot_volume = False sys_config.config.length_for_local_min_max = 2 sys_config.config.length_for_local_min_max_fibonacci = 1 sys_config.config.statistics_excel_file_name = 'pattern_statistics/statistics_pattern_06-11.xlsx' sys_config.config.statistics_excel_file_name = '' sys_config.config.statistics_constraints_excel_file_name = ''
Pattern: feature_columns=Ticks_Till_Pattern_Formed,Slope_Upper_PCT,Slope_Lower_PCT,Slope_Regression_PCT,Slope_Volume_Regression_PCT,Previous_Period_Half_Top_Out_PCT,Previous_Period_Full_Top_Out_PCT,Previous_Period_Half_Bottom_Out_PCT,Previous_Period_Full_Bottom_Out_PCT,Available_Fibonacci_Type_ID label_columns=Touch_Points_Till_Breakout_Top,Touch_Points_Till_Breakout_Bottom 26,-2.0,-1.0,-1.0,-190.0,0.0,0.0,40.0,70.0,0 20,-1.0,-1.0,-1.0,10.0,50.0,50.0,0.0,20.0,0 """ from pattern_predictor_optimizer import PatternPredictorOptimizer from pattern_system_configuration import SystemConfiguration from sertl_analytics.constants.pattern_constants import FT, PRED, STBL, MT, DC sys_config = SystemConfiguration() master_predictor_list = [ sys_config.master_predictor_for_trades, sys_config.master_predictor_touch_points, sys_config.master_predictor_before_breakout, sys_config.master_predictor_after_breakout ] for master_predictor in master_predictor_list: patter_type_list = FT.get_all() for pattern_type in patter_type_list: print('Processing: {} - {}'.format(master_predictor.__class__.__name__, pattern_type)) feature_columns = master_predictor.get_feature_columns(pattern_type) x_data = [1 for col in feature_columns] prediction_dict = master_predictor.predict_for_label_columns( pattern_type, x_data) print('{}: {}'.format(pattern_type, prediction_dict))