Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Getting Percentile of Custom Factor

Hey everybody, I'm attempting to get the percentile of a custom factor over a certain timeframe and I'm having some issues.

Whenever I run the cell, my Percentile column gets some extremely long numbers. The only way to fix this issue is to add a screen=screens to the row where I define ppop= PPOPercentile() . I'm just attempting to find the percentile of the PPO over the past year for a given asset in pipeline. Right now I'm limiting the output to just AAPL as I am trying to just show how the pipeline works, but I would eventually like to run it over a multitude of securities. Any help would be appreciated.

2 responses

Hi Matthew,

Please change

out[:] = stats.percentileofscore(ppo,ppo[-1],'mean')  

in compute() function of your PPOPercentile CustomFactor
to

ppo =  np.array(ppo)  
out[:] = np.array([ stats.percentileofscore(ppoarr[:,i],v,'mean') for i,v in enumerate(ppo[-1])])

What I think happens is that the compute on the CustomFactor is called on all assets (before the screening is done), since there is no screen in the definition of the CustomFactor itself.
So in your original code, self.ema(close,12) and self.ema(close,26) are arrays with 1 row and number of assets columns and ppo is a list of arrays.
Just accounting for that in your percentile calculation above.

Awesome! Worked like a charm!

I am having a little bit of an issue understanding why this is occurring though? How come pipeline executes this way and is there a way to check something like this?

I've always found it difficult to debug pipeline because it either works, works incorrectly, or throws an error, making it hard to see how it is outputting data so I can then attempt to fix the problem myself.