Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
CustomFactor returning NaN for specific days using daily HLC data only

Hi Quants

First of all, I'm new to both Quantopian and object-oriented programming so I might have overlooked (not been aware of) something very basic, my apologies.
However, the challenge that I'm facing is that my CustomFactor for calculating the parabolic SAR value for all Q1500US securities does not work on specific dates, e.g. 2014-05-06.

I can't seem to figure out why the custom factor returns only nan values for this date as there should be same (amount of) daily high, low, and close data available on this very date as on e.g. 2014-05-05 which works fine.

Any help, tips and tricks, code comments or whatsoever is very much appreciated.

FYI: I know that this trading "strategy" is not profitable. I just want to get a grip on the process of creating and testing custom factors.

2 responses

The error message is misleading. The problem is the following statement in your custom factor

        out[:] = close[-1] - talib.SAR(high.max(axis=0), low.min(axis=0), acceleration=0.03, maximum=0.2)

Specifically the problem is with the 'talib.SAR' reference. If you comment out that portion of the code then the pipeline runs fine. Something like this

       out[:] = close[-1] #- talib.SAR(high.max(axis=0), low.min(axis=0), acceleration=0.03, maximum=0.2)

The error probably relates to the ta-lib function not liking NaNs. However, the bigger issue is that you will need to iterate over the securities when using the ta-lib functions. Out of the box, the ta-lib functions expect single arrays of data representing a single security. Maybe take a look at this post for how to implement the ta-lib functions within a custom factor https://www.quantopian.com/posts/using-ta-lib-functions-in-pipeline

Good luck.

Hi Dan Whitnable

I forgot to reply and thank you for your comment - it worked out when taking into account the NaNs!