Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,006 changes: 1,006 additions & 0 deletions examples/scratch_pad/price-movement_ret_calc_vals.ipynb

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/mplfinance/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,9 @@ def _construct_renko_collections(dates, highs, lows, volumes, config_renko_param
edgecolors=edge_colors,
linewidths=lw
)
return [rectCollection,], new_dates, new_volumes, brick_values, brick_size
calculated_values = dict(dates=new_dates,volumes=new_volumes,
values=brick_values,size=brick_size)
return [rectCollection,], calculated_values


def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnfig_params, closes, marketcolors=None):
Expand Down Expand Up @@ -998,7 +1000,7 @@ def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnf
box_values = [] # y values for the boxes
circle_patches = [] # list of circle patches to be used to create the cirCollection
line_seg = [] # line segments that make up the Xs

for index, difference in enumerate(boxes):
diff = abs(difference)

Expand All @@ -1007,9 +1009,9 @@ def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnf

x = [index] * (diff)
y = [curr_price + (i * box_size * sign) for i in range(start_iteration, diff+start_iteration)]

curr_price += (box_size * sign * (diff))
box_values.append(sum(y) / len(y))
box_values.append( y )

for i in range(len(x)): # x and y have the same length
height = box_size * 0.85
Expand All @@ -1036,7 +1038,9 @@ def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnf
linewidths=lw,
antialiaseds=useAA
)
return [cirCollection, xCollection], new_dates, new_volumes, box_values, box_size
calculated_values = dict(dates=new_dates,counts=boxes,values=box_values,
volumes=new_volumes,size=box_size)
return [cirCollection, xCollection], calculated_values


def _construct_aline_collections(alines, dtix=None):
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, 7, 'alpha', 11)
version_info = (0, 12, 7, 'alpha', 12)

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

Expand Down
41 changes: 27 additions & 14 deletions src/mplfinance/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,25 @@ def plot( data, **kwargs ):
collections =_construct_mpf_collections(ptype,dates,xdates,opens,highs,lows,closes,volumes,config,style)

if ptype in VALID_PMOVE_TYPES:
collections, new_dates, volumes, brick_values, size = collections
formatter = IntegerIndexDateTimeFormatter(new_dates, fmtstring)
xdates = np.arange(len(new_dates))
collections, calculated_values = collections
volumes = calculated_values['volumes']
pmove_dates = calculated_values['dates']
pmove_values = calculated_values['values']
if all([isinstance(v,(list,tuple)) for v in pmove_values]):
pmove_avgvals = [sum(v)/len(v) for v in pmove_values]
else:
pmove_avgvals = pmove_values
pmove_size = calculated_values['size']
pmove_counts = calculated_values['counts'] if 'counts' in calculated_values else None
formatter = IntegerIndexDateTimeFormatter(pmove_dates, fmtstring)
xdates = np.arange(len(pmove_dates))

if collections is not None:
for collection in collections:
axA1.add_collection(collection)

if ptype in VALID_PMOVE_TYPES:
mavprices = _plot_mav(axA1,config,xdates,brick_values)
mavprices = _plot_mav(axA1,config,xdates,pmove_avgvals)
else:
mavprices = _plot_mav(axA1,config,xdates,closes)

Expand All @@ -428,8 +437,8 @@ def plot( data, **kwargs ):
_lows = lows
_highs = highs
else:
_lows = brick_values
_highs = [brick+size for brick in brick_values]
_lows = pmove_avgvals
_highs = [value+pmove_size for value in pmove_avgvals]

miny = np.nanmin(_lows)
maxy = np.nanmax(_highs)
Expand Down Expand Up @@ -458,13 +467,17 @@ def plot( data, **kwargs ):

if config['return_calculated_values'] is not None:
retdict = config['return_calculated_values']
if ptype in VALID_PMOVE_TYPES:
prekey = ptype
retdict[prekey+'_bricks'] = brick_values
retdict[prekey+'_dates'] = mdates.num2date(new_dates)
retdict[prekey+'_size'] = size
if config['volume']:
retdict[prekey+'_volumes'] = volumes
if ptype == 'renko':
retdict['renko_bricks' ] = pmove_values
retdict['renko_dates' ] = mdates.num2date(pmove_dates)
retdict['renko_size' ] = pmove_size
retdict['renko_volumes'] = volumes if config['volume'] else None
elif ptype == 'pnf':
retdict['pnf_dates' ] = mdates.num2date(pmove_dates)
retdict['pnf_counts' ] = pmove_counts
retdict['pnf_values' ] = pmove_values
retdict['pnf_size' ] = pmove_size
retdict['pnf_volumes' ] = volumes if config['volume'] else None
if config['mav'] is not None:
mav = config['mav']
if len(mav) != len(mavprices):
Expand All @@ -480,7 +493,7 @@ def plot( data, **kwargs ):
# Note: these are NOT mutually exclusive, so the order of this
# if/elif is important: VALID_PMOVE_TYPES must be first.
if ptype in VALID_PMOVE_TYPES:
dtix = pd.DatetimeIndex([dt for dt in mdates.num2date(new_dates)])
dtix = pd.DatetimeIndex([dt for dt in mdates.num2date(pmove_dates)])
elif not config['show_nontrading']:
dtix = data.index
else:
Expand Down