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

Hi I am getting an issue when trying to access the average volume from USEquityPricing.volume
it is not printing out any of the corresponding volume, I'm not sure if my custom factor is setup correctly


class VolumeTV(CustomFactor): #custom factor  
    inputs =  [USEquityPricing.volume]  
    window_length = 10  
    def compute(self, today, assets,out,volume):  
       # Volume_TV=np.mean(volume,out=out, axis=0)  
       print("NP Average")  
       out[:]=Volume_TV  
    # print(np.mean(volume,out=out, axis=0))  
def make_pipeline():  
    pipe = Pipeline()  
    #attach_pipeline(pipe, name='my_pipeline')  
    #Screen out penny stocks and low liquidity securities.  
    # Prive range Factor#  
    stock_prices = PriceRange(window_length=10)  
    # Time Volume Factor#  
    TimeVolRank = VolumeTV(window_length=10)  
    print("Time volume Rank",TimeVolRank)  
    is_liquid = TimeVolRank.rank(ascending=False) < 1000  
    # Create the mask that we will use for our percentile methods.  
    volumeTV = VolumeTV()  
    base_universe = (is_liquid)  
    Current_Volume =volumeTV  
    #Average_Volume =  
    return pipe


def before_trading_start(context, data):  
    """  
    """  
    # Access results using the name passed to `attach_pipeline`.  
    results = pipeline_output('factors')  
    print results.head(5)  
1 response

Hi JC,

All you're missing is an instance of pipe.add to add your volume factor to the pipeline output. Though that's assuming the existence of some import statements, etc. which it seems you've omitted from what you've pasted here. If you want more detailed help, you can copy and paste all of your code, or share a backtest.

I'll note that there is an easier way to get average volume - just use the SimpleMovingAverage built-in factor with USEquityPricing.volume as the input.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.