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

Hello all,

I am trying to include both end of day and intraday data in a CustomFactor. Is there an example of this?

Even more simply, I am not clear on how any intraday data can get into the calculation. The sample below shows that creating a variable based on price_close = USEquityPricing.close.latest up in the make_pipeline() method does not get updated throughout the day.

Thanks,

Ted

6 responses

USEquityPricing.close.latest refers to the close price of the previous day - so it won't change throughout the current day.

If you want to get current pricing on a minute basis you should use data.current as referenced in this tutorial

Pipelines are meant to be computed on the order of once a day for security selection (the values in pipeline only uses daily data as recent as the previous trading day)

Hopes this helps!
Matt

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.

Matthew,

Thank you for your response. So Pipeline is designed to calculate factors once a day using historical daily data? OK. How do I calculate a factor using intraday data? Is there an example?

Best regards,

Ted

Yes, the pipeline is designed for calculating things once per day using historical daily data.

So - if you scheduled a function to run every 30 minutes and wanted to trade based on some information, you should use the data object.
A quick example of getting the most recent price of APPL as shown in the tutorial would be

data.current(sid(24), 'price')

Besides price, what other kinds of intraday data are you interested in computing?

Data would be average price performance and average volume over a window of several days. But I wanted to include the intraday price performance and volume within the factor.

I had hoped that something like:

price_history = data.history(context.securities, "price", bar_count=20, frequency="1d")  
volume_history = data.history(context.securities, "volume", bar_count=20, frequency="1d")

would get me access to the data I needed, for both historical days and current day. I was looking for an example of how to use that data in a screen at 3:50 pm ET.

You could generate some data within the pipeline, then do other filtering outside of the pipeline.

For example - you could do all your regular filtering based off historical data in the pipeline.

Then, when you order stocks (at a higher frequency) you could check a condition like

if data.current(sid(24), 'price') > x:  
    do something  

in the scheduled function

Is there an algorithm implementing that strategy -- either in the Quantopian examples or forum posts -- that you could point me towards?