Merge branch 'develop' into plot-trades
This commit is contained in:
@@ -196,6 +196,7 @@ class Configuration:
|
||||
if self.args.get('exportfilename'):
|
||||
self._args_to_config(config, argname='exportfilename',
|
||||
logstring='Storing backtest results to {} ...')
|
||||
config['exportfilename'] = Path(config['exportfilename'])
|
||||
else:
|
||||
config['exportfilename'] = (config['user_data_dir']
|
||||
/ 'backtest_results/backtest-result.json')
|
||||
|
@@ -129,11 +129,16 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame:
|
||||
return trades
|
||||
|
||||
|
||||
def load_trades(source: str, db_url: str, exportfilename: str, skip_trades: bool) -> pd.DataFrame:
|
||||
def load_trades(source: str, db_url: str, exportfilename: Path, skip_trades: bool) -> pd.DataFrame:
|
||||
"""
|
||||
Based on configuration option "trade_source":
|
||||
* loads data from DB (using `db_url`)
|
||||
* loads data from backtestfile (using `exportfilename`)
|
||||
:param source: "DB" or "file" - specify source to load from
|
||||
:param db_url: sqlalchemy formatted url to a database
|
||||
:param exportfilename: Json file generated by backtesting
|
||||
:param skip_trades: Skip using trades, only return backtesting data columns
|
||||
:return: DataFrame containing trades
|
||||
"""
|
||||
if skip_trades:
|
||||
df = pd.DataFrame(columns=BT_DATA_COLUMNS)
|
||||
@@ -142,7 +147,7 @@ def load_trades(source: str, db_url: str, exportfilename: str, skip_trades: bool
|
||||
if source == "DB":
|
||||
return load_trades_from_db(db_url)
|
||||
elif source == "file":
|
||||
return load_backtest_data(Path(exportfilename))
|
||||
return load_backtest_data(exportfilename)
|
||||
|
||||
|
||||
def extract_trades_of_period(dataframe: pd.DataFrame, trades: pd.DataFrame) -> pd.DataFrame:
|
||||
|
@@ -421,7 +421,7 @@ class Backtesting:
|
||||
for strategy, results in all_results.items():
|
||||
|
||||
if self.config.get('export', False):
|
||||
self._store_backtest_result(Path(self.config['exportfilename']), results,
|
||||
self._store_backtest_result(self.config['exportfilename'], results,
|
||||
strategy if len(self.strategylist) > 1 else None)
|
||||
|
||||
print(f"Result for strategy {strategy}")
|
||||
|
Reference in New Issue
Block a user