Anyone else have problems with the new rolling.std()in pandas? The outdated method was rolling_std(). The new method works fine, but creates a constant number that does not roll with time series.
The following is sample code. If you trade stocks, you can recognize the formula for Bollinger Bands. The output I get from rolling.std()tracks stocks day after day and obviously does not work.
This is in pandas 0.19.1. Any help would be greatly appreciated.
import datetime
import pandas as pd
import pandas_datareader.data as web
start = datetime.datetime(2012,1,1)
end = datetime.datetime(2012,12,31)
g = web.DataReader(['AAPL'], 'yahoo', start, end)
stocks = g['Close']
stocks['Date'] = pd.to_datetime(stocks.index)
stocks['AAPL_LO'] = stocks['AAPL'] - stocks['AAPL'].rolling(20).std() * 2
stocks['AAPL_HI'] = stocks['AAPL'] + stocks['AAPL'].rolling(20).std() * 2
stocks.dropna(axis=0, how='any', inplace=True)
source
share