Add tests for advise_indicator methods

This commit is contained in:
Matthias 2018-07-18 22:04:34 +02:00
parent 4ebd706cb8
commit aa772c28ad
3 changed files with 13 additions and 10 deletions

View File

@ -28,7 +28,7 @@ class DefaultStrategy(IStrategy):
# Optimal ticker interval for the strategy
ticker_interval = '5m'
def populate_indicators(self, dataframe: DataFrame) -> DataFrame:
def advise_indicators(self, dataframe: DataFrame, pair: str) -> DataFrame:
"""
Adds several different TA indicators to the given DataFrame
@ -196,10 +196,11 @@ class DefaultStrategy(IStrategy):
return dataframe
def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame:
def advise_buy(self, dataframe: DataFrame, pair: str) -> DataFrame:
"""
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame
:param pair: Pair currently analyzed
:return: DataFrame with buy column
"""
dataframe.loc[
@ -217,10 +218,11 @@ class DefaultStrategy(IStrategy):
return dataframe
def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame:
def advise_sell(self, dataframe: DataFrame, pair: str) -> DataFrame:
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame
:param pair: Pair currently analyzed
:return: DataFrame with buy column
"""
dataframe.loc[

View File

@ -3,7 +3,7 @@ IStrategy interface
This module defines the interface to apply for strategies
"""
import logging
from abc import ABC, abstractmethod
from abc import ABC
from datetime import datetime
from enum import Enum
from typing import Dict, List, NamedTuple, Tuple

View File

@ -9,7 +9,6 @@ from freqtrade.strategy import import_strategy
from freqtrade.strategy.default_strategy import DefaultStrategy
from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy.resolver import StrategyResolver
from freqtrade.tests.conftest import log_has
def test_import_strategy(caplog):
@ -73,7 +72,8 @@ def test_load_strategy_invalid_directory(result, caplog):
logging.WARNING,
'Path "{}" does not exist'.format(extra_dir),
) in caplog.record_tuples
assert 'adx' in resolver.strategy.populate_indicators(result)
assert 'adx' in resolver.strategy.advise_indicators(result, 'ETH/BTC')
def test_load_not_found_strategy():
@ -88,7 +88,7 @@ def test_strategy(result):
config = {'strategy': 'DefaultStrategy'}
resolver = StrategyResolver(config)
pair = 'ETH/BTC'
assert resolver.strategy.minimal_roi[0] == 0.04
assert config["minimal_roi"]['0'] == 0.04
@ -98,12 +98,13 @@ def test_strategy(result):
assert resolver.strategy.ticker_interval == '5m'
assert config['ticker_interval'] == '5m'
assert 'adx' in resolver.strategy.populate_indicators(result)
df_indicators = resolver.strategy.advise_indicators(result, pair=pair)
assert 'adx' in df_indicators
dataframe = resolver.strategy.populate_buy_trend(resolver.strategy.populate_indicators(result))
dataframe = resolver.strategy.advise_buy(df_indicators, pair=pair)
assert 'buy' in dataframe.columns
dataframe = resolver.strategy.populate_sell_trend(resolver.strategy.populate_indicators(result))
dataframe = resolver.strategy.advise_sell(df_indicators, pair='ETH/BTC')
assert 'sell' in dataframe.columns