Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Building screeners/tops/stats

Hi guys,

I'm a newbie here ... with some basic experience using python+pandas. I understand quantopian.com is geared towards building trading algos. My main interest, for the time being, is to compute and analyse some statistics regarding intraday volatility using a dynamic universe of around 1000 stocks. I would like to build some daily tops with the stocks that have the biggest intraday range per the whole day and as well as per slices of a day open,midday, close. Can I use quantopian for this purpose. Can anyone suggest some general ideas on how to do that? I've worked with pandas before, I have some experience but it's not very clear for me how can I use quantopian's historic data and IDE to produce those stats since I don't intend to build and backtest a trading algo ... for now.

10 responses

Welcome Ovidiu,

Quantopian has some limitations in this area. You can list up to 100 securities individually in your algorithm (e.g. https://www.quantopian.com/posts/list-of-nasdaq-100-sids-to-use-in-your-algo). Alternatively, you can use the set_universe functionality described on the help page to access up to ~ 2% of the securities in the Quantopian database, however for each backtest run you are limited to a fixed range of the dollar-volume ranking.

An offline alternative which some users have applied is zipline, the open-source backtesting engine used by Quantopian. You'd need to provide your own data, but otherwise my understanding is that it is a good application (I don't have direct experience with zipline). A cool example is https://www.quantopian.com/posts/zipline-in-the-cloud-optimizing-financial-trading-algorithms.

Grant

Well ... with my own data I wouldn't need zipline. I can do it in pandas. But downloading, storing, maintaining those historic data sets is a hustle for someone that's primary a trader not a quant/programmer. I am a professional trader ... with a discretionary intraday approach and some python skills. I do not have the time to store and manage my own data sets. So ... the whole issue here is having both pandas & historic quotes data within the same space. When I discovered quntopian I was very excited thinking it was what I needed = small learning curve programming language (python/pandas) + historic data sets. Now I see the limitations make it almost useless for my needs. I don't understand why the set_universe feature is limited to dollar volume ... for example. I saw a discussion more than one year ago about how professionals make use of this filter and that just volume based filters are somehow less popular. Well ... as a professional trader I cannot agree with that. Every professional trader I know, myself included, makes use of, at least, price and average daily volume as primary filters.

Ovidiu,

Yep...presently, Quantopian is focused on launching their trading API linked to Interactive Brokers, and eventually charging a monthly fee per live algorithm (see https://www.quantopian.com/posts/paper-trading-with-interactive-brokers-open-beta-launch). A big hang-up is that they can't actually distribute the minute-level trade data, since their arrangement with their data source precludes it. Also, although not detailed by Quantopian, I get the sense that they have some infrastructure limitations--they just aren't set up yet for broad screening routines, or even running large batches of backtests with downloadable results. You basically need to have a proven algorithm that can be ported over to Python/Quantopian (or develop it by manual tweaking using the on-line backtester).

Reportedly, they will eventually offer data exploration/research capabilities, but I haven't seen a definite time frame.

Grant

I thank you for your answers Grant. Since you are only a simple user like me, more informed though and kind enough to answer my questions on a Sunday, I would still like to hear some official position from Quantopian admins/developers/owners on these issues.
Thank you again.
Ovidiu

No problem...you're welcome. Just a hobby for me at this point, and a kind of perverse break from my M-F work. --Grant

Hi Ovidiu,

FIrst off, welcome to Quantopian!

We see the current ability to set your tradable universe with dollar volume as a jumping off point. As Grant said our development queue this past year has been dominated with launching and supporting the integration with Interactive Brokers, which we just put into an open beta this month.

Extending universe selection to a wider range of pre-calculated values (and/or unlocking complete customization) is a request we have heard a lot this year - and we would love to support this use case.

Probably the best place to start to understand the requirements for you specific use case would be to see an example built upon the current set_universe() as a starting point and then go from there. If you'd like to share an example in the forums or privately I'd be happy to help iterate that with you. Or, if you'd just like to outline the logic you'd like in pseudocode we can start with that as well.

We always reply to emails sent to [email protected] or you can contact me directly at [email protected]

Best wishes,
Jess

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.

Thank you for answering back Jessica. I sent you some details to [email protected] two days ago. Did you get them?

Hi Ovidiu,

Apologies for the delay in getting back to you (because snow storm, work travel, vacation, snow storm, snow storm, in that order :) ).

I was finally able to get an example working for you here I think. Check out the attached code - this algo will start with the top 1% of stocks based on average daily dollar volume (using set_universe() ). Every day at 9:59am it ranks the universe of stocks based on their price range (high - low traded price) so far today.

It takes a parameter set in the context() method to determine what fraction of the universe to sample/buy. I've used the top 1/3 in this example. So each day at 9:59am the algo will select the top 1/3 of stocks based on their price range and make a $1,000 investment in each one. The algo is currently set up to rebalance each day at 10am, if a stock is still in the 'top' list from yesterday the position is rebalanced to $1,000 exposure, if the stock has dropped out of the screen we close out the position entirely.

I've used the record() method to plot the average price range for the stocks that make it into my top 1/3 screened 'top' list.

Disclaimer: I did not spend much (any) time on performance optimization here, I ran the attached backtest for this YTD and it was ok, I kicked a backtest off for the past 1y period and its still running... I'm sure there are a couple of ways this could be speeded up.

Hope this is a helpful start for you and anyone else interested in this type of algo. As always if anyone else finds bugs with this code please point them out!
Happy to iterate on this as well - Jess

Hi - I was trying to run this sample code but it seems the backtest engine has changed. Any idea why this error comes up please?
20 Error Runtime exception: DateParseError: 'tuple' object has no attribute 'year'

Hi Conan,

Try using this code, it uses 'history' instead of batch_transform but it should accomplish the same goal without the same errors.

Let me know if you have questions on that

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.