Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Bull or Bear, not too complicated

Simple idea: if the price and volume move in the same direction, the market is bullish; otherwise the market is bearish. Therefore, we should buy when both price and volume are increasing and sell when both are decreasing.

Implementation is also intuitive, except for the fact that there is no "open_volume" parameter so we need to set a global variable to store the values of trading volumes.

Note the risk performance is not bad for this algo.

5 responses

could we change it to just the SPY but also have it trade short when markets fall? because unless you know that the certain stocks you picked will performance better then the SPY its hard to examine a lagging indicator

@James: sorry could you please explain a bit further what is the lagging indicator? I don't really understand why and how we should use SPY but would be willing to try it out! Thanks for your idea!

in using the SPY over individual stocks, we can see trading if it where to trade the entire 500 stocks. if we only apply this too a few stocks we would need to find stocks that are strong to begin with. In regards to it being a lagging indicator, what i mean is when applied to the SPY it is chasing the index, probalpy because of the use of last, and not current price and volume. also is it possible to write a code that limits buying power? or possibly buy max amount of shares when all criteria is met, and short when all criteria is met?

@ James: OK I see.

In choosing stocks to buy, I believe Quantopian is going to release a new method that gives you more information to make such choices - I have to say in this algorithm I arbitrarily set the portfolio to be the seven stocks.

As for limiting purchasing power, I think we can use the notional idea discussed in the sample algorithm here. We stop buying / selling after the limit is reached.

Was that what you thought of? Please share more insights here. Thanks!

my idea was to buy all or even half of the buying power when the algorithm states to buy, and when your algorithm gives a sell signal, it would then sell off the entire position in one shot, and go short. this would lead to a higher volatility but I think it will generate a higher alpha and sharp.