Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
custom pipeline factor with window_length > 1?

Based on the example on the help page, I shouldn't be getting this error. The example is:

class MyFactor(CustomFactor):  
    def compute(self, today, asset_ids, out, values):  
       out[:] = do_something_with_values(values)

def initialize(context):  
    p = attach_pipeline(Pipeline(), 'my_pipeline')  
    my_factor = MyFactor(inputs=[USEquityPricing.close], window_length=5)  
    p.add(my_factor, 'my_factor')  

Does out always need to be an array of length N, where N is the number of assets? Or can it be multi-dimensional? If it can be multi-dimensional, how can I modify my code so that it runs?

3 responses

If I modify my code like this:

class ClosePrice(CustomFactor):  
    inputs = [USEquityPricing.close]  
    window_length = 2  
    def compute(self, today, assets, out, close_price):  
        out = np.zeros_like(close_price)  
        out[:,:] = close_price  

I can eliminate the error. However, then my custom factor returns all NaN's.

So, I guess it is correct that out needs to be uni-dimensional.

Grant,
I've had similar problems. Sometimes the documentation says there is support for some pipeline output, but there is not.
Ultimately, the CustomFactors for the pipeline assign a column of a designated type value to each asset.

If you check the thread:
https://www.quantopian.com/posts/my-first-pipeline-how-to-find-stocks-with-consecutive-higher-lows-low-4-low-3-low-2-low-1
You'll see two ways of assigning values to CustomFactors.
Right now, I think they support floats, ints, and booleans, but not strings yet...at least that is what
https://www.quantopian.com/posts/int-and-boolean-types-in-pipeline
seems to indicate.

And then there is what the is what the help sez today:
https://www.quantopian.com/help#fundamental-data

It is a bit confusing for sure, because you are applying the compute() function across all rows(assets), in a seemingly parallel manner.
Good Luck!
alan

Yeah, I can't figure out from the documentation if there should be support for out[:,:] for example, or if it'll only accept out[:]. Is it a bug or not?