optimization with percentrank
Dear Backtrader community,
I have implemented a strategy that uses the indicator bt.indicators.PercentRank(). When running optimization on this strategy, I get the following error message? Any idea/suggestions on how to go around this issue?
Thanks and regards,
multiprocessing.pool.MaybeEncodingError: Error sending result: '[<strategies.XXXStrategy object at 0x000002D1A61754A8>]'. Reason: 'PicklingError("Can't pickle <function PercentRank.<lambda> at 0x000002D1A716A510>: attribute lookup PercentRank.<lambda> on backtrader.indicators.percentrank failed")'
Pickling fails sometimes depending on the ordering of things in a module (there is a long list of things why pickling can fail).
It seems the default lambda definition is not compatible with pickling. Define another
funcas the parameter to
PercentRankand it may work.
This is the default definition:
lambda d: fsum(x < d[-1] for x in d) / len(d))
Hi, this is what I have done and indeed it works. Mysteries of pickle! thanks a lot