Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

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)
sp = web.DataReader('^GSPC','yahoo', start, end) 
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)

enter image description here

share|improve this question
    
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
2  
@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

1 Answer 1

Try to plot the rolling mean against your quotes for SP and see if it makes sense. Although you line of code to compute the rolling mean is correct, there might be something wrong in the data that you pass as input.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.