Exemplo n.º 1
0
 def __get_chart_type_area_winner_loser__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self._chart_name, 'winner & loser'))
     graph_api.figure_data = self.__get_area_winner_loser_figure_data__()
     graph_api.figure_layout_x_axis_dict = None  # dict(type='date',)
     graph_api.figure_layout_y_axis_dict = None  # dict(type='linear', range=[1, 100], dtick=20, ticksuffix='%')
     # graph_api.figure_layout_y_axis_dict = {'type': 'log', 'autorange': True}
     return [MyDCC.graph(graph_api)]
 def __get_chart_type_heatmap__(self):
     graph_list = []
     if self._index in ['', INDICES.ALL]:
         index_list = [
             INDICES.CRYPTO_CCY, INDICES.DOW_JONES, INDICES.NASDAQ100,
             INDICES.Q_FSE
         ]
         # ToDo Check if Q_FSE works...
     else:
         index_list = [self._index]
     for index in index_list:
         index_for_key = index.replace(' ', '_').lower()
         index_for_key = index_for_key if self._index == '' else '{}_{}'.format(
             index_for_key, 'single')
         chart_id = '{}_{}'.format(self._chart_id, index_for_key)
         # print('__get_chart_type_heatmap__: chart_id={}'.format(chart_id))
         chart_name = index
         graph_api = DccGraphApi(chart_id, chart_name)
         graph_api.figure_data = self.__get_heatmap_figure_data__(index)
         graph_api.figure_layout_height = 200
         graph_api.figure_layout_margin = {
             'b': 50,
             'r': 50,
             'l': 50,
             't': 50
         }
         graph_list.append(MyDCC.graph(graph_api))
     return graph_list
Exemplo n.º 3
0
 def __get_chart_type_stack_group__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self._chart_name, 'Assets'))
     graph_api.figure_data = self.__get_stack_group_figure_data__()
     # print(graph_api.figure_data)
     graph_api.figure_layout_x_axis_dict = self.__get_figure_layout_x_axis_dict__()
     graph_api.figure_layout_y_axis_dict = self.__get_figure_layout_y_axis_dict__(graph_api)
     return [MyDCC.graph(graph_api)]
 def __get_dcc_graph_element__(self, detector, graph_api: DccGraphApi):
     pattern_df = graph_api.df
     pattern_list = detector.pattern_list if detector else [
         graph_api.pattern_trade.pattern
     ]
     # print('Pattern_list={}'.format(pattern_list))
     period = detector.sys_config.period if detector else graph_api.period
     # print('_period={} from detector:{}'.format(_period, detector is None))
     candlestick = self.__get_candlesticks_trace__(pattern_df,
                                                   graph_api.ticker_id,
                                                   period)
     # print(candlestick)
     shapes = self.__get_pattern_shape_list__(pattern_list)
     shapes += self.__get_pattern_regression_shape_list__(pattern_list)
     if detector:
         shapes += self.__get_fibonacci_shape_list__(detector)
         shapes += self.__get_wave_peak_shape_list__(detector)
     if graph_api.pattern_trade:
         # graph_api.pattern_trade.ticker_actual.print_ticker('__get_pattern_trade_shape_list__...: last ticker')
         shapes += self.__get_pattern_trade_shape_list__(
             graph_api.pattern_trade)
     if (graph_api.indicator == INDI.BOLLINGER
             or True) and detector is not None:
         indicator_shape_list = self.__get_indicator_shape_list__(
             detector, graph_api.indicator)
         shapes += indicator_shape_list
     graph_api.figure_layout_shapes = [
         my_shapes.shape_parameters for my_shapes in shapes
     ]
     # print(' graph_api.figure_layout_shapes: {}'.format( graph_api.figure_layout_shapes))
     graph_api.figure_layout_annotations = [
         my_shapes.annotation_parameters for my_shapes in shapes
     ]
     graph_api.figure_data = [candlestick]
     return MyDCC.graph(graph_api)
    def __get_graph__(self,
                      ticker_id: str,
                      refresh_interval: int,
                      limit: int = 0):
        period = self.sys_config.period
        aggregation = self.sys_config.period_aggregation
        graph_cache_id = self.sys_config.graph_cache.get_cache_id(
            ticker_id, period, aggregation, limit)
        graph = self.sys_config.graph_cache.get_cached_object_by_key(
            graph_cache_id)
        if graph is not None:
            return graph, graph_cache_id

        if period == PRD.DAILY and self._recommender_table.selected_index != INDICES.CRYPTO_CCY:
            self.sys_config.data_provider.from_db = True
        else:
            self.sys_config.data_provider.from_db = False
        date_start = MyDate.adjust_by_days(MyDate.get_datetime_object().date(),
                                           -limit)
        and_clause = "Date > '{}'".format(date_start)
        graph_title = self.sys_config.graph_cache.get_cache_title(
            ticker_id, period, aggregation, limit)
        detector = self._pattern_controller.get_detector_for_fibonacci_and_pattern(
            self.sys_config, ticker_id, and_clause, limit)
        graph_api = DccGraphApi(graph_cache_id, graph_title)
        graph_api.ticker_id = ticker_id
        graph_api.df = detector.pdh.pattern_data.df
        graph = self.__get_dcc_graph_element__(detector, graph_api)
        cache_api = self.sys_config.graph_cache.get_cache_object_api(
            graph_cache_id, graph, period, refresh_interval)
        self.sys_config.graph_cache.add_cache_object(cache_api)
        return graph, graph_cache_id
Exemplo n.º 6
0
 def get_chart_type_regression(self, master_sale: SalesmanSale):
     graph_api = DccGraphApi(self._chart_id,
                             '{}'.format(master_sale.title),
                             use_title_for_y_axis=False)
     graph_api.figure_data = self.__get_regression_figure_data__(
         master_sale)
     graph_api.figure_layout_x_axis_dict = self.__get_figure_layout_x_axis_dict__(
     )
     # graph_api.figure_layout_y_axis_dict = self.__get_figure_layout_y_axis_dict__(graph_api)
     return [MyDCC.graph(graph_api)]
Exemplo n.º 7
0
 def get_chart_type_scatter(self, title: str):
     graph_api = DccGraphApi(self._chart_id,
                             '{}: {}'.format(self._chart_name, title),
                             use_title_for_y_axis=False)
     graph_api.figure_data = self.__get_scatter_figure_data__()
     graph_api.figure_layout_x_axis_dict = self.__get_figure_layout_x_axis_dict__(
     )
     graph_api.figure_layout_y_axis_dict = self.__get_figure_layout_y_axis_dict__(
         graph_api)
     return [MyDCC.graph(graph_api)]
Exemplo n.º 8
0
 def __add_cache_object_for_ticker_to_graph_first_cache__(self, ticker: str, and_clause=''):
     graph_id = self._graph_first_cache.graph_id
     cache_key = self._graph_first_cache.get_cache_key(ticker, 0)
     if self._graph_first_cache.get_cached_object_by_key(cache_key) is None:
         aggregation = self.sys_config.period_aggregation
         graph_title = self.__get_graph_title__(ticker, self.sys_config.period, aggregation)
         detector = self._pattern_controller.get_detector_for_dash(self.sys_config, ticker, and_clause)
         pattern_data = detector.pdh.pattern_data
         graph_api = DccGraphApi(graph_id, graph_title)
         graph_api.ticker_id = ticker
         graph_api.df = detector.pdh.pattern_data.df
         graph = self.__get_dcc_graph_element__(detector, graph_api)
         cache_api = self.__get_cache_api__(cache_key, graph, detector, pattern_data)
         self._graph_first_cache.add_cache_object(cache_api)
         print('{}: Cached into graph_first_cache: {}'.format(MyDate.get_time_str_from_datetime(), cache_key))
     else:
         print('{}: Already cached by graph_first_cache: {}'.format(MyDate.get_time_str_from_datetime(), cache_key))
 def __add_calculated_graph_to_cache__(self, graph_cache_id: str,
                                       ticker_id: str, period: str,
                                       aggregation: int, limit: int,
                                       indicator: str,
                                       refresh_interval: int):
     date_start = MyDate.adjust_by_days(MyDate.get_datetime_object().date(),
                                        -limit)
     and_clause = "Date > '{}'".format(date_start)
     graph_title = self.sys_config.graph_cache.get_cache_title(
         ticker_id, period, aggregation, limit)
     detector = self._pattern_controller.get_detector_for_fibonacci_and_pattern(
         self.sys_config, ticker_id, and_clause, limit)
     graph_api = DccGraphApi(graph_cache_id, graph_title)
     graph_api.ticker_id = ticker_id
     graph_api.indicator = None if indicator == INDI.NONE else indicator
     graph_api.df = detector.pdh.pattern_data.df
     graph = self.__get_dcc_graph_element__(detector, graph_api)
     cache_api = self.sys_config.graph_cache.get_cache_object_api(
         graph_cache_id, graph, period, refresh_interval)
     self.sys_config.graph_cache.add_cache_object(cache_api)
     return graph
    def __get_chart_type_mood__(self):
        graph_list = []
        if self._index in ['', INDICES.ALL]:
            index_list = [
                INDICES.CRYPTO_CCY, INDICES.DOW_JONES, INDICES.NASDAQ100,
                INDICES.Q_FSE
            ]
            # ToDo Check INDICES.Q_FSE
        else:
            index_list = [self._index]

        for index in index_list:
            index_for_key = index.replace(' ', '_').lower()
            index_for_key = index_for_key if self._index == '' else '{}_{}'.format(
                index_for_key, 'single')
            chart_id = '{}_{}'.format(self._chart_id, index_for_key)
            # print('__get_chart_type_heatmap__: chart_id={}'.format(chart_id))
            chart_name = index
            graph_api = DccGraphApi(chart_id, chart_name)
            figure_data, max_value = self.__get_mood_chart_figure_data__(index)
            max_value = int(round(max_value + 5, -1))
            value_interval = max(10, int(round(max_value / 3, -1)))
            tick_vals = list(range(-max_value, max_value, value_interval))
            tick_text = [abs(value) for value in tick_vals]
            graph_api.figure_data = figure_data
            graph_api.figure_layout_height = 300
            graph_api.figure_layout_margin = {
                'b': 50,
                'r': 50,
                'l': 50,
                't': 50
            }
            graph_api.figure_layout_barmode = 'overlay'
            graph_api.figure_layout_bargap = 0.1
            graph_api.figure_layout_x_axis_dict = {}
            graph_api.figure_layout_y_axis_dict = {
                'range': 'Date',
                'tickvals': tick_vals,
                'ticktext': tick_text
            }
            graph_list.append(MyDCC.graph(graph_api))
        return graph_list
Exemplo n.º 11
0
 def set_graph_api(self):
     self.graph_api = DccGraphApi(self.graph_id, self.graph_title)
     if self.trade_process in [TP.TRADE_REPLAY, TP.PATTERN_REPLAY]:
         self.graph_api.pattern_trade = self.trade_handler.pattern_trade_for_replay
         self.graph_api.ticker_id = self.trade_test_api.symbol
         self.graph_api.df = self.detector.pdh.pattern_data.df
     else:
         self.set_selected_trade_to_api()
         # print('set_graph_api: trade_id={}, pattern_trade.id={}'.format(self.trade_test_api.trade_id,
         #                                                                self.graph_api.pattern_trade.id))
         self.graph_api.ticker_id = self.trade_test_api.symbol
         self.graph_api.df = self.graph_api.pattern_trade.get_data_frame_for_replay(
         )  # ToDo - old (this) or new
         # self.graph_api._df = self.detector.pdh.pattern_data._df
     self.graph_api.period = self.trade_test_api.period
Exemplo n.º 12
0
 def __get_chart_type_roc__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self._chart_name, 'Models'))
     graph_api.figure_data = self.__get_roc_figure_data__()
     graph_api.figure_layout_x_axis_dict = self.__get_figure_layout_x_axis_dict__()
     graph_api.figure_layout_y_axis_dict = self.__get_figure_layout_y_axis_dict__(graph_api)
     return [MyDCC.graph(graph_api)]
Exemplo n.º 13
0
 def __get_chart_type_pie__(self):
     graph_api_all = DccGraphApi(self._chart_id + '_all', self._chart_name + ' (all)')
     graph_api_all.figure_data = self.__get_pie_figure_data__('all')
     graph_api_winner = DccGraphApi(self._chart_id + '_winner', self._chart_name + ' (winner)')
     graph_api_winner.figure_data = self.__get_pie_figure_data__('winner')
     graph_api_loser = DccGraphApi(self._chart_id + '_loser', self._chart_name + ' (loser)')
     graph_api_loser.figure_data = self.__get_pie_figure_data__('loser')
     w_h, l_h = self.__get_winner_loser_heights__(graph_api_winner.values_total, graph_api_loser.values_total)
     graph_api_all.figure_layout_height = 800
     graph_api_winner.figure_layout_height = 800
     graph_api_loser.figure_layout_height = 800
     graph_api_loser.figure_layout_height *= w_h
     graph_api_loser.figure_layout_height *= l_h
     graph_api_all.figure_layout_margin = {'b': 200, 'r': 50, 'l': 50, 't': 50}
     graph_api_winner.figure_layout_margin = {'b': 200, 'r': 50, 'l': 50, 't': 50}
     graph_api_loser.figure_layout_margin = {'b': 200, 'r': 50, 'l': 50, 't': 50}
     return [MyDCC.graph(graph_api_all), MyDCC.graph(graph_api_winner), MyDCC.graph(graph_api_loser)]
 def __get_chart_type_pie__(self):
     graph_api = DccGraphApi(self._chart_id, self._chart_name)
     graph_api.figure_data = self.__get_pie_figure_data__('all')
     graph_api.figure_layout_height = 800
     graph_api.figure_layout_margin = {'b': 200, 'r': 50, 'l': 50, 't': 50}
     return [MyDCC.graph(graph_api)]
Exemplo n.º 15
0
 def __get_chart_type_predictor__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self._chart_name, 'master_predictor'))
     graph_api.figure_data = self.__get_scatter_figure_data_for_predictor__()
     return [MyDCC.graph(graph_api)]
Exemplo n.º 16
0
 def __get_chart_type_heatmap__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self._chart_name, 'Heatmap'))
     graph_api.figure_data = self.__get_heatmap_figure_data__('Test')
     graph_api.figure_layout_x_axis_dict = None  # dict(type='date',)
     graph_api.figure_layout_y_axis_dict = None  # dict(type='linear', range=[1, 100], dtick=20, ticksuffix='%')
     return [MyDCC.graph(graph_api)]
Exemplo n.º 17
0
 def __get_chart_type_confusion_regression__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self.predictor, self.x_variable))
     graph_api.figure_data = self.__get_confusion_regression_figure_data__()
     graph_api.figure_layout_x_axis_dict = self.__get_figure_layout_x_axis_dict__()
     # graph_api.figure_layout_y_axis_dict = self.__get_figure_layout_y_axis_dict__(graph_api)
     return [MyDCC.graph(graph_api)]
Exemplo n.º 18
0
 def __get_scatter_graph_for_trades__(
         self, scatter_graph_id='trade_statistics_scatter_graph'):
     graph_api = DccGraphApi(scatter_graph_id, 'My Trades')
     graph_api.figure_data = self.__get_scatter_figure_data_for_trades__(
         self._df_trade)
     return MyDCC.graph(graph_api)
Exemplo n.º 19
0
 def __get_chart_type_scatter__(self):
     graph_api = DccGraphApi(self._chart_id, '{} ({})'.format(self._chart_name, 'winner & loser'))
     graph_api.figure_data = self.__get_scatter_figure_data__()
     graph_api.figure_layout_x_axis_dict = self.__get_figure_layout_x_axis_dict__()
     graph_api.figure_layout_y_axis_dict = self.__get_figure_layout_y_axis_dict__(graph_api)
     return [MyDCC.graph(graph_api)]