def rolling_vwap(df, length):
 closes = df['close'].values
 volumes = df['volume'].values
 product = (closes * volumes)
 out = full_like(closes, nan)
 for upper_bound in range(length, (len(closes) + 1)):
  bounds = slice((upper_bound - length), upper_bound)
  out[(upper_bound - 1)] = (product[bounds].sum() / volumes[bounds].sum())
 return Series(out, index=df.index)

def rolling_vwap ( df , length ) : closes = df [ 'close' ] . values volumes = df [ 'volume' ] . values product = ( closes * volumes ) out = full_like ( closes , nan ) for upper_bound in range ( length , ( len ( closes ) + 1 ) ) : bounds = slice ( ( upper_bound - length ) , upper_bound ) out [ ( upper_bound - 1 ) ] = ( product [ bounds ] . sum ( ) / volumes [ bounds ] . sum ( ) ) return Series ( out , index = df . index )
simple rolling vwap implementation for testing .