How to stop ZeroDivisionError on a single optimization process?
I am trying to optimize my strategy which uses trailstop during various periods of times. In most of the periods, the optimization is working fine but in some cases, it raises ZDE. I can't figure out why this is happening, but just for an easy workaround I want to just skip that exact parameter combination which leads to the ZDE. How do I do this?
@zuj The only thing that I'm varying is trailpercent in self.order_target_percent(d, target=self.perctarget, exectype=bt.Order.StopTrail, trailpercent=self.p.trailpercent)
during optimization. It is working for trailpercent = 0.01,0.03 but throws the ZDE at trailpercent =0.05. What is happening?
vladisld last edited by
@zuj could you please post the full backtrace of the exception? ( I assume the exception is raised inside the backtrader code, right ?)
@vladisld I changed my code to adapt to the error so I can't post the exact trace now but I remember it happening in the multiprocessing module: float Division by zero error. But I figured out that trailpercent wasn't the issue. ADX was probably causing some error unexpectedly, it doesn't have any safediv param either. I don't know why it happened on a subset of the data but never on the whole data.
Besides, the StopTrail is causing problems too, I thought that if I set the trailpercent=1, then it would just be the normal execution without any stoptrail getting executed because it lags by 100% of the price so why is it making my returns so negative as compared to my returns without using stoptrails? Shouldn't they be the same?