Back to Community
Simple Relative Strength Strategy is not trading - Help needed please

Hello Community,
I created a simple, long-only strategy that holds the top 3 stocks with the highest momentum over its 50-day average. In the Research Environment, my pipeline seems to work and outputs 3 stocks each day. I can't get the darn thing to actually trade in the IDE.

I've attached a notebook that contains both the research & IDE code I created.

Any help would be much appreciated.
Thank you,

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

Hello Michael,

Fix for this problem is fairly easy. On line 67 your code is

long_weight = 1 / len(context.longs)  

Which causes Python to do integer math and result get rounded down to 0. Just changing that 1 to 1.0 will allow Python to do floating point math instead of integer math and your code will run.

Clone Algorithm
4
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: 5b92e5ea9c564643b1986b18
There was a runtime error.

Wow, thank you so much Mikko. You are an absolute genius. As you can probably tell, I just learned Python this month from a Udemy course, so I'm very new to this. I really appreciate your help!