Back to Community
OHLC4 data for feeding BollingerBand factor

Hi all,

I have been wondering about how to use OHLC4 (open + high + low + close) / 4 data into the builtin Bollinger Band factor, which uses the USEquityPricing.close by default. A community guy has given me a hint that a custom_factor should be used for the purpose but I for some reason I am having an issue.

Ps. I am avoiding the get_pricing function and would like to feed the code with the USEquityPricing pipeline data to easily apply it on the Q1500US universe.

Any help would be extremely appreciated.

Regards,
Mihail

Loading notebook preview...
Notebook previews are currently unavailable.
6 responses

Try this:

class OHLC4(CustomFactor):  
    inputs = [USEquityPricing.high, USEquityPricing.low, USEquityPricing.close, USEquityPricing.open]  
    window_safe=True  
    def compute(self, today, assets, out, high, low, close, open):  
        out[:] = np.mean(open + high + low + close, axis=0) / 4  
def custom_pipeline(context):

    m = QTradableStocksUS()

    bband = BollingerBands(inputs=[OHLC4(window_length=6, mask=m)], window_length=20, k=2)  
    low_bb = bband.lower  
    high_bb = bband.upper  
    alpha = low_bb / high_bb  

Hi Daniel,

thanks for the time spent. I believe that

out[:] = np.mean(open + high + low + close, axis=0) / 4  

has to be

out[:] = np.mean(open + high + low + close, axis=1)  

to perform (open + high + close + low)/4, am I right?

Nevertheless, I tried but failed to make the custom factor OHLC4 work... feel free to check the notebook attached

Loading notebook preview...
Notebook previews are currently unavailable.

Hi Mihail,

Try this:

class OHLC4(CustomFactor):  
    inputs = [USEquityPricing.high, USEquityPricing.low, USEquityPricing.close, USEquityPricing.open]  
    window_length = 2  
    window_safe=True  
    def compute(self, today, assets, out, high, low, close, open):  
        out[:] = (open[-1] + high[-1] + low[-1] + close[-1]) / 4.0

def custom_pipeline(context):

    m = QTradableStocksUS()

    bband = BollingerBands(inputs=[OHLC4(mask=m)], window_length=20, k=2)  
    low_bb = bband.lower  
    high_bb = bband.upper  
    alpha = low_bb / high_bb  

Thanks, James,

But does not seem to work that way either....

Error is Custom_factor not defined..

Attach is NB. You need to add the modules that need to be imported into the NB. Hopes this helps.

Loading notebook preview...
Notebook previews are currently unavailable.

Sir, you are THE man!

Thanks alot!