Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Do talib functions not work in research?

I am trying going through the tutorials right now very slowly so I can learn exactly how everything processes. However, I am at the point where it shows you how to make simple moving averages of everything in the pipeline. I am trying to make a ema using the talib function but it won't work. I keep getting a securityviolation error on the line when i try to make the ema.

from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters import QTradableStocksUS
from quantopian.pipeline.factors import SimpleMovingAverage
import talib

def make_pipeline():

mean_close_10 = SimpleMovingAverage(  
    inputs=[USEquityPricing.close],  
    window_length=10  
)  
mean_close_30 = SimpleMovingAverage(  
inputs=[USEquityPricing.close],  
window_length=30  
)  
percent_difference = (mean_close_10 - mean_close_30) / mean_close_30  
return Pipeline(  
    columns={  
        'percent_difference': percent_difference  
    }  
)  

mean_crossover_filter = mean_close_10 < mean_close_30
em8 = talib.ema(usequitypricing.close, 8)
my_pipe = make_pipeline()
result = run_pipeline(my_pipe, '2015-05-05','2015-05-05')
result.head()

1 response

Yes the talib libraries work in the research notebooks. They just can't be used to define pipeline calculations unless one codes a CustomFactor.

The problem is with the statement

em8 = talib.ema(usequitypricing.close, 8)

The ema function expects a numpy array of prices as the first parameter. The 'usequitypricing.close' object is a 'BoundColumn' object (see https://www.quantopian.com/help#zipline_pipeline_data_dataset_BoundColumn ). The key to understanding pipelines is the code only defines what the columns are (eg the factors) and what rows are returned (ie the screen). One isn't doing the actual calculations at this point.

Without getting into the specifics, if one wishes to use an ema calculation in defining a pipeline, look at the built in factor ExponentialWeightedMovingAverage (look under https://www.quantopian.com/help#built-in-factors). Another approach if more customization is needed would be to define a CustomFactor. The talib functions can be used inside this factor ( see https://www.quantopian.com/posts/using-ta-lib-functions-in-pipeline )

Hope that helps a little bit.