Update webserver backtseting to reuse prior results
This commit is contained in:
parent
e9baabce6f
commit
a6c7f45545
@ -752,17 +752,7 @@ class Backtesting:
|
|||||||
min_backtest_date = datetime.now(tz=timezone.utc) - timedelta(weeks=4)
|
min_backtest_date = datetime.now(tz=timezone.utc) - timedelta(weeks=4)
|
||||||
return min_backtest_date
|
return min_backtest_date
|
||||||
|
|
||||||
def start(self) -> None:
|
def load_prior_backtest(self):
|
||||||
"""
|
|
||||||
Run backtesting end-to-end
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
data: Dict[str, Any] = {}
|
|
||||||
|
|
||||||
data, timerange = self.load_bt_data()
|
|
||||||
self.load_bt_data_detail()
|
|
||||||
logger.info("Dataload complete. Calculating indicators")
|
|
||||||
|
|
||||||
self.run_ids = {
|
self.run_ids = {
|
||||||
strategy.get_strategy_name(): get_strategy_run_id(strategy)
|
strategy.get_strategy_name(): get_strategy_run_id(strategy)
|
||||||
for strategy in self.strategylist
|
for strategy in self.strategylist
|
||||||
@ -775,6 +765,19 @@ class Backtesting:
|
|||||||
self.results = find_existing_backtest_stats(
|
self.results = find_existing_backtest_stats(
|
||||||
self.config['user_data_dir'] / 'backtest_results', self.run_ids, min_backtest_date)
|
self.config['user_data_dir'] / 'backtest_results', self.run_ids, min_backtest_date)
|
||||||
|
|
||||||
|
def start(self) -> None:
|
||||||
|
"""
|
||||||
|
Run backtesting end-to-end
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
data: Dict[str, Any] = {}
|
||||||
|
|
||||||
|
data, timerange = self.load_bt_data()
|
||||||
|
self.load_bt_data_detail()
|
||||||
|
logger.info("Dataload complete. Calculating indicators")
|
||||||
|
|
||||||
|
self.load_prior_backtest()
|
||||||
|
|
||||||
for strat in self.strategylist:
|
for strat in self.strategylist:
|
||||||
if self.results and strat.get_strategy_name() in self.results['strategy']:
|
if self.results and strat.get_strategy_name() in self.results['strategy']:
|
||||||
# When previous result hash matches - reuse that result and skip backtesting.
|
# When previous result hash matches - reuse that result and skip backtesting.
|
||||||
|
@ -77,7 +77,15 @@ async def api_start_backtest(bt_settings: BacktestRequest, background_tasks: Bac
|
|||||||
lastconfig['enable_protections'] = btconfig.get('enable_protections')
|
lastconfig['enable_protections'] = btconfig.get('enable_protections')
|
||||||
lastconfig['dry_run_wallet'] = btconfig.get('dry_run_wallet')
|
lastconfig['dry_run_wallet'] = btconfig.get('dry_run_wallet')
|
||||||
|
|
||||||
|
ApiServer._bt.results = {}
|
||||||
|
ApiServer._bt.load_prior_backtest()
|
||||||
|
|
||||||
ApiServer._bt.abort = False
|
ApiServer._bt.abort = False
|
||||||
|
if (ApiServer._bt.results and
|
||||||
|
strat.get_strategy_name() in ApiServer._bt.results['strategy']):
|
||||||
|
# When previous result hash matches - reuse that result and skip backtesting.
|
||||||
|
logger.info(f'Reusing result of previous backtest for {strat.get_strategy_name()}')
|
||||||
|
else:
|
||||||
min_date, max_date = ApiServer._bt.backtest_one_strategy(
|
min_date, max_date = ApiServer._bt.backtest_one_strategy(
|
||||||
strat, ApiServer._bt_data, ApiServer._bt_timerange)
|
strat, ApiServer._bt_data, ApiServer._bt_timerange)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user