Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Iterate through Values in make_pipeline()

I'm trying to iterate through values in research in my make_pipeline() function. For instance, some pseudocode for what I'm trying to do would be like:

testingFactor = EBITDA / EV

if EV < 0 and EBITDA > 0:  
    testingFactor = - (EVITDA/ EV)  

Is there any way to do something of this manner while making my pipeline? When I try this it just changes everything, completely ignoring the if statement

2 responses

One can't really use logic in this fashion when setting up a pipeline. Remember that this is just the pipeline definition which only get's executed once (when the algo is initialized) and NOT really code which get's executed when fetching data.

The most foolproof method is to simply do this logic when the dataframe is returned (typically in the 'before_trading_start' method).

However, there are a few neat methods that factors have which could be useful in this specific case. Take a look at this post https://www.quantopian.com/posts/log-normal-return-built-in-factor . The 'abs()' method may do what you want? Something like this.

ev = Fundamentals.enterprise_value.latest  
ebitda = Fundamentals.ebitda.latest

testingFactor = ebitda / ev.abs()

Not sure if this works for you but check out the attached notebook.

Good luck.

Thanks for the info. I ended up finding a solution by simply iterating through the final dataframe created after make_pipeline(), and doing what I wanted to there.