Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Selecting of a universe based on daily traded volume and higher stock price

Hello Everyone,
I am new to Quantopian, and new to Python as well. I am trying to build an algorithm that will determine a set of action based on a set of stock that satisfy the following criteria but don't know how to start
- Daily traded volume higher than 100k (for 3 consecutive day)
- Traded stock price is higher than the latest 30 days average price. Let's say 10% higher

Could you please let me know if is possible to select the right stocks with the above critera using current API on Quanopian?

Thank you very much for your help
Ly

8 responses

Hi Ly,

Welcome to Quantopian, we're glad to have you!

I've attached some code that follows your criteria. One caveat is you cannot select a customized basket of US stocks. We let you select 2% of the stocks (based on volume) for backtests in minute mode and 10% of stocks for backtests in daily mode. Thus, your stocks will be grouped based on their dollar-volume. For more info see here.

Try cloning the attach algo and playing around with the set_universe() and other functions. And feel free to keep asking questions!

Best,
Alisa

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.

Alisa and Ly,

My understanding is and per the help page, the set_universe ranking is by dollar-volume, not volume.

Cheers,

Grant

Hi Grant,

You're absolutely right! Thanks for the great catch - I'll go ahead and edit that.

Always appreciate it.

Hi Alisa and Grant,
Thanks for the answers. I was having the impression that the set_universe ranking will outbid the stocks that have higher volume, but lower price by stock with higher price, but less volume (e.g. a stock with 1M in volume, but 1$ price will not be ranked as high has the stock with 100k in volume, but $11 in price). Is that correct?

Another point that I don't seem to understand the purpose of the line below

track the volume history for 3 days

volume_history = history(bar_count=3, frequency='1d', field='volume')

Does that line track the volume history for a specific stock (I don't see the stock ID in the command) or which volume history it is referring to?

Thanks,
Lely

Hi Ly,

You're correct, since set_universe is based on dollar-volume the stock with 1M in volume and $1 price will be ranked higher.

The volume_history line tracks the volume history for 3 days of all the stocks in the specified set_universe. I wrote 3 days based on your criteria "Daily traded volume higher than 100k (for 3 consecutive day)".

Hope that clarifies things!

Alisa

Thanks Alisa. Is there any way to extract individual stock from a set_universe and check for their volume history separately?

Hello Alisa and Ly,

You might have a look at the details of what the history API returns according to the help page:

Returned Data

The returned data for daily history, for each day, is:

close_price: the close of the last minute bar for that day. For the current day, the most recent close is returned.  
price: same as close_price.  
open_price: the open of the first minute bar of the given day.  
volume: the sum of all minute volumes. For the current day, the sum of volume thus far.  
high: the max of the minute highs for the given day.  
low: the min of the minute bar lows for the given day.

So, volume_history = history(bar_count=3, frequency='1d', field='volume') doesn't track the volume history for three days, but rather two, plus cumulative volume data for the current day. Correct?

Grant

Hi Grant,

Absolutely - great catch and astute reading! Always appreciative of an extra set of eyes and a helping hand.

To clarify for anyone following the thread, if you want to track 5 consecutive days of volume history, you will need to set the bar_count to 6 because this behavior.