Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline - Bollinger Bands CustomFactor using TA-Lib or Manually Calculated?

Hi all - looking to use Bollinger Bands to filter securities within a Pipeline. However, I am having trouble finding documentation or forum posts on whether best practice would be:

  1. Use TA-Lib in a CustomFactor
  2. Manually calculate in a CustomFactor

More importantly for calculating Bollinger Bands, how do you get data over a period of time in a pipeline custom factor to calculate standard deviation and moving average?

1 response

Try:

from quantopian.pipeline import Pipeline  
from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.factors import BollingerBands

def initialize(context):  
    my_pipe = make_pipeline()  
    attach_pipeline(my_pipe, 'my_pipeline')

def make_pipeline():  
    bb = BollingerBands(window_length=20, k=2)  
    return Pipeline(columns={  
        'bb_upper' : bb.upper,  
        'bb_middle' : bb.middle,  
        'bb_lower' : bb.lower,  
    })

def before_trading_start(context, data):  
    # Store our pipeline output DataFrame in context.  
    print pipeline_output('my_pipeline')