Ejemplo n.º 1
0
def _valid_update_width_kwargs():
    vkwargs = {

        'ohlc_ticksize'    : { 'Default'     : None,
                               'Description' : 'length of horizontal open/close tickmarks on ohlc bars',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },

        'ohlc_linewidth'   : { 'Default'     : None,
                               'Description' : 'width (thickness) of ohlc bars',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },

        'volume_width'     : { 'Default'     : None,
                               'Description' : 'width of volume bars',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },

        'volume_linewidth' : { 'Default'     : None,
                               'Description' : 'width of edges of volume bars',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },

        'candle_width'     : { 'Default'     : None,
                               'Description' : 'width of candles',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },

        'candle_linewidth' : { 'Default'     : None,
                               'Description' : 'width of candle edges and wicks',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },

        'line_width'       : { 'Default'     : None,
                               'Description' : 'width of lines (for line plots and moving averages)',
                               'Validator'   : lambda value: isinstance(value,(float,int)) },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 2
0
def _valid_update_width_kwargs():
    vkwargs = {
        'ohlc_ticksize': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
        'ohlc_linewidth': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
        'volume_width': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
        'volume_linewidth': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
        'candle_width': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
        'candle_linewidth': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
        'line_width': {
            'Default': None,
            'Validator': lambda value: isinstance(value, (float, int))
        },
    }
    _validate_vkwargs_dict(vkwargs)
    return vkwargs
Ejemplo n.º 3
0
def _valid_addplot_kwargs():

    valid_linestyles = ['-','solid','--','dashed','-.','dashdot','.','dotted',None,' ','']


    vkwargs = {
        'scatter'     : { 'Default'     : False,
                          'Validator'   : lambda value: isinstance(value,bool) },

        'panel'       : { 'Default'     : 'main',
                          'Validator'   : lambda value: value in ['main','lower'] },

        'marker'      : { 'Default'     : 'o',
                          'Validator'   : lambda value: not isinstance(value,bool)  },

        'markersize'  : { 'Default'     : 18,
                          'Validator'   : lambda value: isinstance(value,(int,float)) },

        'color'       : { 'Default'     : None,
                          'Validator'   : lambda value: mcolors.is_color_like(value) },

        'linestyle'   : { 'Default'     : None,
                          'Validator'   : lambda value: value in valid_linestyles },

        'secondary_y' : { 'Default'     : 'auto',
                          'Validator'   : lambda value: isinstance(value,bool) or value == 'auto' }
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 4
0
def _valid_pointnfig_kwargs():
    '''
    Construct and return the "valid pointnfig kwargs table" for the mplfinance.plot(type='pnf') 
    function. A valid kwargs table is a `dict` of `dict`s. The keys of the outer dict are 
    the valid key-words for the function.  The value for each key is a dict containing 2 
    specific keys: "Default", and "Validator" with the following values:
        "Default"      - The default value for the kwarg if none is specified.
        "Validator"    - A function that takes the caller specified value for the kwarg,
                         and validates that it is the correct type, and (for kwargs with 
                         a limited set of allowed values) may also validate that the
                         kwarg value is one of the allowed values.
    '''
    vkwargs = {
        'box_size': {
            'Default':
            'atr',
            'Validator':
            lambda value: isinstance(value, (float, int)) or value == 'atr'
        },
        'atr_length': {
            'Default': 14,
            'Validator': lambda value: isinstance(value, int)
        },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 5
0
def _valid_addplot_kwargs():

    valid_linestyles = ('-','solid','--','dashed','-.','dashdot','.','dotted',None,' ','')
    valid_types = ('line','scatter','bar', 'ohlc', 'candle')

    vkwargs = {
        'scatter'     : { 'Default'     : False,
                          'Validator'   : lambda value: isinstance(value,bool) },

        'type'        : { 'Default'     : 'line',
                          'Validator'   : lambda value: value in valid_types },

        'mav'         : { 'Default'     : None,
                          'Validator'   : _mav_validator },
        
        'panel'       : { 'Default'     : 0, 
                          'Validator'   : lambda value: _valid_panel_id(value) },

        'marker'      : { 'Default'     : 'o',
                          'Validator'   : lambda value: _bypass_kwarg_validation(value)  },

        'markersize'  : { 'Default'     : 18,
                          'Validator'   : lambda value: isinstance(value,(int,float)) },

        'color'       : { 'Default'     : None,
                          'Validator'   : lambda value: mcolors.is_color_like(value) or
                                         (isinstance(value,(list,tuple,np.ndarray)) and all([mcolors.is_color_like(v) for v in value])) },

        'linestyle'   : { 'Default'     : None,
                          'Validator'   : lambda value: value in valid_linestyles },

        'width'       : { 'Default'     : None, # width of `bar` or `line` 
                          'Validator'   : lambda value: isinstance(value,(int,float)) or
                                                        all([isinstance(v,(int,float)) for v in value]) },

        'bottom'      : { 'Default'     : 0,  # bottom for `type=bar` plots
                          'Validator'   : lambda value: isinstance(value,(int,float)) or
                                                        all([isinstance(v,(int,float)) for v in value]) },
        'alpha'       : { 'Default'     : 1,  # alpha of `bar`, `line`, or `scatter`
                          'Validator'   : lambda value: isinstance(value,(int,float)) or
                                                        all([isinstance(v,(int,float)) for v in value]) },

        'secondary_y' : { 'Default'     : 'auto',
                          'Validator'   : lambda value: isinstance(value,bool) or value == 'auto' },

        'y_on_right'  : { 'Default'     : None,
                          'Validator'   : lambda value: isinstance(value,bool) },
        
        'ylabel'      : { 'Default'     : None,
                          'Validator'   : lambda value: isinstance(value,str) },

        'ylim'        : {'Default'      : None,
                         'Validator'    : lambda value: isinstance(value, (list,tuple)) and len(value) == 2 
                                                                      and all([isinstance(v,(int,float)) for v in value])},
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 6
0
def _valid_make_mpf_style_kwargs():
    vkwargs = {
        'base_mpf_style': {
            'Default': None,
            'Validator': lambda value: value in _styles.keys()
        },
        'base_mpl_style': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },  # and is in plt.style.available
        'marketcolors': {
            'Default': None,  # 
            'Validator': lambda value: isinstance(value, dict)
        },
        'mavcolors': {
            'Default': None,
            'Validator': lambda value: isinstance(value, list)
        },  # TODO: all([mcolors.is_color_like(v) for v in value.values()])
        'facecolor': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
        'edgecolor': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
        'figcolor': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
        'gridcolor': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
        'gridstyle': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
        'gridaxis': {
            'Default':
            None,
            'Validator':
            lambda value: value in [
                'vertical'[0:len(value)], 'horizontal'[0:len(value)], 'both'[
                    0:len(value)]
            ]
        },
        'y_on_right': {
            'Default': None,
            'Validator': lambda value: isinstance(value, bool)
        },
        'rc': {
            'Default': None,
            'Validator': lambda value: isinstance(value, dict)
        },
    }
    _validate_vkwargs_dict(vkwargs)
    return vkwargs
Ejemplo n.º 7
0
def _valid_make_marketcolors_kwargs():
    vkwargs = {
        'up': {
            'Default': None,
            'Validator': lambda value: mcolors.is_color_like(value)
        },
        'down': {
            'Default': None,
            'Validator': lambda value: mcolors.is_color_like(value)
        },
        'alpha': {
            'Default':
            None,
            'Validator':
            lambda value:
            (isinstance(value, float) and 0.0 <= value and 1.0 >= value)
        },
        'edge': {
            'Default': None,
            'Validator': lambda value: _valid_mpf_color_spec(value)
        },
        'wick': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or isinstance(value, str) or
            mcolors.is_color_like(value)
        },
        'ohlc': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or isinstance(value, str) or
            mcolors.is_color_like(value)
        },
        'volume': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or isinstance(value, str) or
            mcolors.is_color_like(value)
        },
        'vcdopcod': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'inherit': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'base_mpf_style': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
    }
    _validate_vkwargs_dict(vkwargs)
    return vkwargs
Ejemplo n.º 8
0
def _valid_scale_width_kwargs():
    vkwargs = {
        'ohlc'    : { 'Default'     : None,
                      'Validator'   : lambda value: isinstance(value,(float,int)) },

        'volume'  : { 'Default'     : None,
                      'Validator'   : lambda value: isinstance(value,(float,int)) },

        'candle'  : { 'Default'     : None,
                      'Validator'   : lambda value: isinstance(value,(float,int)) },
    }
    _validate_vkwargs_dict(vkwargs)
    return vkwargs
Ejemplo n.º 9
0
def _valid_addplot_kwargs():

    valid_linestyles = [
        "-",
        "solid",
        "--",
        "dashed",
        "-.",
        "dashdot",
        ".",
        "dotted",
        None,
        " ",
        "",
    ]

    vkwargs = {
        "scatter": {
            "Default": False,
            "Validator": lambda value: isinstance(value, bool),
        },
        "panel": {
            "Default": "main",
            "Validator": lambda value: value in ["main", "lower"],
        },
        "marker": {
            "Default": "o",
            "Validator": lambda value: _bypass_kwarg_validation(value),
        },
        "markersize": {
            "Default": 18,
            "Validator": lambda value: isinstance(value, (int, float)),
        },
        "color": {
            "Default": None,
            "Validator": lambda value: mcolors.is_color_like(value),
        },
        "linestyle": {
            "Default": None,
            "Validator": lambda value: value in valid_linestyles,
        },
        "secondary_y": {
            "Default": "auto",
            "Validator":
            lambda value: isinstance(value, bool) or value == "auto",
        },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 10
0
def _valid_lines_kwargs():
    '''
    Construct and return the "valid lines (hlines,vlines,alines,tlines) kwargs table" 
    for the mplfinance.plot() `[h|v|a|t]lines=` kwarg functions.
    A valid kwargs table is a `dict` of `dict`s. The keys of the outer dict are 
    the valid key-words for the function.  The value for each key is a dict containing 2 
    specific keys: "Default", and "Validator" with the following values:
        "Default"      - The default value for the kwarg if none is specified.
        "Validator"    - A function that takes the caller specified value for the kwarg,
                         and validates that it is the correct type, and (for kwargs with 
                         a limited set of allowed values) may also validate that the
                         kwarg value is one of the allowed values.
    '''
    valid_linestyles = ['-','solid','--','dashed','-.','dashdot',':','dotted',None,' ','']
    vkwargs = {
        'hlines'    : { 'Default'     : None,
                        'Validator'   : _bypass_kwarg_validation },
        'vlines'    : { 'Default'     : None,
                        'Validator'   : _bypass_kwarg_validation },
        'alines'    : { 'Default'     : None,
                        'Validator'   : _bypass_kwarg_validation },
        'tlines'    : { 'Default'     : None,
                        'Validator'   : _bypass_kwarg_validation },
        'colors'    : { 'Default'     : None,
                        'Validator'   : lambda value: value is None or
                                            mcolors.is_color_like(value) or
                                            ( isinstance(value,(list,tuple)) and
                                              all([mcolors.is_color_like(v) for v in value]) ) },
        'linestyle' : { 'Default'     : '-',
                        'Validator'   : lambda value: value is None or value in valid_linestyles },
        'linewidths': { 'Default'     : None,
                        'Validator'   : lambda value: value is None or
                                            isinstance(value,(float,int)) or 
                                            all([isinstance(v,(float,int)) for v in value]) },
        'alpha'     : { 'Default'     : 1.0,
                        'Validator'   : lambda value: isinstance(value,(float,int)) },

        'tline_use' : { 'Default'     : 'close', 
                        'Validator'   : lambda value: isinstance(value,str) or (isinstance(value,(list,tuple)) and
                                                                      all([isinstance(v,str) for v in value]) ) },
        'tline_method': { 'Default'   : 'point-to-point',
                          'Validator' : lambda value: value in ['point-to-point','least-squares'] }
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 11
0
def _valid_make_mpf_style_kwargs():
    vkwargs = {
        'base_mpf_style': { 'Default'     : None,
                            'Description' : 'mplfinance style to use as base of new mplfinance style',
                            'Validator'   : lambda value: value in _styles.keys() },

        'base_mpl_style': { 'Default'     : None,
                            'Description' : 'matplotlib style to use as base of new mplfinance style',
                            'Validator'   : lambda value: isinstance(value,str) }, # and is in plt.style.available

        'marketcolors'  : { 'Default'     : None,
                            'Description' : 'market colors object, from `mpf.make_market_colors()`',
                            'Validator'   : lambda value: isinstance(value,dict)  },

        'mavcolors'     : { 'Default'     : None,
                            'Description' : 'sequence of colors to use for moving averages',
                            'Validator'   : lambda value: isinstance(value,list) },  # TODO: all([_mpf_is_color_like(v) for v in value.values()])


        'facecolor'     : { 'Default'     : None,
                            'Description' : 'background color for Axes',
                            'Validator'   : lambda value: isinstance(value,str) },

        'edgecolor'     : { 'Default'     : None,
                            'Description' : 'edge color for Axes',
                            'Validator'   : lambda value: isinstance(value,str) },

        'figcolor'      : { 'Default'     : None,
                            'Description' : 'background color for Figure.',
                            'Validator'   : lambda value: isinstance(value,str) },

        'gridcolor'     : { 'Default'     : None,
                            'Description' : 'color for grid lines',
                            'Validator'   : lambda value: isinstance(value,str) },

        'gridstyle'     : { 'Default'     : None,
                            'Description' : "grid line style ('-', '--', '-.', ':', '', offset, on-off-seq)."+
                                            " (see also: https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html)",
                            'Validator'   : lambda value: isinstance(value,str) },

        'gridaxis'      : { 'Default'     : None,
                            'Description' : "grid lines 'vertical', 'horizontal', or 'both'",
                            'Validator'   : lambda value: value in [ 'vertical'[0:len(value)], 'horizontal'[0:len(value)], 'both'[0:len(value)] ] },

        'y_on_right'    : { 'Default'     : None,
                            'Description' : 'True|False primary Axes y-ticks and labels on right.',
                            'Validator'   : lambda value: isinstance(value,bool) },

        'rc'            : { 'Default'     : None,
                            'Description' : 'rcparams overrides (dict) (all other rcparams unchanged)',
                            'Validator'   : lambda value: isinstance(value,dict) },

        'legacy_rc'     : { 'Default'     : None,  # Just in case someone depended upon old behavior
                            'Description' : 'rcparams to set (dict) (all other rcparams cleared)',
                            'Validator'   : lambda value: isinstance(value,dict) },

        'style_name'    : { 'Default'     : None,
                            'Description' : 'name for this style; useful when calling `mpf.write_style_file(style,filename)`',
                            'Validator'   : lambda value: isinstance(value,str) },

    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 12
0
def _valid_make_marketcolors_kwargs():
    vkwargs = {
        'up'            : { 'Default'     : None,
                            'Description' : 'color to indicate up', 
                            'Validator'   : lambda value: _mpf_is_color_like(value) },

        'down'          : { 'Default'     : None,
                            'Description' : 'color to indicate down', 
                            'Validator'   : lambda value: _mpf_is_color_like(value) },

        'hollow'        : { 'Default'     : None,
                            'Description' : "color for hollow candles (for `type=hollow`)",
                            'Validator'   : lambda value: _mpf_is_color_like(value) },

        'alpha'         : { 'Default'     : None,
                            'Description' : 'opacity 0.0 (transparent) to 1.0 (opaque);'+
                                            ' applies to candles,renko,pnf (but not ohlc bars)',
                            'Validator'   : lambda value: (isinstance(value,float)
                                                           and 0.0 <= value and 1.0 >= value ) },

        'edge'          : { 'Default'     : None,
                            'Description' : 'color of candle edge; may also be "i" or "inherit"'+
                                            ' to take color from base_mpf_style',
                            'Validator'   : lambda value: _valid_mpf_color_spec(value) },

        'wick'          : { 'Default'     : None,
                            'Description' : "color of candle wick; may be single color,"+
                                            " or may be dict with keys 'up' and 'down'",
                            'Validator'   : lambda value: isinstance(value,dict)
                                                          or isinstance(value,str)
                                                          or _mpf_is_color_like(value) },

        'ohlc'          : { 'Default'     : None,
			    'Description' : "color of ohlc bars; may be single color,"+
					    " or may be dict with keys 'up' and 'down'",
                            'Validator'   : lambda value: isinstance(value,dict)
                                                          or isinstance(value,str)
                                                          or _mpf_is_color_like(value) },

        'volume'        : { 'Default'   : None,
			    'Description' : "color of volume bars; may be single color,"+
					    " or may be dict with keys 'up' and 'down'",
                            'Validator'   : lambda value: isinstance(value,dict)
                                                          or isinstance(value,str)
                                                          or _mpf_is_color_like(value) },

        'vcdopcod'      : { 'Default'     : False,
                            'Description' : 'True/False volume color depends on price change from previous day',
                            'Validator'   : lambda value: isinstance(value,bool) },


        'inherit'       : { 'Default'     : False,
                            'Description' : 'inherit color from base_mpf_style for: edge,volume,ohlc,wick',
                            'Validator'   : lambda value: isinstance(value,bool) },

        'base_mpf_style': { 'Default'     : None,
                            'Description' : 'mplfinance style market colors as basis for new market colors object',
                            'Validator'   : lambda value: isinstance(value,str) },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 13
0
def _valid_plot_kwargs():
    '''
    Construct and return the "valid kwargs table" for the mplfinance.plot() function.
    A valid kwargs table is a `dict` of `dict`s.  The keys of the outer dict are the
    valid key-words for the function.  The value for each key is a dict containing
    2 specific keys: "Default", and "Validator" with the following values:
        "Default"      - The default value for the kwarg if none is specified.
        "Validator"    - A function that takes the caller specified value for the kwarg,
                         and validates that it is the correct type, and (for kwargs with 
                         a limited set of allowed values) may also validate that the
                         kwarg value is one of the allowed values.
    '''

    vkwargs = {
        'type': {
            'Default':
            'ohlc',
            'Validator':
            lambda value: value in
            ['candle', 'candlestick', 'ohlc', 'bars', 'ohlc_bars', 'line']
        },
        'style': {
            'Default':
            'default',
            'Validator':
            lambda value: value in _styles.available_styles() or isinstance(
                value, dict)
        },
        'volume': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'mav': {
            'Default': None,
            'Validator': _mav_validator
        },
        'study': {
            'Default': None,
            #'Validator'   : lambda value: isinstance(value,dict) }, #{'studyname': {study parms}} example: {'TE':{'mav':20,'upper':2,'lower':2}}
            'Validator': lambda value: _kwarg_not_implemented(value)
        },
        'marketcolors': {
            'Default': None,  # use 'style' for default, instead.
            'Validator': lambda value: isinstance(value, dict)
        },
        'no_xgaps': {
            'Default': True,  # None means follow default logic below:
            'Validator': lambda value: _warn_no_xgaps_deprecated(value)
        },
        'show_nontrading': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'figscale': {
            'Default':
            1.0,  # scale base figure size up or down.
            'Validator':
            lambda value: isinstance(value, float) or isinstance(value, int)
        },
        'figratio': {
            'Default':
            (8.00,
             5.75),  # aspect ratio; will equal fig size when figscale=1.0
            'Validator':
            lambda value: isinstance(value,
                                     (tuple, list)) and len(value) == 2 and
            isinstance(value[0],
                       (float, int)) and isinstance(value[1], (float, int))
        },
        'linecolor': {
            'Default': 'k',  # line color in line plot
            'Validator': lambda value: mcolors.is_color_like(value)
        },
        'title': {
            'Default': None,  # Plot Title
            'Validator': lambda value: isinstance(value, str)
        },
        'ylabel': {
            'Default': 'Price',  # y-axis label
            'Validator': lambda value: isinstance(value, str)
        },
        'ylabel_lower': {
            'Default': None,  # y-axis label default logic below
            'Validator': lambda value: isinstance(value, str)
        },

        #'xlabel'      : { 'Default'     : None,  # x-axis label, default is None because obvious it's time or date
        #                  'Validator'   : lambda value: isinstance(value,str) },
        'addplot': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or (isinstance(
                value, list) and all([isinstance(d, dict) for d in value]))
        },
        'savefig': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or isinstance(value, str) or
            isinstance(value, io.BytesIO)
        },
        'block': {
            'Default': True,
            'Validator': lambda value: isinstance(value, bool)
        },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
def _valid_plot_kwargs():
    '''
    Construct and return the "valid kwargs table" for the mplfinance.plot() function.
    A valid kwargs table is a `dict` of `dict`s.  The keys of the outer dict are the
    valid key-words for the function.  The value for each key is a dict containing
    2 specific keys: "Default", and "Validator" with the following values:
        "Default"      - The default value for the kwarg if none is specified.
        "Validator"    - A function that takes the caller specified value for the kwarg,
                         and validates that it is the correct type, and (for kwargs with 
                         a limited set of allowed values) may also validate that the
                         kwarg value is one of the allowed values.
    '''

    vkwargs = {
        'columns'                   : { 'Default'     : None, # use default names: ('Open', 'High', 'Low', 'Close', 'Volume')
                                        'Validator'   : lambda value: isinstance(value, (tuple, list))
                                                                   and len(value) == 5
                                                                   and all(isinstance(c, str) for c in value) },
        'type'                      : { 'Default'     : 'ohlc',
                                        'Validator'   : lambda value: value in _get_valid_plot_types() },
 
        'style'                     : { 'Default'     : None,
                                        'Validator'   : _styles._valid_mpf_style },
 
        'volume'                    : { 'Default'     : False,
                                        'Validator'   : lambda value: isinstance(value,bool) or isinstance(value,mpl_axes.Axes) },
 
        'mav'                       : { 'Default'     : None,
                                        'Validator'   : _mav_validator },
        
        'renko_params'              : { 'Default'     : dict(),
                                        'Validator'   : lambda value: isinstance(value,dict) },

        'pnf_params'                : { 'Default'     : dict(),
                                        'Validator'   : lambda value: isinstance(value,dict) },
 
        'study'                     : { 'Default'     : None,
                                        'Validator'   : lambda value: _kwarg_not_implemented(value) }, 
 
        'marketcolors'              : { 'Default'     : None, # use 'style' for default, instead.
                                        'Validator'   : lambda value: isinstance(value,dict) },
 
        'no_xgaps'                  : { 'Default'     : True,  # None means follow default logic below:
                                        'Validator'   : lambda value: _warn_no_xgaps_deprecated(value) },
 
        'show_nontrading'           : { 'Default'     : False, 
                                        'Validator'   : lambda value: isinstance(value,bool) },
 
        'figscale'                  : { 'Default'     : None, # scale base figure size up or down.
                                        'Validator'   : lambda value: isinstance(value,float) or isinstance(value,int) },
 
        'figratio'                  : { 'Default'     : None, # aspect ratio; scaled to 8.0 height
                                        'Validator'   : lambda value: isinstance(value,(tuple,list))
                                                                      and len(value) == 2
                                                                      and isinstance(value[0],(float,int))
                                                                      and isinstance(value[1],(float,int)) },
 
        'figsize'                   : { 'Default'     : None,  # figure size; overrides figratio and figscale
                                        'Validator'   : lambda value: isinstance(value,(tuple,list))
                                                                      and len(value) == 2
                                                                      and isinstance(value[0],(float,int))
                                                                      and isinstance(value[1],(float,int)) },
 
        'linecolor'                 : { 'Default'     : None, # line color in line plot
                                        'Validator'   : lambda value: mcolors.is_color_like(value) },

        'title'                     : { 'Default'     : None, # Figure Title
                                        'Validator'   : lambda value: isinstance(value,(str,dict)) },
 
        'axtitle'                   : { 'Default'     : None, # Axes Title (subplot title)
                                        'Validator'   : lambda value: isinstance(value,str) },
 
        'ylabel'                    : { 'Default'     : 'Price', # y-axis label
                                        'Validator'   : lambda value: isinstance(value,str) },
 
        'ylabel_lower'              : { 'Default'     : None, # y-axis label default logic below
                                        'Validator'   : lambda value: isinstance(value,str) },
 
        'addplot'                   : { 'Default'     : None, 
                                        'Validator'   : lambda value: isinstance(value,dict) or (isinstance(value,list) and all([isinstance(d,dict) for d in value])) },
 
        'savefig'                   : { 'Default'     : None, 
                                        'Validator'   : lambda value: isinstance(value,dict) or isinstance(value,str) or isinstance(value, io.BytesIO) },
 
        'block'                     : { 'Default'     : None, 
                                        'Validator'   : lambda value: isinstance(value,bool) },
 
        'returnfig'                 : { 'Default'     : False, 
                                        'Validator'   : lambda value: isinstance(value,bool) },

        'return_calculated_values'  : {'Default'      : None,
                                       'Validator'    : lambda value: isinstance(value, dict) and len(value) == 0},

        'set_ylim'                  : {'Default'      : None,
                                       'Validator'    : lambda value: _warn_set_ylim_deprecated(value) },
 
        'ylim'                      : {'Default'      : None,
                                       'Validator'    : lambda value: isinstance(value, (list,tuple)) and len(value) == 2 
                                                                      and all([isinstance(v,(int,float)) for v in value])},
 
        'xlim'                      : {'Default'      : None,
                                       'Validator'    : lambda value: isinstance(value, (list,tuple)) and len(value) == 2 
                                                                      and all([isinstance(v,(int,float)) for v in value])},
 
        'set_ylim_panelB'           : {'Default'      : None,
                                       'Validator'    : lambda value: _warn_set_ylim_deprecated(value) },
 
        'hlines'                    : { 'Default'     : None, 
                                        'Validator'   : lambda value: _hlines_validator(value) },
 
        'vlines'                    : { 'Default'     : None, 
                                        'Validator'   : lambda value: _vlines_validator(value) },

        'alines'                    : { 'Default'     : None, 
                                        'Validator'   : lambda value: _alines_validator(value) },
 
        'tlines'                    : { 'Default'     : None, 
                                        'Validator'   : lambda value: _tlines_validator(value) },
       
        'panel_ratios'              : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,(tuple,list)) and len(value) <= 10 and
                                                                      all([isinstance(v,(int,float)) for v in value]) },

        'main_panel'                : { 'Default'     : 0,
                                        'Validator'   : lambda value: _valid_panel_id(value) },

        'volume_panel'              : { 'Default'     : 1,
                                        'Validator'   : lambda value: _valid_panel_id(value) },

        'num_panels'                : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,int) and value in range(1,10+1) },

        'datetime_format'           : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,str) },

        'xrotation'                 : { 'Default'     : 45,
                                        'Validator'   : lambda value: isinstance(value,(int,float)) },

        'axisoff'                   : { 'Default'     : False,
                                        'Validator'   : lambda value: isinstance(value,bool) },

        'closefig'                  : { 'Default'     : 'auto',
                                        'Validator'   : lambda value: isinstance(value,bool) },

        'fill_between'              : { 'Default'     : None,
                                        'Validator'   : lambda value: _num_or_seq_of_num(value) or 
                                                                     (isinstance(value,dict) and 'y1' in value and
                                                                       _num_or_seq_of_num(value['y1'])) },

        'tight_layout'              : { 'Default'     : False,
                                        'Validator'   : lambda value: isinstance(value,bool) },

        'width_adjuster_version'    : { 'Default'     : 'v1',
                                        'Validator'   : lambda value: value in ('v0', 'v1') },

        'scale_width_adjustment'    : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,dict) and len(value) > 0 },

        'update_width_config'       : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,dict) and len(value) > 0 },

        'return_width_config'       : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,dict) and len(value)==0 },

        'saxbelow'                  : { 'Default'     : True,  # Issue#115 Comment#639446764
                                        'Validator'   : lambda value: isinstance(value,bool) },
        
        'scale_padding'             : { 'Default'     : 1.0,   # Issue#193 
                                        'Validator'   : lambda value: _scale_padding_validator(value) },

        'ax'                        : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,mpl_axes.Axes) },

        'volume_exponent'           : { 'Default'     : None,
                                        'Validator'   : lambda value: isinstance(value,int) or value == 'legacy'},

        'tz_localize'               : { 'Default'     : True,
                                        'Validator'   : lambda value: isinstance(value,bool) },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 15
0
def _valid_plot_kwargs():
    '''
    Construct and return the "valid kwargs table" for the mplfinance.plot() function.
    A valid kwargs table is a `dict` of `dict`s.  The keys of the outer dict are the
    valid key-words for the function.  The value for each key is a dict containing
    2 specific keys: "Default", and "Validator" with the following values:
        "Default"      - The default value for the kwarg if none is specified.
        "Validator"    - A function that takes the caller specified value for the kwarg,
                         and validates that it is the correct type, and (for kwargs with 
                         a limited set of allowed values) may also validate that the
                         kwarg value is one of the allowed values.
    '''

    vkwargs = {
        'columns': {
            'Default': ('Open', 'High', 'Low', 'Close', 'Volume'),
            'Validator':
            lambda value: isinstance(value, (tuple, list)) and len(value) == 5
            and all(isinstance(c, str) for c in value)
        },
        'type': {
            'Default':
            'ohlc',
            'Validator':
            lambda value: value in ('candle', 'candlestick', 'ohlc',
                                    'ohlc_bars', 'line', 'renko', 'pnf')
        },
        'style': {
            'Default':
            'default',
            'Validator':
            lambda value: value in _styles.available_styles() or isinstance(
                value, dict)
        },
        'volume': {
            'Default':
            False,
            'Validator':
            lambda value: isinstance(value, bool) or value in ['B', 'C']
        },
        'mav': {
            'Default': None,
            'Validator': _mav_validator
        },
        'renko_params': {
            'Default': dict(),
            'Validator': lambda value: isinstance(value, dict)
        },
        'pnf_params': {
            'Default': dict(),
            'Validator': lambda value: isinstance(value, dict)
        },
        'study': {
            'Default': None,
            'Validator': lambda value: _kwarg_not_implemented(value)
        },
        'marketcolors': {
            'Default': None,  # use 'style' for default, instead.
            'Validator': lambda value: isinstance(value, dict)
        },
        'no_xgaps': {
            'Default': True,  # None means follow default logic below:
            'Validator': lambda value: _warn_no_xgaps_deprecated(value)
        },
        'show_nontrading': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'figscale': {
            'Default':
            1.0,  # scale base figure size up or down.
            'Validator':
            lambda value: isinstance(value, float) or isinstance(value, int)
        },
        'figratio': {
            'Default':
            (8.00,
             5.75),  # aspect ratio; will equal fig size when figscale=1.0
            'Validator':
            lambda value: isinstance(value,
                                     (tuple, list)) and len(value) == 2 and
            isinstance(value[0],
                       (float, int)) and isinstance(value[1], (float, int))
        },
        'linecolor': {
            'Default': None,  # line color in line plot
            'Validator': lambda value: mcolors.is_color_like(value)
        },
        'title': {
            'Default': None,  # Plot Title
            'Validator': lambda value: isinstance(value, str)
        },
        'ylabel': {
            'Default': 'Price',  # y-axis label
            'Validator': lambda value: isinstance(value, str)
        },
        'ylabel_lower': {
            'Default': None,  # y-axis label default logic below
            'Validator': lambda value: isinstance(value, str)
        },
        'addplot': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or (isinstance(
                value, list) and all([isinstance(d, dict) for d in value]))
        },
        'savefig': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, dict) or isinstance(value, str) or
            isinstance(value, io.BytesIO)
        },
        'block': {
            'Default': True,
            'Validator': lambda value: isinstance(value, bool)
        },
        'returnfig': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'return_calculated_values': {
            'Default': None,
            'Validator':
            lambda value: isinstance(value, dict) and len(value) == 0
        },
        'set_ylim': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, (list, tuple)) and len(value) == 2
            and all([isinstance(v, (int, float)) for v in value])
        },
        'set_ylim_panelB': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, (list, tuple)) and len(value) == 2
            and all([isinstance(v, (int, float)) for v in value])
        },
        'set_ylim_panelC': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, (list, tuple)) and len(value) == 2
            and all([isinstance(v, (int, float)) for v in value])
        },
        'hlines': {
            'Default': None,
            'Validator': lambda value: _hlines_validator(value)
        },
        'vlines': {
            'Default': None,
            'Validator': lambda value: _vlines_validator(value)
        },
        'alines': {
            'Default': None,
            'Validator': lambda value: _alines_validator(value)
        },
        'tlines': {
            'Default': None,
            'Validator': lambda value: _tlines_validator(value)
        },
        'panel_order': {
            'Default':
            'ABC',
            'Validator':
            lambda value: isinstance(value, str) and len(value) == 3 and (
                ('A' in value and 'B' in value and 'C' in value) or
                ('a' in value and 'b' in value and 'c' in value))
        },
        'panel_ratio': {
            'Default': (5, 2, 2),
            'Validator':
            lambda value: isinstance(value, (tuple, list)) and len(value) == 3
            and all([isinstance(v, (int, float)) for v in value])
        },
        'datetime_format': {
            'Default': None,
            'Validator': lambda value: isinstance(value, str)
        },
        'xrotation': {
            'Default': 45,
            'Validator': lambda value: isinstance(value, (int, float))
        },
        'axesoff': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'axesoffdark': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'closefig': {
            'Default': 'auto',
            'Validator': lambda value: isinstance(value, bool)
        },
        'yscale': {
            'Default':
            None,
            'Validator':
            lambda value: isinstance(value, str) or
            (isinstance(value, dict) and 'yscale' in value)
        },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 16
0
def _valid_addplot_kwargs():

    valid_linestyles = ('-', 'solid', '--', 'dashed', '-.', 'dashdot', '.',
                        'dotted', None, ' ', '')
    #valid_types = ('line','scatter','bar','ohlc','candle')
    valid_types = ('line', 'scatter', 'bar')

    vkwargs = {
        'scatter': {
            'Default': False,
            'Validator': lambda value: isinstance(value, bool)
        },
        'type': {
            'Default': 'line',
            'Validator': lambda value: value in valid_types
        },
        'panel': {
            'Default': 'A',  # new: use 'A' for 'main', 'B' for 'lower'
            'Validator': lambda value: value in
            ('A', 'B', 'C', 'main', 'lower')
        },
        'marker': {
            'Default': 'o',
            'Validator': lambda value: _bypass_kwarg_validation(value)
        },
        'markersize': {
            'Default': 18,
            'Validator': lambda value: isinstance(value, (int, float))
        },
        'color': {
            'Default': None,
            'Validator': lambda value: mcolors.is_color_like(value)
        },
        'linestyle': {
            'Default': None,
            'Validator': lambda value: value in valid_linestyles
        },
        'width': {
            'Default':
            0.8,
            'Validator':
            lambda value: isinstance(value, (int, float)) or all(
                [isinstance(v, (int, float)) for v in value])
        },
        'bottom': {
            'Default':
            0,
            'Validator':
            lambda value: isinstance(value, (int, float)) or all(
                [isinstance(v, (int, float)) for v in value])
        },
        'alpha': {
            'Default':
            1,
            'Validator':
            lambda value: isinstance(value, (int, float)) or all(
                [isinstance(v, (int, float)) for v in value])
        },
        'secondary_y': {
            'Default': 'auto',
            'Validator':
            lambda value: isinstance(value, bool) or value == 'auto'
        }
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs
Ejemplo n.º 17
0
def _valid_plot_kwargs():
    """
    Construct and return the "valid kwargs table" for the mplfinance.plot() function.
    A valid kwargs table is a `dict` of `dict`s.  The keys of the outer dict are the
    valid key-words for the function.  The value for each key is a dict containing
    2 specific keys: "Default", and "Validator" with the following values:
        "Default"      - The default value for the kwarg if none is specified.
        "Validator"    - A function that takes the caller specified value for the kwarg,
                         and validates that it is the correct type, and (for kwargs with
                         a limited set of allowed values) may also validate that the
                         kwarg value is one of the allowed values.
    """

    vkwargs = {
        "columns": {
            "Default": ("Open", "High", "Low", "Close", "Volume"),
            "Validator":
            lambda value: isinstance(value, (tuple, list)) and len(value) == 5
            and all(isinstance(c, str) for c in value),
        },
        "type": {
            "Default":
            "ohlc",
            "Validator":
            lambda value: value in [
                "candle",
                "candlestick",
                "ohlc",
                "bars",
                "ohlc_bars",
                "line",
                "renko",
                "pnf",
                "p&f",
                "pointnfigure",
            ],
        },
        "style": {
            "Default":
            "default",
            "Validator":
            lambda value: value in _styles.available_styles() or isinstance(
                value, dict),
        },
        "volume": {
            "Default": False,
            "Validator": lambda value: isinstance(value, bool),
        },
        "mav": {
            "Default": None,
            "Validator": _mav_validator
        },
        "renko_params": {
            "Default": dict(),
            "Validator": lambda value: isinstance(value, dict),
        },
        "pointnfig_params": {
            "Default": dict(),
            "Validator": lambda value: isinstance(value, dict),
        },
        "study": {
            "Default": None,
            #'Validator'   : lambda value: isinstance(value,dict) }, #{'studyname': {study parms}} example: {'TE':{'mav':20,'upper':2,'lower':2}}
            "Validator": lambda value: _kwarg_not_implemented(value),
        },
        "marketcolors": {
            "Default": None,  # use 'style' for default, instead.
            "Validator": lambda value: isinstance(value, dict),
        },
        "no_xgaps": {
            "Default": True,  # None means follow default logic below:
            "Validator": lambda value: _warn_no_xgaps_deprecated(value),
        },
        "show_nontrading": {
            "Default": False,
            "Validator": lambda value: isinstance(value, bool),
        },
        "figscale": {
            "Default":
            1.0,  # scale base figure size up or down.
            "Validator":
            lambda value: isinstance(value, float) or isinstance(value, int),
        },
        "figratio": {
            "Default": (
                8.00,
                5.75,
            ),  # aspect ratio; will equal fig size when figscale=1.0
            "Validator":
            lambda value: isinstance(value,
                                     (tuple, list)) and len(value) == 2 and
            isinstance(value[0],
                       (float, int)) and isinstance(value[1], (float, int)),
        },
        "linecolor": {
            "Default": "k",  # line color in line plot
            "Validator": lambda value: mcolors.is_color_like(value),
        },
        "title": {
            "Default": None,  # Plot Title
            "Validator": lambda value: isinstance(value, str),
        },
        "ylabel": {
            "Default": "Price",  # y-axis label
            "Validator": lambda value: isinstance(value, str),
        },
        "ylabel_lower": {
            "Default": None,  # y-axis label default logic below
            "Validator": lambda value: isinstance(value, str),
        },
        #'xlabel'                    : { 'Default'     : None,  # x-axis label, default is None because obvious it's time or date
        #                                'Validator'   : lambda value: isinstance(value,str) },
        "addplot": {
            "Default":
            None,
            "Validator":
            lambda value: isinstance(value, dict) or (isinstance(
                value, list) and all([isinstance(d, dict) for d in value])),
        },
        "savefig": {
            "Default":
            None,
            "Validator":
            lambda value: isinstance(value, dict) or isinstance(value, str) or
            isinstance(value, io.BytesIO),
        },
        "block": {
            "Default": True,
            "Validator": lambda value: isinstance(value, bool)
        },
        "returnfig": {
            "Default": False,
            "Validator": lambda value: isinstance(value, bool),
        },
        "return_calculated_values": {
            "Default": None,
            "Validator":
            lambda value: isinstance(value, dict) and len(value) == 0,
        },
    }

    _validate_vkwargs_dict(vkwargs)

    return vkwargs