Hi, I have an algorithm that does a considerable amount of math and I'm getting an error message that one of the loops in the code is making the algorithm to timeout. Is it possible to get some help on how to reduce this loop since I've tried killing it once it's met some conditions but for some reason it keeps on going?
Cole S
Hey Micah, you'll need to share some code if you want help. Â Do you expect this loop to take more than 10 minutes or are you in an infinite loop? Â The only time I've hit the 10 minute mark is training models or a mistaken infinite loop. Â I can't really imagine math operations taking 10 minutes unless you are running it on a massive universe.
Â
-Cole
Micah Jesse
Micah Jesse
Hey Cole, here's the code. And I believe it's not an infinite loop unless I must have missed something that didn't account for my counters and increment statements.Â
Cole S
Hey Micah,
The problem is here. Â If len(self.highOpen) == 2 the loop will execute,but the if statement won't fire if len(self.highOpen) == 2Â and if the if block does not execute, you will never move either appendSymbol or self.highOpen forward and you have an infinite loop.
I would not use a while here. Â I would use the for loop and if check for my conditions and then if my conditions are met, I would break.Â
Â
Cole S
I noticed you are using de-spac symbols. Â I'm big into spacs and PL and CANO are two of my big holdings, would love to know what you are wanting to do with them. Â I've got some algo ideas for de-spacs around warrants but have not implemented them.
Micah Jesse
Is the problem If len(self.highOpen) == 2 or If len(self.highOpen) <= 2? Because from the code the check is wether the len(self.highOpen) is less than or equal to 2? Could you help decode this more. I’m sort of getting lost here. Also, about the spacs, I sort of hadn’t realized I was dealing with them primarily, to be honest, my goal is make some profits every time I trade in order to raise more money. Then I can start thinking of buying and holding stocks for investment purposes.Â
Cole S
Hey Micah,
It's a problem both ways. Â I think using the while loop is not a good idea here, it makes the code more confusing and harder to understand. Â I would get rid of the outer while loop rewrite it with for loops only and check conditions in the loops.
Micah Jesse
Just removed the while loop and added the appendSymbol counter to the if statement and it’s working now, but it’s adding more than 2 items in the list. Trying to check on that now….
Micah Jesse
Could you enlighten me more about the de-spacs Algo ideas?
Cole S
Well, it's just an idea based on my trading of them, I'm not sure if there is Alpha there or not. Â But the idea is to arbitrage the warrant and the common. Â I think there is enough movement and deviation in them that you could vary the position in each of them up and down as they move closer and further apart. Â The warrant usually holds a certain ratio to the common but this varies over time. Â My idea was to exploit that variance.
Micah Jesse
I haven’t had enough experience with trading so far to start working on warrants, I’m still building my analysis and findings with common stocks. You’ve got any tips you can help out with maybe?
Micah Jesse
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!