@@ -1147,6 +1147,45 @@ def _plot_mav(ax,config,xdates,prices,apmav=None,apwidth=None):
1147
1147
mavp_list .append (mavprices )
1148
1148
return mavp_list
1149
1149
1150
+
1151
+ def _plot_ema (ax ,config ,xdates ,prices ,apmav = None ,apwidth = None ):
1152
+ '''ema: exponential moving average'''
1153
+ style = config ['style' ]
1154
+ if apmav is not None :
1155
+ mavgs = apmav
1156
+ else :
1157
+ mavgs = config ['ema' ]
1158
+ mavp_list = []
1159
+ if mavgs is not None :
1160
+ shift = None
1161
+ if isinstance (mavgs ,dict ):
1162
+ shift = mavgs ['shift' ]
1163
+ mavgs = mavgs ['period' ]
1164
+ if isinstance (mavgs ,int ):
1165
+ mavgs = mavgs , # convert to tuple
1166
+ if len (mavgs ) > 7 :
1167
+ mavgs = mavgs [0 :7 ] # take at most 7
1168
+
1169
+ if style ['mavcolors' ] is not None :
1170
+ mavc = cycle (style ['mavcolors' ])
1171
+ else :
1172
+ mavc = None
1173
+
1174
+ for idx ,mav in enumerate (mavgs ):
1175
+ # mean = pd.Series(prices).rolling(mav).mean()
1176
+ mean = pd .Series (prices ).ewm (span = mav ,adjust = False ).mean ()
1177
+ if shift is not None :
1178
+ mean = mean .shift (periods = shift [idx ])
1179
+ mavprices = mean .values
1180
+ lw = config ['_width_config' ]['line_width' ]
1181
+ if mavc :
1182
+ ax .plot (xdates , mavprices , linewidth = lw , color = next (mavc ))
1183
+ else :
1184
+ ax .plot (xdates , mavprices , linewidth = lw )
1185
+ mavp_list .append (mavprices )
1186
+ return mavp_list
1187
+
1188
+
1150
1189
def _auto_secondary_y ( panels , panid , ylo , yhi ):
1151
1190
# If mag(nitude) for this panel is not yet set, then set it
1152
1191
# here, as this is the first ydata to be plotted on this panel:
0 commit comments