Remove freqAI model bridge in favor of self.freqai
This commit is contained in:
parent
c91e23dc50
commit
8fa6e8b4ba
@ -1,12 +0,0 @@
|
|||||||
from freqtrade.resolvers.freqaimodel_resolver import FreqaiModelResolver
|
|
||||||
|
|
||||||
|
|
||||||
class CustomModel:
|
|
||||||
"""
|
|
||||||
A bridge between the user defined IFreqaiModel class
|
|
||||||
and the strategy.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, config):
|
|
||||||
|
|
||||||
self.bridge = FreqaiModelResolver.load_freqaimodel(config)
|
|
@ -145,11 +145,20 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
informative_data.candle_type = config['candle_type_def']
|
informative_data.candle_type = config['candle_type_def']
|
||||||
self._ft_informative.append((informative_data, cls_method))
|
self._ft_informative.append((informative_data, cls_method))
|
||||||
|
|
||||||
|
def load_freqAI_model(self) -> None:
|
||||||
|
if self.config.get('freqai', None):
|
||||||
|
# Import here to avoid importing this if freqAI is disabled
|
||||||
|
from freqtrade.resolvers.freqaimodel_resolver import FreqaiModelResolver
|
||||||
|
|
||||||
|
self.freqai = FreqaiModelResolver.load_freqaimodel(self.config)
|
||||||
|
|
||||||
def ft_bot_start(self, **kwargs) -> None:
|
def ft_bot_start(self, **kwargs) -> None:
|
||||||
"""
|
"""
|
||||||
Strategy init - runs after dataprovider has been added.
|
Strategy init - runs after dataprovider has been added.
|
||||||
Must call bot_start()
|
Must call bot_start()
|
||||||
"""
|
"""
|
||||||
|
self.load_freqAI_model()
|
||||||
|
|
||||||
strategy_safe_wrapper(self.bot_start)()
|
strategy_safe_wrapper(self.bot_start)()
|
||||||
|
|
||||||
self.ft_load_hyper_params(self.config.get('runmode') == RunMode.HYPEROPT)
|
self.ft_load_hyper_params(self.config.get('runmode') == RunMode.HYPEROPT)
|
||||||
|
@ -7,7 +7,6 @@ from pandas import DataFrame
|
|||||||
from technical import qtpylib
|
from technical import qtpylib
|
||||||
|
|
||||||
from freqtrade.exchange import timeframe_to_prev_date
|
from freqtrade.exchange import timeframe_to_prev_date
|
||||||
from freqtrade.freqai.strategy_bridge import CustomModel
|
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.strategy import DecimalParameter, IntParameter, merge_informative_pair
|
from freqtrade.strategy import DecimalParameter, IntParameter, merge_informative_pair
|
||||||
from freqtrade.strategy.interface import IStrategy
|
from freqtrade.strategy.interface import IStrategy
|
||||||
@ -21,7 +20,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
Example strategy showing how the user connects their own
|
Example strategy showing how the user connects their own
|
||||||
IFreqaiModel to the strategy. Namely, the user uses:
|
IFreqaiModel to the strategy. Namely, the user uses:
|
||||||
self.model = CustomModel(self.config)
|
self.model = CustomModel(self.config)
|
||||||
self.model.bridge.start(dataframe, metadata)
|
self.freqai.start(dataframe, metadata)
|
||||||
|
|
||||||
to make predictions on their data. populate_any_indicators() automatically
|
to make predictions on their data. populate_any_indicators() automatically
|
||||||
generates the variety of features indicated by the user in the
|
generates the variety of features indicated by the user in the
|
||||||
@ -67,9 +66,6 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
informative_pairs.append((pair, tf))
|
informative_pairs.append((pair, tf))
|
||||||
return informative_pairs
|
return informative_pairs
|
||||||
|
|
||||||
def bot_start(self):
|
|
||||||
self.model = CustomModel(self.config)
|
|
||||||
|
|
||||||
def populate_any_indicators(
|
def populate_any_indicators(
|
||||||
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False
|
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False
|
||||||
):
|
):
|
||||||
@ -88,7 +84,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
:coin: the name of the coin which will modify the feature names.
|
:coin: the name of the coin which will modify the feature names.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self.model.bridge.lock:
|
with self.freqai.lock:
|
||||||
if informative is None:
|
if informative is None:
|
||||||
informative = self.dp.get_pair_dataframe(pair, tf)
|
informative = self.dp.get_pair_dataframe(pair, tf)
|
||||||
|
|
||||||
@ -180,7 +176,7 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
# the target mean/std values for each of the labels created by user in
|
# the target mean/std values for each of the labels created by user in
|
||||||
# `populate_any_indicators()` for each training period.
|
# `populate_any_indicators()` for each training period.
|
||||||
|
|
||||||
dataframe = self.model.bridge.start(dataframe, metadata, self)
|
dataframe = self.freqai.start(dataframe, metadata, self)
|
||||||
|
|
||||||
dataframe["target_roi"] = dataframe["&-s_close_mean"] + dataframe["&-s_close_std"] * 1.25
|
dataframe["target_roi"] = dataframe["&-s_close_mean"] + dataframe["&-s_close_std"] * 1.25
|
||||||
dataframe["sell_roi"] = dataframe["&-s_close_mean"] - dataframe["&-s_close_std"] * 1.25
|
dataframe["sell_roi"] = dataframe["&-s_close_mean"] - dataframe["&-s_close_std"] * 1.25
|
||||||
@ -234,9 +230,9 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
follow_mode = self.config.get("freqai", {}).get("follow_mode", False)
|
follow_mode = self.config.get("freqai", {}).get("follow_mode", False)
|
||||||
|
|
||||||
if not follow_mode:
|
if not follow_mode:
|
||||||
pair_dict = self.model.bridge.dd.pair_dict
|
pair_dict = self.freqai.dd.pair_dict
|
||||||
else:
|
else:
|
||||||
pair_dict = self.model.bridge.dd.follower_dict
|
pair_dict = self.freqai.dd.follower_dict
|
||||||
|
|
||||||
entry_tag = trade.enter_tag
|
entry_tag = trade.enter_tag
|
||||||
|
|
||||||
@ -244,12 +240,12 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
"prediction" + entry_tag not in pair_dict[pair]
|
"prediction" + entry_tag not in pair_dict[pair]
|
||||||
or pair_dict[pair]["prediction" + entry_tag] > 0
|
or pair_dict[pair]["prediction" + entry_tag] > 0
|
||||||
):
|
):
|
||||||
with self.model.bridge.lock:
|
with self.freqai.lock:
|
||||||
pair_dict[pair]["prediction" + entry_tag] = abs(trade_candle["&-s_close"])
|
pair_dict[pair]["prediction" + entry_tag] = abs(trade_candle["&-s_close"])
|
||||||
if not follow_mode:
|
if not follow_mode:
|
||||||
self.model.bridge.dd.save_drawer_to_disk()
|
self.freqai.dd.save_drawer_to_disk()
|
||||||
else:
|
else:
|
||||||
self.model.bridge.dd.save_follower_dict_to_disk()
|
self.freqai.dd.save_follower_dict_to_disk()
|
||||||
|
|
||||||
roi_price = pair_dict[pair]["prediction" + entry_tag]
|
roi_price = pair_dict[pair]["prediction" + entry_tag]
|
||||||
roi_time = self.max_roi_time_long.value
|
roi_time = self.max_roi_time_long.value
|
||||||
@ -284,16 +280,16 @@ class FreqaiExampleStrategy(IStrategy):
|
|||||||
entry_tag = trade.enter_tag
|
entry_tag = trade.enter_tag
|
||||||
follow_mode = self.config.get("freqai", {}).get("follow_mode", False)
|
follow_mode = self.config.get("freqai", {}).get("follow_mode", False)
|
||||||
if not follow_mode:
|
if not follow_mode:
|
||||||
pair_dict = self.model.bridge.dd.pair_dict
|
pair_dict = self.freqai.dd.pair_dict
|
||||||
else:
|
else:
|
||||||
pair_dict = self.model.bridge.dd.follower_dict
|
pair_dict = self.freqai.dd.follower_dict
|
||||||
|
|
||||||
with self.model.bridge.lock:
|
with self.freqai.lock:
|
||||||
pair_dict[pair]["prediction" + entry_tag] = 0
|
pair_dict[pair]["prediction" + entry_tag] = 0
|
||||||
if not follow_mode:
|
if not follow_mode:
|
||||||
self.model.bridge.dd.save_drawer_to_disk()
|
self.freqai.dd.save_drawer_to_disk()
|
||||||
else:
|
else:
|
||||||
self.model.bridge.dd.save_follower_dict_to_disk()
|
self.freqai.dd.save_follower_dict_to_disk()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import pandas as pd
|
|||||||
import talib.abstract as ta
|
import talib.abstract as ta
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
from freqtrade.freqai.strategy_bridge import CustomModel
|
|
||||||
from freqtrade.strategy import DecimalParameter, IntParameter, merge_informative_pair
|
from freqtrade.strategy import DecimalParameter, IntParameter, merge_informative_pair
|
||||||
from freqtrade.strategy.interface import IStrategy
|
from freqtrade.strategy.interface import IStrategy
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ class freqai_test_strat(IStrategy):
|
|||||||
Example strategy showing how the user connects their own
|
Example strategy showing how the user connects their own
|
||||||
IFreqaiModel to the strategy. Namely, the user uses:
|
IFreqaiModel to the strategy. Namely, the user uses:
|
||||||
self.model = CustomModel(self.config)
|
self.model = CustomModel(self.config)
|
||||||
self.model.bridge.start(dataframe, metadata)
|
self.freqai.start(dataframe, metadata)
|
||||||
|
|
||||||
to make predictions on their data. populate_any_indicators() automatically
|
to make predictions on their data. populate_any_indicators() automatically
|
||||||
generates the variety of features indicated by the user in the
|
generates the variety of features indicated by the user in the
|
||||||
@ -64,9 +63,6 @@ class freqai_test_strat(IStrategy):
|
|||||||
informative_pairs.append((pair, tf))
|
informative_pairs.append((pair, tf))
|
||||||
return informative_pairs
|
return informative_pairs
|
||||||
|
|
||||||
def bot_start(self):
|
|
||||||
self.model = CustomModel(self.config)
|
|
||||||
|
|
||||||
def populate_any_indicators(
|
def populate_any_indicators(
|
||||||
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False
|
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False
|
||||||
):
|
):
|
||||||
@ -85,7 +81,7 @@ class freqai_test_strat(IStrategy):
|
|||||||
:coin: the name of the coin which will modify the feature names.
|
:coin: the name of the coin which will modify the feature names.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self.model.bridge.lock:
|
with self.freqai.lock:
|
||||||
if informative is None:
|
if informative is None:
|
||||||
informative = self.dp.get_pair_dataframe(pair, tf)
|
informative = self.dp.get_pair_dataframe(pair, tf)
|
||||||
|
|
||||||
@ -146,7 +142,7 @@ class freqai_test_strat(IStrategy):
|
|||||||
# the model will return 4 values, its prediction, an indication of whether or not the
|
# the model will return 4 values, its prediction, an indication of whether or not the
|
||||||
# prediction should be accepted, the target mean/std values from the labels used during
|
# prediction should be accepted, the target mean/std values from the labels used during
|
||||||
# each training period.
|
# each training period.
|
||||||
dataframe = self.model.bridge.start(dataframe, metadata, self)
|
dataframe = self.freqai.start(dataframe, metadata, self)
|
||||||
|
|
||||||
dataframe["target_roi"] = dataframe["&-s_close_mean"] + dataframe["&-s_close_std"] * 1.25
|
dataframe["target_roi"] = dataframe["&-s_close_mean"] + dataframe["&-s_close_std"] * 1.25
|
||||||
dataframe["sell_roi"] = dataframe["&-s_close_mean"] - dataframe["&-s_close_std"] * 1.25
|
dataframe["sell_roi"] = dataframe["&-s_close_mean"] - dataframe["&-s_close_std"] * 1.25
|
||||||
|
Loading…
Reference in New Issue
Block a user