# Calculating Bollinger Band Correctly

My bollinger band comes out like the below, which doesn't seem right. Any idea what is wrong with my code for calculating upper and lower bollinber bands?

I obtained my data from here

start, end = dt.datetime(1976, 1, 1), dt.datetime(2013, 12, 31)
here are my bollinger calculations


calculation for bollinger band

ave = pd.stats.moments.rolling_mean(self[name], window)
std = pd.stats.moments.rolling_std(self[name], window)
self['upper'] = ave + (2 * std)
self['lower'] = ave - (2 * std)


-
I am not into python but looks like that your average (ave) time series does not look right in relation to "SP", at least ave does not converge with "SP". –  Matt Wolf May 13 at 5:53
Perhaps try to plot ave to see where it is, and perhaps on a different window plot std to see its size. Providing a full code might be helpful as well. –  Bach May 13 at 6:41
@Bach I second the recommendation on providing more code (or perhaps a simplified version that can reproduce the plot from scratch). –  John May 14 at 14:35
Seems like the rolling Standard deviation for the $lower$ band is slightly lagging the $SP$ ... Make sure the rolling window is the same for both the upper & lower bands –  Rime Dec 11 at 6:45