Fixed: self.use_backslap = Bool on line97

If self.use_backslap = True   Backslap executes
If self.use_backslap = False  Original Backtest Code executes
This commit is contained in:
creslinux 2018-07-16 15:57:15 +00:00
parent 5aaf454f12
commit 4a39a754f4

View File

@ -94,12 +94,12 @@ class Backtesting(object):
self.np_sto: int = self.np_close # stops_triggered_on - Should be low, FT uses close self.np_sto: int = self.np_close # stops_triggered_on - Should be low, FT uses close
self.np_sco: int = self.np_close # stops_calculated_on - Should be stop, FT uses close self.np_sco: int = self.np_close # stops_calculated_on - Should be stop, FT uses close
self.use_backslap = True # Enable backslap self.use_backslap = True # Enable backslap - if false Orginal code is executed.
self.debug = True # Main debug enable, very print heavy, enable 2 loops recommended self.debug = True # Main debug enable, very print heavy, enable 2 loops recommended
self.debug_timing = False # Stages within Backslap self.debug_timing = False # Stages within Backslap
self.debug_2loops = False # Limit each pair to two loops, useful when debugging self.debug_2loops = False # Limit each pair to two loops, useful when debugging
self.debug_vector = True # Debug vector calcs self.debug_vector = True # Debug vector calcs
self.debug_timing_main_loop = False # print overall timing per pair self.debug_timing_main_loop = False # print overall timing per pair - works in Backtest and Backslap
@staticmethod @staticmethod
@ -245,6 +245,10 @@ class Backtesting(object):
:return: DataFrame :return: DataFrame
""" """
use_backslap = self.use_backslap
debug_timing = self.debug_timing_main_loop
if use_backslap: # Use Back Slap code
headers = ['date', 'buy', 'open', 'close', 'sell', 'high', 'low'] headers = ['date', 'buy', 'open', 'close', 'sell', 'high', 'low']
processed = args['processed'] processed = args['processed']
@ -253,10 +257,6 @@ class Backtesting(object):
trades = [] trades = []
trade_count_lock: Dict = {} trade_count_lock: Dict = {}
use_backslap = self.use_backslap
debug_timing = self.debug_timing_main_loop
if use_backslap: # Use Back Slap code
########################### Call out BSlap Loop instead of Original BT code ########################### Call out BSlap Loop instead of Original BT code
bslap_results: list = [] bslap_results: list = []
for pair, pair_data in processed.items(): for pair, pair_data in processed.items():
@ -304,6 +304,13 @@ class Backtesting(object):
else: # use Original Back test code else: # use Original Back test code
########################## Original BT loop ########################## Original BT loop
headers = ['date', 'buy', 'open', 'close', 'sell']
processed = args['processed']
max_open_trades = args.get('max_open_trades', 0)
realistic = args.get('realistic', False)
trades = []
trade_count_lock: Dict = {}
for pair, pair_data in processed.items(): for pair, pair_data in processed.items():
if debug_timing: # Start timer if debug_timing: # Start timer
fl = self.s() fl = self.s()
@ -1035,6 +1042,7 @@ class Backtesting(object):
if self.config.get('export', False): if self.config.get('export', False):
self._store_backtest_result(self.config.get('exportfilename'), results) self._store_backtest_result(self.config.get('exportfilename'), results)
if self.use_backslap:
logger.info( logger.info(
'\n====================================================== ' '\n====================================================== '
'BackSLAP REPORT' 'BackSLAP REPORT'
@ -1045,6 +1053,17 @@ class Backtesting(object):
results results
) )
) )
else:
logger.info(
'\n================================================= '
'BACKTEST REPORT'
' ==================================================\n'
'%s',
self._generate_text_table(
data,
results
)
)
## TODO. Catch open trades for this report. ## TODO. Catch open trades for this report.
# logger.info( # logger.info(