backtrader_plotting
backtrader_plotting copied to clipboard
Fixed running with multiple different strategies...
Fixed running with multiple different strategies using StFetcher (tested custom strategy and BuyAndHold backtrader test strategy); fixed plotting in Pycharm (iplot was set by default)
Example code with running multiple strategies: strategy_params is a dict of custom parameters:
strategy_params = dict(fast=range(20, 30, 4),
slow=range(20, 30, 4),)
class StFetcher(object):
_STRATS = [] #list of dicts(key=strategy,value=kwargs)
def __new__(cls, *args, **kwargs):
idx = kwargs.pop('idx')
(key, value), = cls._STRATS[idx].items()
obj = key(*args, **{**kwargs, **value})
return obj
StFetcher._STRATS = [{SMACrossLongShort: strategy_params},
{BuyAndHold_Buy: strategy_params}] #actually it should be an empty dict
cerebro.optstrategy(StFetcher, idx=[0, 1])
bo = Bokeh()
browser = OptBrowser(bo, optimized_runs)
browser.start(iplot=False)


The best-case scenario would be to create multiple tables for the number of strategy types we have, but it is better done than perfect.
I needed to compare my SMA cross strategy with BuyAndHold strategy and the pull request will allow others to do the same.
Hi do you have any idea why when I use two shares to plot a realistic plot (like in Pairtrading algo) sell and buy arrows only show on one of the plots?
Thanks
Sorry, I am quite busy with other projects at the moment. Tbh I don't understand what problem this PR fixes.
Also is it intended to comment out the source code printing from the meta tab?
Whats wrong with plotting in PyCharm? I used to use PyCharm myself and didn't notice that plotting didn't work.