Merge pull request #88 from gcarq/reduce_memory_use

Reduce memory use in backtesting
This commit is contained in:
Michael Egger 2017-10-31 00:28:38 +01:00 committed by GitHub
commit ea1b1e11ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -44,13 +44,13 @@ def conf():
def backtest(conf, pairs, mocker): def backtest(conf, pairs, mocker):
trades = [] trades = []
mocked_history = mocker.patch('freqtrade.analyze.get_ticker_history')
mocker.patch.dict('freqtrade.main._CONF', conf) mocker.patch.dict('freqtrade.main._CONF', conf)
mocker.patch('arrow.utcnow', return_value=arrow.get('2017-08-20T14:50:00'))
for pair in pairs: for pair in pairs:
with open('freqtrade/tests/testdata/'+pair+'.json') as data_file: with open('freqtrade/tests/testdata/'+pair+'.json') as data_file:
data = json.load(data_file) data = json.load(data_file)
mocked_history.return_value = data
mocker.patch('freqtrade.analyze.get_ticker_history', return_value=data)
mocker.patch('arrow.utcnow', return_value=arrow.get('2017-08-20T14:50:00'))
ticker = analyze_ticker(pair)[['close', 'date', 'buy']].copy() ticker = analyze_ticker(pair)[['close', 'date', 'buy']].copy()
# for each buy point # for each buy point
for row in ticker[ticker.buy == 1].itertuples(index=True): for row in ticker[ticker.buy == 1].itertuples(index=True):

View File

@ -79,9 +79,10 @@ def buy_strategy_generator(params):
@pytest.mark.skipif(not os.environ.get('BACKTEST', False), reason="BACKTEST not set") @pytest.mark.skipif(not os.environ.get('BACKTEST', False), reason="BACKTEST not set")
def test_hyperopt(conf, pairs, mocker): def test_hyperopt(conf, pairs, mocker):
mocked_buy_trend = mocker.patch('freqtrade.analyze.populate_buy_trend')
def optimizer(params): def optimizer(params):
buy_strategy = buy_strategy_generator(params) mocked_buy_trend.side_effect = buy_strategy_generator(params)
mocker.patch('freqtrade.analyze.populate_buy_trend', side_effect=buy_strategy)
results = backtest(conf, pairs, mocker) results = backtest(conf, pairs, mocker)
result = format_results(results) result = format_results(results)