Move store_backtest_results to optimize_reports
This commit is contained in:
parent
328dbd3930
commit
6106d59e1a
@ -6,7 +6,6 @@ This module contains the backtesting logic
|
|||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
|
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
@ -134,23 +133,6 @@ class Backtesting:
|
|||||||
|
|
||||||
return data, timerange
|
return data, timerange
|
||||||
|
|
||||||
def _store_backtest_result(self, recordfilename: Path, results: DataFrame,
|
|
||||||
strategyname: Optional[str] = None) -> None:
|
|
||||||
|
|
||||||
records = [(t.pair, t.profit_percent, t.open_time.timestamp(),
|
|
||||||
t.close_time.timestamp(), t.open_index - 1, t.trade_duration,
|
|
||||||
t.open_rate, t.close_rate, t.open_at_end, t.sell_reason.value)
|
|
||||||
for index, t in results.iterrows()]
|
|
||||||
|
|
||||||
if records:
|
|
||||||
if strategyname:
|
|
||||||
# Inject strategyname to filename
|
|
||||||
recordfilename = Path.joinpath(
|
|
||||||
recordfilename.parent,
|
|
||||||
f'{recordfilename.stem}-{strategyname}').with_suffix(recordfilename.suffix)
|
|
||||||
logger.info(f'Dumping backtest results to {recordfilename}')
|
|
||||||
file_dump_json(recordfilename, records)
|
|
||||||
|
|
||||||
def _get_ohlcv_as_lists(self, processed: Dict) -> Dict[str, DataFrame]:
|
def _get_ohlcv_as_lists(self, processed: Dict) -> Dict[str, DataFrame]:
|
||||||
"""
|
"""
|
||||||
Helper function to convert a processed dataframes into lists for performance reasons.
|
Helper function to convert a processed dataframes into lists for performance reasons.
|
||||||
|
@ -1,9 +1,33 @@
|
|||||||
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Dict
|
from pathlib import Path
|
||||||
|
from typing import Dict, Optional
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
|
from freqtrade.misc import file_dump_json
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def store_backtest_result(recordfilename: Path, results: DataFrame,
|
||||||
|
strategyname: Optional[str] = None) -> None:
|
||||||
|
|
||||||
|
records = [(t.pair, t.profit_percent, t.open_time.timestamp(),
|
||||||
|
t.close_time.timestamp(), t.open_index - 1, t.trade_duration,
|
||||||
|
t.open_rate, t.close_rate, t.open_at_end, t.sell_reason.value)
|
||||||
|
for index, t in results.iterrows()]
|
||||||
|
|
||||||
|
if records:
|
||||||
|
if strategyname:
|
||||||
|
# Inject strategyname to filename
|
||||||
|
recordfilename = Path.joinpath(
|
||||||
|
recordfilename.parent,
|
||||||
|
f'{recordfilename.stem}-{strategyname}').with_suffix(recordfilename.suffix)
|
||||||
|
logger.info(f'Dumping backtest results to {recordfilename}')
|
||||||
|
file_dump_json(recordfilename, records)
|
||||||
|
|
||||||
|
|
||||||
def generate_text_table(data: Dict[str, Dict], stake_currency: str, max_open_trades: int,
|
def generate_text_table(data: Dict[str, Dict], stake_currency: str, max_open_trades: int,
|
||||||
results: DataFrame, skip_nan: bool = False) -> str:
|
results: DataFrame, skip_nan: bool = False) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user