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

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59de7260531e8653e3580eec
There was a runtime error.
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.

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59deb1063790dd40aad79314
There was a runtime error.

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

Loading notebook preview...
Notebook previews are currently unavailable.

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.

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59df12fe2c2c49458a506500
There was a runtime error.