Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to select stocks Dynamicly

hello , i want to know how to select stocks Dynamicly . For example. I want to select the stocks which is 10% high than its today openrice. I do not know how to do it . 3Q

4 responses

I suggest having a look at the history() API in the help docs (see https://www.quantopian.com/help#ide-history). In particular, note:

Day Units

"d" suffix to the frequency parameter. The dataframe returned is always in daily bars. The bars never span more than one trading day.
Examples:
history(1, "1d", "price") returns the current price.
history(1, "1d", "volume") returns the volume since the current day's open, even if it is partial.
history(2, "1d", "price") returns yesterday's close price and the current price.
history(6, "1d", "price") returns the prices for the previous 5 days and the current price.
Partial trading days are treated as a single day unit. Scheduled half day sessions, unplanned early closures for unusual circumstances, and other truncated sessions are each treated as a single trading day.

and,

open_price: the open of the first minute bar of the given day.

So, you get access to trailing daily bars, plus the open for the current day, and the current minute bar.

thank you very much .My mother language is not Englis ,Maybe I can not explain it very clearly yesterday. I know the history API .But ,i mean ,how can i choose the stock Dynamicly in the handle_data() function ,not in the initialize(context) function . In the initialize() function ,I do not know which stock will be choosed . I want to duiring the handle_data() function, I choose some stocks ,which is much higher than its today open_price.

Here's an example. Is this the sort of thing you are trying to do? --Grant

Here is the same algo that Grant posted, but it uses the set_universe feature rather than a fixed basket of stocks. I think a dynamic universe is what you are looking for, as of right now, set_universe and before_trading_start are the two ways that you can implement a dynamic universe.

David