qteasy/visual.py
def mpf_plot(stock_data=None, share_name=None, stock=None, start=None, end=None,
             asset_type='E', plot_type=None, no_visual=False, mav=None, indicator=None,
             indicator_par=None, **kwargs):
    """plot stock data or extracted data in renko form
    """
    assert plot_type is not None
    if end is None:
        now = pd.to_datetime('now') + pd.Timedelta(8, 'h')
        if now.hour >= 23:
            end = pd.to_datetime('today')
        else:
            end = pd.to_datetime('today') - pd.Timedelta(1, 'd')
    if start is None:
        start = end - pd.Timedelta(60, 'd')
    if mav is None:
        mav = [5, 10, 20, 60]
    end = pd.to_datetime(end)
    start = pd.to_datetime(start)
    # 当stock_data没有给出时，则从网上或本地获取股票数据
    if stock_data is None:
        assert stock is not None
        if 'adj' in kwargs:
            adj = kwargs['adj']
        else:
            adj = 'none'
        # 准备股票数据，为了实现动态图表，应该获取一只股票在全历史周期内的所有价格数据，并且在全周期上计算
        # 所需的均线以及指标数据，显示的时候只显示其中一部分即可，并且可以使用鼠标缩放平移
        # 因此_prepare_mpf_data()函数应该返回一个包含所有历史价格以及相关指标的DataFrame
        daily, share_name = _get_mpf_data(stock=stock,
                                          asset_type=asset_type,
                                          adj=adj,
                                          mav=mav,
                                          indicator=indicator,
                                          indicator_par=indicator_par)
        has_volume = True
    else:
        assert isinstance(stock_data, pd.DataFrame)
        assert all(col in stock_data.columns for col in ['open', 'high', 'low', 'close'])
        daily = stock_data
        has_volume = 'volume' in stock_data.columns
        if share_name is None:
            share_name = 'stock'
    # 如果给出或获取的数据没有volume列，则生成空数据列
    if 'volume' not in daily.columns:
        daily['volume'] = np.nan
    daily = _add_indicators(daily, mav=mav)

    my_color = mpf.make_marketcolors(up='r',
                                     down='g',
                                     edge='inherit',
                                     wick='inherit',
                                     volume='inherit')
    my_style = mpf.make_mpf_style(marketcolors=my_color,
                                  figcolor='(0.82, 0.83, 0.85)',
                                  gridcolor='(0.82, 0.83, 0.85)')
    if not no_visual:
        idx_start = np.searchsorted(daily.index, start)
        idx_range = np.searchsorted(daily.index, end) - idx_start
        my_candle = InterCandle(data=daily, stock_name=share_name, style=my_style,
                                idx_start=idx_start, idx_range=idx_range)
        my_candle.refresh_texts(daily.iloc[idx_start + idx_range - 1])
        my_candle.refresh_plot(idx_start, idx_range)
    return daily
plot stock data or extracted data in renko form
    
plot stock data or extracted data in renko form
plot stock data or extracted data in renko form
def mpf_plot(stock_data=None, share_name=None, stock=None, start=None, end=None,
             asset_type='E', plot_type=None, no_visual=False, mav=None, indicator=None,
             indicator_par=None, **kwargs):
    assert plot_type is not None
    if end is None:
        now = pd.to_datetime('now') + pd.Timedelta(8, 'h')
        if now.hour >= 23:
            end = pd.to_datetime('today')
        else:
            end = pd.to_datetime('today') - pd.Timedelta(1, 'd')
    if start is None:
        start = end - pd.Timedelta(60, 'd')
    if mav is None:
        mav = [5, 10, 20, 60]
    end = pd.to_datetime(end)
    start = pd.to_datetime(start)
    if stock_data is None:
        assert stock is not None
        if 'adj' in kwargs:
            adj = kwargs['adj']
        else:
            adj = 'none'
        daily, share_name = _get_mpf_data(stock=stock,
                                          asset_type=asset_type,
                                          adj=adj,
                                          mav=mav,
                                          indicator=indicator,
                                          indicator_par=indicator_par)
        has_volume = True
    else:
        assert isinstance(stock_data, pd.DataFrame)
        assert all(col in stock_data.columns for col in ['open', 'high', 'low', 'close'])
        daily = stock_data
        has_volume = 'volume' in stock_data.columns
        if share_name is None:
            share_name = 'stock'
    if 'volume' not in daily.columns:
        daily['volume'] = np.nan
    daily = _add_indicators(daily, mav=mav)
    my_color = mpf.make_marketcolors(up='r',
                                     down='g',
                                     edge='inherit',
                                     wick='inherit',
                                     volume='inherit')
    my_style = mpf.make_mpf_style(marketcolors=my_color,
                                  figcolor='(0.82, 0.83, 0.85)',
                                  gridcolor='(0.82, 0.83, 0.85)')
    if not no_visual:
        idx_start = np.searchsorted(daily.index, start)
        idx_range = np.searchsorted(daily.index, end) - idx_start
        my_candle = InterCandle(data=daily, stock_name=share_name, style=my_style,
                                idx_start=idx_start, idx_range=idx_range)
        my_candle.refresh_texts(daily.iloc[idx_start + idx_range - 1])
        my_candle.refresh_plot(idx_start, idx_range)
    return daily
def mpf_plot ( stock_data = None , share_name = None , stock = None , start = None , end = None , asset_type = 'E' , plot_type = None , no_visual = False , mav = None , indicator = None , indicator_par = None , ** kwargs ) : assert plot_type is not None if end is None : now = pd . to_datetime ( 'now' ) + pd . Timedelta ( 8 , 'h' ) if now . hour >= 23 : end = pd . to_datetime ( 'today' ) else : end = pd . to_datetime ( 'today' ) - pd . Timedelta ( 1 , 'd' ) if start is None : start = end - pd . Timedelta ( 60 , 'd' ) if mav is None : mav = [ 5 , 10 , 20 , 60 ] end = pd . to_datetime ( end ) start = pd . to_datetime ( start ) if stock_data is None : assert stock is not None if 'adj' in kwargs : adj = kwargs [ 'adj' ] else : adj = 'none' daily , share_name = _get_mpf_data ( stock = stock , asset_type = asset_type , adj = adj , mav = mav , indicator = indicator , indicator_par = indicator_par ) has_volume = True else : assert isinstance ( stock_data , pd . DataFrame ) assert all ( col in stock_data . columns for col in [ 'open' , 'high' , 'low' , 'close' ] ) daily = stock_data has_volume = 'volume' in stock_data . columns if share_name is None : share_name = 'stock' if 'volume' not in daily . columns : daily [ 'volume' ] = np . nan daily = _add_indicators ( daily , mav = mav ) my_color = mpf . make_marketcolors ( up = 'r' , down = 'g' , edge = 'inherit' , wick = 'inherit' , volume = 'inherit' ) my_style = mpf . make_mpf_style ( marketcolors = my_color , figcolor = '(0.82, 0.83, 0.85)' , gridcolor = '(0.82, 0.83, 0.85)' ) if not no_visual : idx_start = np . searchsorted ( daily . index , start ) idx_range = np . searchsorted ( daily . index , end ) - idx_start my_candle = InterCandle ( data = daily , stock_name = share_name , style = my_style , idx_start = idx_start , idx_range = idx_range ) my_candle . refresh_texts ( daily . iloc [ idx_start + idx_range - 1 ] ) my_candle . refresh_plot ( idx_start , idx_range ) return daily
plot stock data or extracted data in renko form
plot stock data or extracted data in renko form
"""plot stock data or extracted data in renko form
    """ # 当stock_data没有给出时，则从网上或本地获取股票数据 # 准备股票数据，为了实现动态图表，应该获取一只股票在全历史周期内的所有价格数据，并且在全周期上计算 # 所需的均线以及指标数据，显示的时候只显示其中一部分即可，并且可以使用鼠标缩放平移 # 因此_prepare_mpf_data()函数应该返回一个包含所有历史价格以及相关指标的DataFrame # 如果给出或获取的数据没有volume列，则生成空数据列
stock_data
share_name
stock
start
end
asset_type
plot_type
no_visual
mav
indicator
indicator_par