@@ -63,6 +63,7 @@ def moving_average(x, n, type='simple'):
6363
6464 weights /= weights .sum ()
6565
66+
6667 a = np .convolve (x , weights , mode = 'full' )[:len (x )]
6768 a [:n ] = a [n ]
6869 return a
@@ -146,11 +147,15 @@ def moving_average_convergence(x, nslow=26, nfast=12):
146147ax1 .set_title ('%s daily' % ticker )
147148
148149### plot the price and volume data
150+ dx = r .adj_close - r .close
151+ low = r .low + dx
152+ high = r .high + dx
153+
149154deltas = np .zeros_like (prices )
150155deltas [1 :] = np .diff (prices )
151156up = deltas > 0
152- ax2 .vlines (r .date [up ], r . low [up ], r . high [up ], color = 'black' , label = '_nolegend_' )
153- ax2 .vlines (r .date [~ up ], r . low [~ up ], r . high [~ up ], color = 'black' , label = '_nolegend_' )
157+ ax2 .vlines (r .date [up ], low [up ], high [up ], color = 'black' , label = '_nolegend_' )
158+ ax2 .vlines (r .date [~ up ], low [~ up ], high [~ up ], color = 'black' , label = '_nolegend_' )
154159ma20 = moving_average (prices , 20 , type = 'simple' )
155160ma200 = moving_average (prices , 200 , type = 'simple' )
156161
@@ -207,6 +212,7 @@ def moving_average_convergence(x, nslow=26, nfast=12):
207212
208213 ax .fmt_xdata = mdates .DateFormatter ('%Y-%m-%d' )
209214
215+
210216class PriceFormatter (mticker .FormatStrFormatter ):
211217 'suppress the lowest tick label to prevent overlap'
212218 def __call__ (self , x , pos = None ):
@@ -216,6 +222,7 @@ def __call__(self, x, pos=None):
216222 return mticker .FormatStrFormatter .__call__ (self , x , pos = None )
217223
218224ax2 .yaxis .set_major_formatter (PriceFormatter ('%d' ))
225+
219226plt .show ()
220227
221228
0 commit comments