Initial fix - test

This commit is contained in:
Matthias
2023-05-20 11:14:13 +02:00
parent 073dac8d5f
commit 2e675efa13
2 changed files with 15 additions and 39 deletions

View File

@@ -55,7 +55,6 @@ class LookaheadAnalysis:
self.current_analysis = Analysis()
self.minimum_trade_amount = config['minimum_trade_amount']
self.targeted_trade_amount = config['targeted_trade_amount']
self.exportfilename = config['exportfilename']
self.strategy_obj = strategy_obj
@staticmethod

View File

@@ -3,6 +3,7 @@
from unittest.mock import PropertyMock
import numpy as np
import pytest
import freqtrade.commands.arguments
import freqtrade.optimize.lookahead_analysis
@@ -10,7 +11,15 @@ from freqtrade.configuration import TimeRange
from freqtrade.data import history
from freqtrade.data.converter import clean_ohlcv_dataframe
from freqtrade.data.history import get_timerange
from tests.conftest import patch_exchange
from tests.conftest import generate_test_data, patch_exchange
@pytest.fixture
def lookahead_conf(default_conf_usdt):
default_conf_usdt['minimum_trade_amount'] = 10
default_conf_usdt['targeted_trade_amount'] = 20
return default_conf_usdt
def trim_dictlist(dict_list, num):
@@ -20,50 +29,18 @@ def trim_dictlist(dict_list, num):
return new
def load_data_test(what, testdatadir):
timerange = TimeRange.parse_timerange('1510694220-1510700340')
data = history.load_pair_history(pair='UNITTEST/BTC', datadir=testdatadir,
timeframe='1m', timerange=timerange,
drop_incomplete=False,
fill_up_missing=False)
base = 0.001
if what == 'raise':
data.loc[:, 'open'] = data.index * base
data.loc[:, 'high'] = data.index * base + 0.0001
data.loc[:, 'low'] = data.index * base - 0.0001
data.loc[:, 'close'] = data.index * base
if what == 'lower':
data.loc[:, 'open'] = 1 - data.index * base
data.loc[:, 'high'] = 1 - data.index * base + 0.0001
data.loc[:, 'low'] = 1 - data.index * base - 0.0001
data.loc[:, 'close'] = 1 - data.index * base
if what == 'sine':
hz = 0.1 # frequency
data.loc[:, 'open'] = np.sin(data.index * hz) / 1000 + base
data.loc[:, 'high'] = np.sin(data.index * hz) / 1000 + base + 0.0001
data.loc[:, 'low'] = np.sin(data.index * hz) / 1000 + base - 0.0001
data.loc[:, 'close'] = np.sin(data.index * hz) / 1000 + base
return {'UNITTEST/BTC': clean_ohlcv_dataframe(data, timeframe='1m', pair='UNITTEST/BTC',
fill_missing=True, drop_incomplete=True)}
def test_biased_strategy(default_conf, mocker, caplog) -> None:
def test_biased_strategy(lookahead_conf, mocker, caplog) -> None:
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
patch_exchange(mocker)
mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist',
PropertyMock(return_value=['UNITTEST/BTC']))
default_conf['timeframe'] = '5m'
default_conf['timerange'] = '-1510694220'
default_conf['strategy'] = 'strategy_test_v3_with_lookahead_bias'
default_conf['strategy_path'] = 'tests/strategy/strats'
lookahead_conf['timeframe'] = '5m'
lookahead_conf['timerange'] = '-1510694220'
lookahead_conf['strategy'] = 'strategy_test_v3_with_lookahead_bias'
strategy_obj = {}
strategy_obj['name'] = "strategy_test_v3_with_lookahead_bias"
freqtrade.optimize.lookahead_analysis.LookaheadAnalysis(default_conf, strategy_obj, {})
freqtrade.optimize.lookahead_analysis.LookaheadAnalysis(lookahead_conf, strategy_obj)
pass