Back to Community
Custom Factor using "open"

Hello,

How do you make a custom factor using the "open" as the input? Can any body show with an example?

Thanks

2 responses

hey, here is are some examples:

from quantopian.pipeline import CustomFactor, Pipeline  
import numpy

class StdDev(CustomFactor):  
    def compute(self, today, asset_ids, out, values):  
        # Calculates the column-wise standard deviation, ignoring NaNs  
        out[:] = numpy.nanstd(values, axis=0)

class AverageRange(CustomFactor):  
     inputs=[USEquityPricing.open, USEquityPricing.close]  
    def compute(self, today, asset_ids, out, opn, clse):  
        out[:] = np.nanmean(abs(clse-opn), axis=0)

def make_pipeline():  
    std_dev = StdDev(  
        inputs=[USEquityPricing.open],  
        window_length=5  
    )

    avg_rng= AverageRange(  
        window_length=5  
    )

    return Pipeline(  
        columns={  
            'std_dev': std_dev,  
            'avg_rng': avg_rng  
        }  
    )

result = run_pipeline(make_pipeline(), '2018-10-31', '2019-10-31')  
result.head()  

Thank you very much Mathieu.