def draw(self, render='html', file_name=None, width=None, height=None, title=None, keep_ui_state=True, annotation_df=None, target_type: TargetType = TargetType.open_long): if target_type == TargetType.open_long: df = self.open_long_df.copy() elif target_type == TargetType.open_short: df = self.open_short_df.copy() df['target_type'] = target_type.value if pd_is_not_null(df): drawer = Drawer(NormalData(df=df)) drawer.draw_table(render=render, file_name=file_name, width=width, height=height, title=title, keep_ui_state=keep_ui_state)
def get_trading_signals_figure(order_reader: OrderReader, entity_id: str, start_timestamp=None, end_timestamp=None): entity_type, _, _ = decode_entity_id(entity_id) data_schema = get_kdata_schema(entity_type=entity_type, level=order_reader.level) if not start_timestamp: start_timestamp = order_reader.start_timestamp if not end_timestamp: end_timestamp = order_reader.end_timestamp kdata_reader = DataReader(entity_ids=[entity_id], data_schema=data_schema, entity_schema=entity_schema_map.get(entity_type), start_timestamp=start_timestamp, end_timestamp=end_timestamp, level=order_reader.level) # generate the annotation df order_reader.move_on(timeout=0) df = order_reader.data_df.copy() df = df[df.entity_id == entity_id].copy() if pd_is_not_null(df): df['value'] = df['order_price'] df['flag'] = df['order_type'].apply(lambda x: order_type_flag(x)) df['color'] = df['order_type'].apply(lambda x: order_type_color(x)) print(df.tail()) drawer = Drawer(main_df=kdata_reader.data_df, annotation_df=df) return drawer.draw_kline(show=False)
def on_finish(self): # show the result import plotly.io as pio pio.renderers.default = "browser" reader = AccountReader(trader_names=[self.trader_name]) drawer = Drawer(main_data=NormalData( reader.data_df.copy()[['trader_name', 'timestamp', 'all_value']], category_field='trader_name')) drawer.draw_line()
def on_finish(self, timestmap): self.on_trading_finish(timestmap) # show the result if self.draw_result: import plotly.io as pio pio.renderers.default = "browser" reader = AccountStatsReader(trader_names=[self.trader_name]) df = reader.data_df drawer = Drawer(main_data=NormalData(df.copy()[['trader_name', 'timestamp', 'all_value']], category_field='trader_name')) drawer.draw_line(show=True)
def result_drawer(self) -> Drawer: return Drawer(NormalData(df=self.result_df))
def pipe_drawer(self) -> Drawer: drawer = Drawer(NormalData(df=self.pipe_df)) return drawer
def draw_line(self, show=True): drawer = Drawer(main_data=NormalData( self.data_df.copy()[['trader_name', 'timestamp', 'all_value']], category_field='trader_name')) return drawer.draw_line(show=show)
self.filters += filter else: self.filters = filter super().__init__(Order, None, None, None, None, None, None, the_timestamp, start_timestamp, end_timestamp, columns, self.filters, order, None, level, category_field='trader_name', time_field='timestamp', computing_window=None) if __name__ == '__main__': reader = AccountStatsReader(trader_names=['000338_ma_trader']) drawer = Drawer(main_data=NormalData( reader.data_df.copy()[['trader_name', 'timestamp', 'all_value']], category_field='trader_name')) drawer.draw_line()
def factor_drawer(self) -> Drawer: drawer = Drawer(NormalData(df=self.factor_df)) return drawer
entity_ids: List[str] = None, exchanges: List[str] = None, codes: List[str] = None, the_timestamp: Union[str, pd.Timestamp] = None, start_timestamp: Union[str, pd.Timestamp] = None, end_timestamp: Union[str, pd.Timestamp] = None, columns: List = ['id', 'entity_id', 'timestamp', 'level', 'open', 'close', 'high', 'low'], filters: List = None, order: object = None, limit: int = None, level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY, category_field: str = 'entity_id', time_field: str = 'timestamp', computing_window: int = None, keep_all_timestamp: bool = False, fill_method: str = 'ffill', effective_number: int = None, accumulator: Accumulator = None, need_persist: bool = False, dry_run: bool = False, adjust_type: Union[AdjustType, str] = None, window=30) -> None: self.adjust_type = adjust_type transformer = TopBottomTransformer(window=window) super().__init__(entity_schema, provider, entity_provider, entity_ids, exchanges, codes, the_timestamp, start_timestamp, end_timestamp, columns, filters, order, limit, level, category_field, time_field, computing_window, keep_all_timestamp, fill_method, effective_number, transformer, accumulator, need_persist, dry_run, adjust_type) if __name__ == '__main__': factor = TopBottomFactor(codes=['601318'], start_timestamp='2005-01-01', end_timestamp=now_pd_timestamp(), level=IntervalLevel.LEVEL_1DAY, window=120) print(factor.factor_df) data_reader1 = DataReader(codes=['601318'], data_schema=Stock1dKdata, entity_schema=Stock) drawer = Drawer(main_df=data_reader1.data_df, factor_df=factor.factor_df[['top', 'bottom']]) drawer.draw_kline()
rects = [] duans = [] for index, item in duan_df.iterrows(): if len(duans) == 4: x = duans[0][0] x1 = duans[3][0] if duans[0][1] < duans[1][1]: y, y1 = intersect((duans[0][1], duans[1][1]), (duans[2][1], duans[3][1])) else: y, y1 = intersect((duans[1][1], duans[0][1]), (duans[3][1], duans[2][1])) rects.append(((x, y), (x1, y1))) duans = [] else: duans.append((index[1], item.value)) drawer = Drawer(main_df=df, factor_df_list=[flag_df[['value']], duan_df], annotation_df=flag_df) fig = drawer.draw_kline(show=False) for rect in rects: fig.add_shape(type="rect", x0=rect[0][0], y0=rect[0][1], x1=rect[1][0], y1=rect[1][1], line=dict( color="RoyalBlue", width=2, ), fillcolor="LightSkyBlue", ) fig.update_shapes(dict(xref='x', yref='y')) fig.show() # the __all__ is generated __all__ = ['Direction', 'Fenxing', 'KState', 'DuanState', 'a_include_b', 'is_including', 'get_direction', 'is_up',