Skip to content

Commit

Permalink
Merge pull request #498 from DanielGoldfarb/master
Browse files Browse the repository at this point in the history
completed kwarg descriptions for `mpf.kwarg_help()`
  • Loading branch information
DanielGoldfarb authored Feb 1, 2022
2 parents 8fa38f2 + 6110d05 commit 1f710ca
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 131 deletions.
56 changes: 31 additions & 25 deletions src/mplfinance/_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,60 +61,61 @@ def _apply_mpfstyle(style):
def _valid_make_mpf_style_kwargs():
vkwargs = {
'base_mpf_style': { 'Default' : None,
'Description' : '',
'Description' : 'mplfinance style to use as base of new mplfinance style',
'Validator' : lambda value: value in _styles.keys() },

'base_mpl_style': { 'Default' : None,
'Description' : '',
'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' : '',
'Description' : 'market colors object, from `mpf.make_market_colors()`',
'Validator' : lambda value: isinstance(value,dict) },

'mavcolors' : { 'Default' : None,
'Description' : '',
'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' : '',
'Description' : 'background color for Axes',
'Validator' : lambda value: isinstance(value,str) },

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

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

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

'gridstyle' : { 'Default' : None,
'Description' : '',
'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' : '',
'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' : '',
'Description' : 'True|False primary Axes y-ticks and labels on right.',
'Validator' : lambda value: isinstance(value,bool) },

'rc' : { 'Default' : None,
'Description' : '',
'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' : '',
'Description' : 'rcparams to set (dict) (all other rcparams cleared)',
'Validator' : lambda value: isinstance(value,dict) },

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

}
Expand Down Expand Up @@ -209,55 +210,60 @@ def _valid_mpf_style(value):
def _valid_make_marketcolors_kwargs():
vkwargs = {
'up' : { 'Default' : None,
'Description' : '',
'Description' : 'color to indicate up',
'Validator' : lambda value: _mpf_is_color_like(value) },

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

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

'alpha' : { 'Default' : None,
'Description' : '',
'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' : '',
'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' : '',
'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' : '',
'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' : '',
'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' : '',
'Description' : 'True/False volume color depends on price change from previous day',
'Validator' : lambda value: isinstance(value,bool) },


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

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

Expand Down
52 changes: 37 additions & 15 deletions src/mplfinance/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,12 @@ def _valid_renko_kwargs():
'''
vkwargs = {
'brick_size' : { 'Default' : 'atr',
'Description' : '',
'Description' : 'size of each brick on y-axis (typically price).'+
' specify a number, or specify "atr" for average true range.',
'Validator' : lambda value: isinstance(value,(float,int))
or value == 'atr' },
'atr_length' : { 'Default' : 14,
'Description' : '',
'Description' : 'number of periods for atr calculation (if brick size is "atr")',
'Validator' : lambda value: isinstance(value,int)
or value == 'total' },
}
Expand All @@ -416,16 +417,18 @@ def _valid_pnf_kwargs():
'''
vkwargs = {
'box_size' : { 'Default' : 'atr',
'Description' : '',
'Description' : 'size of each box on y-axis (typically price).'+
' specify a number, or specify "atr" for average true range.',
'Validator' : lambda value: isinstance(value,(float,int))
or value == 'atr' },
'atr_length' : { 'Default' : 14,
'Description' : '',
'Description' : 'number of periods for atr calculation (if box size is "atr")',
'Validator' : lambda value: isinstance(value,int)
or value == 'total' },

'reversal' : { 'Default' : 1,
'Description' : '',
'Description' : 'number of boxes, in opposite direction, needed to reverse'+
' a trend (i.e. to start a new column).',
'Validator' : lambda value: isinstance(value,int) },
}

Expand All @@ -451,52 +454,71 @@ def _valid_lines_kwargs():
valid_linestyles = ['-','solid','--','dashed','-.','dashdot',':','dotted',None,' ','']
vkwargs = {
'hlines' : { 'Default' : None,
'Description' : '',
'Description' : 'Draw one or more HORIZONTAL LINES across entire plot, by'+
' specifying a price, or sequence of prices. May also be a dict'+
' with key `hlines` specifying a price or sequence of prices, plus'+
' one or more of the following keys: `colors`, `linestyle`,'+
' `linewidths`, `alpha`.',
'Validator' : _bypass_kwarg_validation },

'vlines' : { 'Default' : None,
'Description' : '',
'Description' : 'Draw one or more VERTICAL LINES across entire plot, by'+
' specifying a date[time], or sequence of date[time]. May also'+
' be a dict with key `vlines` specifying a date[time] or sequence'+
' of date[time], plus one or more of the following keys:'+
' `colors`, `linestyle`, `linewidths`, `alpha`.',
'Validator' : _bypass_kwarg_validation },

'alines' : { 'Default' : None,
'Description' : '',
'Description' : 'Draw one or more ARBITRARY LINES anywhere on the plot, by'+
' specifying a sequence of two or more date/price pairs, or by'+
' specifying a sequence of sequences of two or more date/price pairs.'+
' May also be a dict with key `alines` (as date/price pairs described above),'+
' plus one or more of the following keys:'+
' `colors`, `linestyle`, `linewidths`, `alpha`.',
'Validator' : _bypass_kwarg_validation },

'tlines' : { 'Default' : None,
'Description' : '',
'Description' : 'Draw one or more TREND LINES by specifying one or more pairs of date[times]'+
' between which each trend line should be drawn. May also be a dict with key'+
' `tlines` as just described, plus one or more of the following keys:'+
' `colors`, `linestyle`, `linewidths`, `alpha`, `tline_use`,`tline_method`.',
'Validator' : _bypass_kwarg_validation },

'colors' : { 'Default' : None,
'Description' : '',
'Description' : 'Color of [hvat]lines (or sequence of colors, if each line to be a different color)',
'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' : '-',
'Description' : '',
'Description' : 'line style of [hvat]lines (or sequence of line styles, if each line to have a different linestyle)',
'Validator' : lambda value: value is None or value in valid_linestyles or
all([v in valid_linestyles for v in value]) },

'linewidths': { 'Default' : None,
'Description' : '',
'Description' : 'line width of [hvat]lines (or sequence of line widths, if each line to have a different width)',
'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,
'Description' : '',
'Description' : 'Opacity of [hvat]lines. float from 0.0 to 1.0 '+
' (1.0 means fully opaque; 0.0 means transparent.',
'Validator' : lambda value: isinstance(value,(float,int)) },


'tline_use' : { 'Default' : 'close',
'Description' : '',
'Description' : 'value to use for TREND LINE ("open","high","low","close") or sequence of'+
' any combination of "open", "high", "low", "close" to use a average of the'+
' specified values to determine the trend line.',
'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',
'Description' : '',
'Description' : 'method for TREND LINE determination: "point-to-point" or "least-squares"',
'Validator' : lambda value: value in ['point-to-point','least-squares'] }
}

Expand Down
2 changes: 1 addition & 1 deletion src/mplfinance/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version_info = (0, 12, 8, 'beta', 8)
version_info = (0, 12, 8, 'beta', 9)

_specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''}

Expand Down
Loading

0 comments on commit 1f710ca

Please sign in to comment.