Help!!
-
Hi guys, it's been a couple days for me to start backtrader, before then I used zipline from Quantopian or bt (not backtrader, but the other one)..
Obviously, this is one of the most comprehensive open source backtesting platform, but I don't know why I really confused with the codes.. So instead of building my sklearn indicators inside the system, I use my extended datafeed, but failed to feed it into the system......
Can somebody help me to give example how feed the extended code and build the signals? I have read all the documentation, including extending datafeed but always failed to test it. Here's my datafeed, the idea is I'll buy when daily mean states > 0 and sell when daily mean states < 0. Thanks
-
See for example here:
class CustomDataLoader(btfeeds.PandasData): lines = ('TOTAL_SCORE','Beta',) params = ( ('openinterest',None), #None= column not present ('TOTAL_SCORE',-1), ('Beta',-1) ) datafields = btfeeds.PandasData.datafields + (['TOTAL_SCORE','Beta'])
and here
class PandasDataOptix(btfeeds.PandasData): lines = ('optix_close', 'optix_pess', 'optix_opt',) params = (('optix_close', -1), ('optix_pess', -1), ('optix_opt', -1)) datafields = btfeeds.PandasData.datafields + (
You have to add the name of your extra lines to the
lines
definition and extend thedatafields
definition.Once you have the lines available you only have to check in
next
:def next(self): if self.data.states > 0: self.buy()
Where of course, position management may also play a role.