(price, n, alphaIn=None)
return ema
Algorithm by Stockchart
Algorithm by Stockchart
Algorithm by Stockchart
def emaHelper(price, n, alphaIn=None):
	"""
	Algorithm by Stockchart
	"""
	length_of_df = len(price.axes[0])
	
	initial_sma = price[0:n].mean()
	
	ema = pd.Series(np.nan, index=range(0, length_of_df))
	ema.iat[n-1] = initial_sma
	
	if(not alphaIn):
		alpha = (2.0/(n + 1.0))
	else:
		alpha = alphaIn
	
	for i in range(n, length_of_df):
		ema.iat[i] = price.iat[i]* alpha + (1-alpha)* ema.iat[i-1]
	
	return ema
def emaHelper ( price , n , alphaIn = None ) : length_of_df = len ( price . axes [ 0 ] ) initial_sma = price [ 0 : n ] . mean ( ) ema = pd . Series ( np . nan , index = range ( 0 , length_of_df ) ) ema . iat [ n - 1 ] = initial_sma if ( not alphaIn ) : alpha = ( 2.0 / ( n + 1.0 ) ) else : alpha = alphaIn for i in range ( n , length_of_df ) : ema . iat [ i ] = price . iat [ i ] * alpha + ( 1 - alpha ) * ema . iat [ i - 1 ] return ema