Implement startup-period to default-strategy

This commit is contained in:
Matthias 2019-10-23 17:57:38 +02:00
parent 704121c197
commit 6382a4cd04
3 changed files with 16 additions and 9 deletions

View File

@ -421,7 +421,6 @@ class Backtesting:
timerange = TimeRange.parse_timerange(None if self.config.get(
'timerange') is None else str(self.config.get('timerange')))
data = history.load_data(
datadir=Path(self.config['datadir']),
pairs=pairs,
@ -447,9 +446,11 @@ class Backtesting:
'Loading backtest data from %s up to %s (%s days)..',
min_date.isoformat(), max_date.isoformat(), (max_date - min_date).days
)
if not timerange.starttype:
# If no startts was defined, we need to move the backtesting start
logger.info("Moving start-date by %s candles.", self.required_startup)
if (not timerange.starttype or (self.required_startup
and min_date.timestamp == timerange.startts)):
# If no startts was defined, or test-data starts at the defined test-date
logger.warning("Moving start-date by %s candles to account for startup time.",
self.required_startup)
timerange.startts = (min_date.timestamp
+ timeframe_to_seconds(self.ticker_interval)
* self.required_startup)

View File

@ -39,6 +39,9 @@ class DefaultStrategy(IStrategy):
'stoploss_on_exchange': False
}
# Count of candles the strategy requires before producing valid signals
startup_candle_count: int = 20
# Optional time in force for orders
order_time_in_force = {
'buy': 'gtc',
@ -105,9 +108,6 @@ class DefaultStrategy(IStrategy):
# EMA - Exponential Moving Average
dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
# SMA - Simple Moving Average
dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

View File

@ -838,7 +838,10 @@ def test_backtest_start_timerange(default_conf, mocker, caplog, testdatadir):
f'Using data directory: {testdatadir} ...',
'Using stake_currency: BTC ...',
'Using stake_amount: 0.001 ...',
'Backtesting with data from 2017-11-14T21:17:00+00:00 '
'Backtesting with data from 2017-11-14T21:37:00+00:00 '
'up to 2017-11-14T22:58:00+00:00 (0 days)..',
'Moving start-date by 20 candles to account for startup time.',
'Loading backtest data from 2017-11-14T21:17:00+00:00 '
'up to 2017-11-14T22:58:00+00:00 (0 days)..',
'Parameter --enable-position-stacking detected ...'
]
@ -892,7 +895,10 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir):
f'Using data directory: {testdatadir} ...',
'Using stake_currency: BTC ...',
'Using stake_amount: 0.001 ...',
'Backtesting with data from 2017-11-14T21:17:00+00:00 '
'Backtesting with data from 2017-11-14T21:37:00+00:00 '
'up to 2017-11-14T22:58:00+00:00 (0 days)..',
'Moving start-date by 20 candles to account for startup time.',
'Loading backtest data from 2017-11-14T21:17:00+00:00 '
'up to 2017-11-14T22:58:00+00:00 (0 days)..',
'Parameter --enable-position-stacking detected ...',
'Running backtesting for Strategy DefaultStrategy',