Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help needed debug my algorithm, no stock output

Hi,

I'm new to Quantopian, and this is my first algorithm for the SMA crossover strategy. I can see the result stocks from my pipeline in the notebook, but when I copy over to algorithm and try backtest, there seems no stocks purchase or rebalance.

Can anyone review my code and help out? Thanks!

Ryan

3 responses

Hello Ryan,

Your algorithm actually buys stocks. However the criteria for buys is really tight, which means there isn't that many stocks passing buying filters. See here, I ran backtest from 2016-09-01 to 2017-10-04 and only got two days of trading activity.

Hi Mikko,

Thanks for reply!

I also attached my notebook, which uses the same criteria as my algorithm.
However you can see there are lot stocks generated from each day.
So I still think there must be something wrong when I move it over from the notebook to the algorithm.

Ryan

Figured this out by myself....

In my original algorithm, I set
long_weight = 1 / len(context.longs)
and the result is int, that's why the weight is always 0.

So I changed it to
long_weight = 1.0 / len(context.longs)
and the result is float.