def __init__(self, main_df: pd.DataFrame = None, factor_df: pd.DataFrame = None, sub_df: pd.DataFrame = None, main_data: NormalData = None, factor_data: NormalData = None, sub_data: NormalData = None, annotation_df: pd.DataFrame = None) -> None: """ :param main_df: df for main chart :param factor_df: factor df on main chart :param sub_df: df for sub chart under main chart :param main_data: NormalData wrap main_df,use either :param factor_data: NormalData wrap factor_df,use either :param sub_data: NormalData wrap sub_df,use either :param annotation_df: """ # 主图数据 if main_data is None: main_data = NormalData(main_df) self.main_data: NormalData = main_data # 主图因子 if factor_data is None: factor_data = NormalData(factor_df) self.factor_data: NormalData = factor_data # 副图数据 if sub_data is None: sub_data = NormalData(sub_df) self.sub_data: NormalData = sub_data # 主图的标记数据 self.annotation_df = annotation_df
def __init__( self, main_df: pd.DataFrame = None, factor_df_list: List[pd.DataFrame] = None, sub_df_list: pd.DataFrame = None, main_data: NormalData = None, factor_data_list: List[NormalData] = None, sub_data_list: NormalData = None, sub_col_chart: Optional[dict] = None, rects: List[Rect] = None, annotation_df: pd.DataFrame = None, scale_value: int = None, ) -> None: """ :param main_df: df for main chart :param factor_df_list: list of factor df on main chart :param sub_df_list: df for sub chart under main chart :param main_data: NormalData wrap main_df,use either :param factor_data_list: list of NormalData wrap factor_df,use either :param sub_data_list: NormalData wrap sub_df,use either :param annotation_df: """ #: 主图数据 if main_data is None: main_data = NormalData(main_df) self.main_data: NormalData = main_data #: 主图因子 if not factor_data_list and factor_df_list: factor_data_list = [] for df in factor_df_list: factor_data_list.append(NormalData(df)) #: 每一个df可能有多个column, 代表多个指标,对于连续型的,可以放在一个df里面 #: 对于离散型的,比如一些特定模式的连线,放在多个df里面较好,因为index不同 self.factor_data_list: List[NormalData] = factor_data_list #: 副图数据 if not sub_data_list and sub_df_list: sub_data_list = [] for df in sub_df_list: sub_data_list.append(NormalData(df)) #: 每一个df可能有多个column, 代表多个指标,对于连续型的,可以放在一个df里面 #: 对于离散型的,比如一些特定模式的连线,放在多个df里面较好,因为index不同 self.sub_data_list: List[NormalData] = sub_data_list #: 幅图col对应的图形,line or bar self.sub_col_chart = sub_col_chart #: 主图的标记数据 self.annotation_df = annotation_df #: list of rect self.rects = rects self.scale_value = scale_value
def __init__(self, main_df: pd.DataFrame = None, factor_df_list: List[pd.DataFrame] = None, sub_df_list: pd.DataFrame = None, main_data: NormalData = None, factor_data_list: List[NormalData] = None, sub_data_list: NormalData = None, rects: List[Rect] = None, annotation_df: pd.DataFrame = None) -> None: """ :param main_df: df for main chart :param factor_df_list: list of factor df on main chart :param sub_df_list: df for sub chart under main chart :param main_data: NormalData wrap main_df,use either :param factor_data_list: list of NormalData wrap factor_df,use either :param sub_data_list: NormalData wrap sub_df,use either :param annotation_df: """ # 主图数据 if main_data is None: main_data = NormalData(main_df) self.main_data: NormalData = main_data # 主图因子 if not factor_data_list and factor_df_list: factor_data_list = [] for df in factor_df_list: factor_data_list.append(NormalData(df)) # 每一个df可能有多个column, 代表多个指标,对于连续型的,可以放在一个df里面 # 对于离散型的,比如一些特定模式的连线,放在多个df里面较好,因为index不同 self.factor_data_list: List[NormalData] = factor_data_list # 副图数据 if not sub_data_list and sub_df_list: sub_data_list = [] for df in sub_df_list: sub_data_list.append(NormalData(df)) # 每一个df可能有多个column, 代表多个指标,对于连续型的,可以放在一个df里面 # 对于离散型的,比如一些特定模式的连线,放在多个df里面较好,因为index不同 self.sub_data_list: List[NormalData] = sub_data_list # 主图的标记数据 self.annotation_df = annotation_df # list of rect self.rects = rects
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)
def on_finish(self): # 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 __init__(self, main_df: pd.DataFrame = None, factor_df_list: List[pd.DataFrame] = None, sub_df: pd.DataFrame = None, main_data: NormalData = None, factor_data_list: List[NormalData] = None, sub_data: NormalData = None, rects=None, annotation_df: pd.DataFrame = None) -> None: """ :param main_df: df for main chart :param factor_df_list: list of factor df on main chart :param sub_df: df for sub chart under main chart :param main_data: NormalData wrap main_df,use either :param factor_data_list: list of NormalData wrap factor_df,use either :param sub_data: NormalData wrap sub_df,use either :param annotation_df: """ # 主图数据 if main_data is None: main_data = NormalData(main_df) self.main_data: NormalData = main_data # 主图因子 if not factor_data_list and factor_df_list: factor_data_list = [] for df in factor_df_list: factor_data_list.append(NormalData(df)) self.factor_data_list: NormalData = factor_data_list # 副图数据 if sub_data is None: sub_data = NormalData(sub_df) self.sub_data: NormalData = sub_data # 主图的标记数据 self.annotation_df = annotation_df
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 add_sub_df(self, df: pd.DataFrame): self.add_sub_data(NormalData(df))
def add_factor_df(self, df: pd.DataFrame): self.add_factor_data(NormalData(df))
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 result_drawer(self) -> Drawer: return Drawer(NormalData(df=self.result_df))
def factor_drawer(self) -> Drawer: drawer = Drawer(NormalData(df=self.factor_df)) return drawer
Order, None, None, None, None, None, None, 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() # the __all__ is generated __all__ = ["clear_trader", "get_trader_info", "get_order_securities", "AccountStatsReader", "OrderReader"]