def get_bull_ratios(self, index_code, start_date, end_date):
     obj = BullStockRatio(index_code,
                          dbinfo=self.dbinfo,
                          redis_host=self.redis_host)
     df = obj.get_k_data_between(start_date, end_date)
     df = df.sort_values(by=['date'], ascending=True)
     df = df.reset_index(drop=True)
     return df
Exemple #2
0
def create_index_figure_column(code, dtype, start_date, end_date):
    delta_days = (end_date - start_date).days
    if delta_days <= 0: return None
    start_date = start_date.strftime('%Y-%m-%d')
    end_date = end_date.strftime('%Y-%m-%d')
    if dtype == 'K线图': 
        obj = CIndex(code)
        df = obj.get_k_data_in_range(start_date, end_date)
        source = ColumnDataSource(df)
        mapper = linear_cmap(field_name='pchange', palette=['red', 'green'], low=0, high=0, low_color = 'green', high_color = 'red')
        p = figure(plot_height=500, plot_width=1200, tools="", toolbar_location=None, sizing_mode="scale_both", x_range=(0, len(df)))
        p.xaxis.axis_label = "时间"
        p.yaxis.axis_label = "点数"
        p.xaxis.major_label_overrides = {i: mdate for i, mdate in enumerate(df['date'])}
        p.segment(x0='index', y0='low', x1='date', y1='high', line_width=2, color='black', source=source)
        p.vbar(x='index', bottom='open', top='close', width = 50 / delta_days, color=mapper, source=source)
        p.add_tools(HoverTool(tooltips=[("数量", "@close"), ("时间", "@date")]))
        volume_p = figure(plot_height=150, plot_width=1200, tools="", toolbar_location=None, sizing_mode="scale_both")
        volume_p.x_range = p.x_range
        volume_p.vbar(x='date', top='volume', width = 50 / delta_days, color=mapper, source=source)
        return column(p, volume_p)
    else:
        obj = BullStockRatio(code)
        df = obj.get_k_data_between(start_date, end_date)
        source = ColumnDataSource(df)
        p = figure(plot_height=500, plot_width=1200, tools="", toolbar_location=None, sizing_mode="scale_both")
        p.xaxis.axis_label = "时间"
        p.yaxis.axis_label = "比例"
        p.line(x = 'index', y = 'ratio', line_width = 3, line_alpha = 1.0, source = source)
        p.xaxis.major_label_overrides = {i: mdate for i, mdate in enumerate(df['date'])}
        p.add_tools(HoverTool(tooltips=[("比例", "@ratio"), ("时间", "@date")]))
        return column(p)
Exemple #3
0
 def _set_bull_stock_ratio(code_id):
     return (code_id, BullStockRatio(code_id).update(cdate, num))