up
This commit is contained in:
parent
b222485199
commit
22f3e52cbd
@ -35,12 +35,8 @@
|
||||
"timeout": 20000
|
||||
},
|
||||
"pair_whitelist": [
|
||||
"BTC/USDT",
|
||||
"DOGE/USDT",
|
||||
"OKB/USDT",
|
||||
"TON/USDT",
|
||||
"XRP/USDT",
|
||||
"SOL/USDT"
|
||||
"TON/USDT"
|
||||
],
|
||||
"pair_blacklist": []
|
||||
},
|
||||
@ -66,46 +62,46 @@
|
||||
],
|
||||
"freqai": {
|
||||
"enabled": true,
|
||||
"identifier": "test175",
|
||||
"freqaimodel": "XGBoostRegressor",
|
||||
"purge_old_models": 2,
|
||||
"train_period_days": 90,
|
||||
"backtest_period_days": 10,
|
||||
"live_retrain_hours": 0,
|
||||
"data_kitchen": {
|
||||
"fillna": "ffill",
|
||||
"feature_parameters": {
|
||||
"DI_threshold": 0.9,
|
||||
"DI_threshold": 0.5,
|
||||
"weight_factor": 0.9
|
||||
}
|
||||
},
|
||||
"freqaimodel": "XGBoostRegressor",
|
||||
"purge_old_models": 2,
|
||||
"identifier": "test175",
|
||||
"train_period_days": 30,
|
||||
"backtest_period_days": 10,
|
||||
"live_retrain_hours": 0,
|
||||
"feature_selection": {
|
||||
"method": "recursive_elimination",
|
||||
"threshold": 0.01
|
||||
},
|
||||
"feature_parameters": {
|
||||
"include_timeframes": ["3m", "5m", "1h"],
|
||||
"include_timeframes": ["3m"],
|
||||
"include_corr_pairlist": ["BTC/USDT", "ETH/USDT"],
|
||||
"label_period_candles": 12,
|
||||
"include_shifted_candles": 3,
|
||||
"indicator_periods_candles": [10, 20, 50],
|
||||
"plot_feature_importances": 1
|
||||
"plot_feature_importances": 1,
|
||||
"feature_selection": {
|
||||
"method": "none"
|
||||
}
|
||||
},
|
||||
"data_split_parameters": {
|
||||
"test_size": 0.2,
|
||||
"shuffle": true,
|
||||
"shuffle": false,
|
||||
"random_state": 42
|
||||
},
|
||||
"model_training_parameters": {
|
||||
"n_estimators": 100,
|
||||
"learning_rate": 0.05,
|
||||
"max_depth": 5,
|
||||
"subsample": 0.8,
|
||||
"colsample_bytree": 0.8,
|
||||
"n_estimators": 500,
|
||||
"learning_rate": 0.015,
|
||||
"max_depth": 6,
|
||||
"subsample": 0.9,
|
||||
"colsample_bytree": 0.9,
|
||||
"objective": "reg:squarederror",
|
||||
"eval_metric": "rmse",
|
||||
"early_stopping_rounds": 50,
|
||||
"verbose": 0
|
||||
"early_stopping_rounds": 150,
|
||||
"reg_alpha": 0.1,
|
||||
"reg_lambda": 1.0
|
||||
}
|
||||
},
|
||||
"api_server": {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
---
|
||||
services:
|
||||
freqtrade:
|
||||
image: freqtradeorg/freqtrade:stable_freqaitorch
|
||||
image: freqtradeorg/freqtrade:develop_freqaitorch
|
||||
# # Enable GPU Image and GPU Resources
|
||||
# # Make sure to uncomment the whole deploy section
|
||||
# deploy:
|
||||
@ -70,5 +70,6 @@ services:
|
||||
--config /freqtrade/config_examples/config_freqai.okx.json
|
||||
--strategy-path /freqtrade/templates
|
||||
--strategy OKXRegressionStrategy
|
||||
--timerange 20240415-20250415
|
||||
--timerange 20250315-20250415
|
||||
--fee 0.0008
|
||||
--cache none
|
||||
|
||||
@ -11,6 +11,8 @@ from freqtrade.strategy import CategoricalParameter, DecimalParameter
|
||||
from xgboost import XGBRegressor
|
||||
import ccxt
|
||||
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class OKXRegressionStrategy(IStrategy):
|
||||
@ -51,6 +53,7 @@ class OKXRegressionStrategy(IStrategy):
|
||||
},
|
||||
"data_split_parameters": {
|
||||
"test_size": 0.2,
|
||||
"random_state": 42,
|
||||
"shuffle": False
|
||||
},
|
||||
"train_period_days": 90,
|
||||
@ -88,15 +91,18 @@ class OKXRegressionStrategy(IStrategy):
|
||||
# 成交量均线
|
||||
dataframe[f"%-%-volume_ma-{period}"] = ta.SMA(dataframe["volume"], timeperiod=period)
|
||||
|
||||
# OKX 订单簿特征(通过 CCXT)
|
||||
try:
|
||||
order_book = self.fetch_okx_order_book(metadata["pair"])
|
||||
dataframe[f"%-%-order_book_imbalance-{period}"] = (
|
||||
order_book["bids"] - order_book["asks"]
|
||||
) / (order_book["bids"] + order_book["asks"] + 1e-10)
|
||||
except Exception as e:
|
||||
logger.warning(f"获取 {metadata['pair']} 订单簿失败:{str(e)}")
|
||||
dataframe[f"%-%-order_book_imbalance-{period}"] = 0.0
|
||||
# 仅为 BTC/USDT 和 ETH/USDT 生成 order_book_imbalance
|
||||
#
|
||||
pair = metadata.get('pair', 'unknown')
|
||||
if pair in ["BTC/USDT", "ETH/USDT"]:
|
||||
try:
|
||||
order_book = self.fetch_okx_order_book(pair)
|
||||
dataframe[f"%-%-order_book_imbalance"] = (
|
||||
order_book["bids"] - order_book["asks"]
|
||||
) / (order_book["bids"] + order_book["asks"] + 1e-10)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch order book for {pair}: {str(e)}")
|
||||
dataframe[f"%-%-order_book_imbalance"] = 0.0
|
||||
|
||||
# 数据清洗
|
||||
dataframe = dataframe.replace([np.inf, -np.inf], np.nan)
|
||||
@ -131,28 +137,108 @@ class OKXRegressionStrategy(IStrategy):
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:
|
||||
"""
|
||||
设置回归模型的目标变量。
|
||||
设置回归模型的目标变量,为不同币对设置动态止损和ROI阈值。
|
||||
输入:dataframe(K线数据:close, high, low),metadata(交易对信息),config(FreqAI配置)
|
||||
输出:更新后的dataframe,包含目标标签
|
||||
"""
|
||||
label_period = self.freqai_config["feature_parameters"]["label_period_candles"]
|
||||
# 目标:未来价格变化
|
||||
dataframe["&-s_close"] = (
|
||||
dataframe["close"].shift(-label_period) - dataframe["close"]
|
||||
) / dataframe["close"]
|
||||
# 获取配置参数
|
||||
label_period = self.freqai_config["feature_parameters"]["label_period_candles"] # 标签预测周期(如5分钟K线的N根)
|
||||
pair = metadata["pair"] # 当前交易对(如DOGE/USDT)
|
||||
|
||||
# ROI 目标
|
||||
# 计算未来价格变化率(现有逻辑)
|
||||
dataframe["&-s_close"] = (dataframe["close"].shift(-label_period) - dataframe["close"]) / dataframe["close"]
|
||||
|
||||
# 计算不同时间窗口的ROI(现有逻辑)
|
||||
for minutes in [0, 15, 30]:
|
||||
candles = int(minutes / 5)
|
||||
candles = int(minutes / 5) # 假设5分钟K线
|
||||
if candles > 0:
|
||||
dataframe[f"&-roi_{minutes}"] = (
|
||||
dataframe["close"].shift(-candles) - dataframe["close"]
|
||||
) / dataframe["close"]
|
||||
dataframe[f"&-roi_{minutes}"] = (dataframe["close"].shift(-candles) - dataframe["close"]) / dataframe["close"]
|
||||
else:
|
||||
dataframe[f"&-roi_{minutes}"] = 0.0
|
||||
|
||||
# 动态阈值
|
||||
# 计算市场状态指标:ADX(14周期,与label_period_candles对齐)
|
||||
dataframe["adx"] = ta.ADX(dataframe["high"], dataframe["low"], dataframe["close"], timeperiod=14)
|
||||
|
||||
# 定义币对特定的ADX阈值和止损/ROI范围
|
||||
pair_thresholds = {
|
||||
"DOGE/USDT": {
|
||||
"adx_trend": 20, # 趋势市场ADX阈值
|
||||
"adx_oscillation": 15, # 震荡市场ADX阈值
|
||||
"stoploss_trend": -0.08, # 趋势市场止损:-8%
|
||||
"stoploss_oscillation": -0.04, # 震荡市场止损:-4%
|
||||
"stoploss_mid": -0.06, # 中间状态止损:-6%
|
||||
"roi_trend": 0.06, # 趋势市场ROI:6%
|
||||
"roi_oscillation": 0.025, # 震荡市场ROI:2.5%
|
||||
"roi_mid": 0.04 # 中间状态ROI:4%
|
||||
},
|
||||
"BTC/USDT": {
|
||||
"adx_trend": 25,
|
||||
"adx_oscillation": 20,
|
||||
"stoploss_trend": -0.03,
|
||||
"stoploss_oscillation": -0.015,
|
||||
"stoploss_mid": -0.02,
|
||||
"roi_trend": 0.03,
|
||||
"roi_oscillation": 0.015,
|
||||
"roi_mid": 0.02
|
||||
},
|
||||
"SOL/USDT": {
|
||||
"adx_trend": 22,
|
||||
"adx_oscillation": 18,
|
||||
"stoploss_trend": -0.06,
|
||||
"stoploss_oscillation": -0.03,
|
||||
"stoploss_mid": -0.045,
|
||||
"roi_trend": 0.045,
|
||||
"roi_oscillation": 0.02,
|
||||
"roi_mid": 0.03
|
||||
},
|
||||
"XRP/USDT": {
|
||||
"adx_trend": 22,
|
||||
"adx_oscillation": 18,
|
||||
"stoploss_trend": -0.06,
|
||||
"stoploss_oscillation": -0.03,
|
||||
"stoploss_mid": -0.045,
|
||||
"roi_trend": 0.045,
|
||||
"roi_oscillation": 0.02,
|
||||
"roi_mid": 0.03
|
||||
}
|
||||
}
|
||||
|
||||
# 动态化 &-stoploss_pred(基于市场状态和币对)
|
||||
dataframe["&-stoploss_pred"] = 0.0
|
||||
for index, row in dataframe.iterrows():
|
||||
thresholds = pair_thresholds.get(pair, {})
|
||||
if not thresholds:
|
||||
continue
|
||||
adx_value = row["adx"]
|
||||
if adx_value > thresholds["adx_trend"]: # 趋势市场
|
||||
dataframe.at[index, "&-stoploss_pred"] = thresholds["stoploss_trend"] # 宽松止损
|
||||
elif adx_value < thresholds["adx_oscillation"]: # 震荡市场
|
||||
dataframe.at[index, "&-stoploss_pred"] = thresholds["stoploss_oscillation"] # 严格止损
|
||||
else: # 中间状态
|
||||
dataframe.at[index, "&-stoploss_pred"] = thresholds["stoploss_mid"] # 中等止损
|
||||
# 风险控制:设置止损下限
|
||||
if dataframe.at[index, "&-stoploss_pred"] < -0.10:
|
||||
dataframe.at[index, "&-stoploss_pred"] = -0.10
|
||||
|
||||
# 动态化 &-roi_0_pred(基于市场趋势和币对)
|
||||
dataframe["&-roi_0_pred"] = 0.0
|
||||
for index, row in dataframe.iterrows():
|
||||
thresholds = pair_thresholds.get(pair, {})
|
||||
if not thresholds:
|
||||
continue
|
||||
adx_value = row["adx"]
|
||||
if adx_value > thresholds["adx_trend"]: # 强趋势市场
|
||||
dataframe.at[index, "&-roi_0_pred"] = thresholds["roi_trend"] # 高ROI
|
||||
elif adx_value < thresholds["adx_oscillation"]: # 震荡市场
|
||||
dataframe.at[index, "&-roi_0_pred"] = thresholds["roi_oscillation"] # 低ROI
|
||||
else: # 中间状态
|
||||
dataframe.at[index, "&-roi_0_pred"] = thresholds["roi_mid"] # 中等ROI
|
||||
# 风险控制:设置ROI上限
|
||||
if dataframe.at[index, "&-roi_0_pred"] > 0.10:
|
||||
dataframe.at[index, "&-roi_0_pred"] = 0.10
|
||||
|
||||
# 计算RSI预测(现有逻辑)
|
||||
dataframe["&-buy_rsi_pred"] = ta.RSI(dataframe["close"], timeperiod=14).rolling(20).mean()
|
||||
dataframe["&-stoploss_pred"] = -0.05
|
||||
dataframe["&-roi_0_pred"] = 0.03
|
||||
|
||||
# 数据清洗
|
||||
dataframe = dataframe.replace([np.inf, -np.inf], np.nan)
|
||||
@ -241,10 +327,17 @@ class OKXRegressionStrategy(IStrategy):
|
||||
|
||||
return dataframe
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: Dict) -> DataFrame:
|
||||
dataframe['atr'] = dataframe['ATR_14']
|
||||
# 确保 ATR 列存在
|
||||
if 'ATR_14' not in dataframe.columns:
|
||||
dataframe['ATR_14'] = 0.0
|
||||
|
||||
# 计算动态止损线
|
||||
dataframe['stop_loss_line'] = dataframe['entry_price'] - (dataframe['ATR_14'] * 2)
|
||||
|
||||
# 发送止损信息
|
||||
self.dp.send_msg(f"ATR: {dataframe['ATR_14'].iloc[-1]:.5f}, Stop Loss Line: {dataframe['stop_loss_line'].iloc[-1]:.5f}")
|
||||
|
||||
# 应用动态止损逻辑
|
||||
return self._dynamic_stop_loss(dataframe, metadata)
|
||||
|
||||
def custom_stake_amount(self, pair: str, current_time: 'datetime', current_rate: float,
|
||||
|
||||
56759
output.log
56759
output.log
File diff suppressed because it is too large
Load Diff
30789
output_filted.log
30789
output_filted.log
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
{"OKXRegressionStrategy":{"run_id":"ab18fb2868557acc58d74ca02f236930d0ae691f","backtest_start_time":1746187066,"timeframe":"3m","timeframe_detail":null,"backtest_start_ts":1713139200,"backtest_end_ts":1744675200}}
|
||||
@ -1 +0,0 @@
|
||||
{"$schema":"https://schema.freqtrade.io/schema.json","trading_mode":"spot","margin_mode":"isolated","max_open_trades":4,"stake_currency":"USDT","stake_amount":150,"startup_candle_count":30,"tradable_balance_ratio":1,"fiat_display_currency":"USD","dry_run":true,"timeframe":"3m","dry_run_wallet":1000,"cancel_open_orders_on_exit":true,"stoploss":-0.05,"unfilledtimeout":{"entry":5,"exit":15},"exchange":{"name":"okx","key":"REDACTED","secret":"REDACTED","enable_ws":false,"ccxt_config":{"enableRateLimit":true,"rateLimit":500,"options":{"defaultType":"spot"}},"ccxt_async_config":{"enableRateLimit":true,"rateLimit":500,"timeout":20000},"pair_whitelist":["BTC/USDT","DOGE/USDT","OKB/USDT","TON/USDT","XRP/USDT","SOL/USDT"],"pair_blacklist":[]},"entry_pricing":{"price_side":"same","use_order_book":true,"order_book_top":1,"price_last_balance":0.0,"check_depth_of_market":{"enabled":false,"bids_to_ask_delta":1}},"exit_pricing":{"price_side":"other","use_order_book":true,"order_book_top":1},"pairlists":[{"method":"StaticPairList"}],"freqai":{"enabled":true,"data_kitchen":{"fillna":"ffill","feature_parameters":{"DI_threshold":0.9,"weight_factor":0.9}},"freqaimodel":"XGBoostRegressor","purge_old_models":2,"identifier":"test175","train_period_days":30,"backtest_period_days":10,"live_retrain_hours":0,"feature_selection":{"method":"recursive_elimination","threshold":0.01},"feature_parameters":{"include_timeframes":["3m","5m","1h"],"include_corr_pairlist":["BTC/USDT","ETH/USDT"],"label_period_candles":12,"include_shifted_candles":3,"indicator_periods_candles":[10,20,50],"plot_feature_importances":1},"data_split_parameters":{"test_size":0.2,"shuffle":true,"random_state":42},"model_training_parameters":{"n_estimators":100,"learning_rate":0.05,"max_depth":5,"subsample":0.8,"colsample_bytree":0.8,"objective":"reg:squarederror","eval_metric":"rmse","early_stopping_rounds":50,"verbose":0}},"api_server":{"enabled":true,"listen_ip_address":"0.0.0.0","listen_port":8080,"verbosity":"error","enable_openapi":false,"jwt_secret_key":"6a599ab046dbb419014807dffd7b8823bfa7e5df56b17d545485deb87331b4ca","ws_token":"6O5pBDiRigiZrmIsofaE2rkKMJtf9h8zVQ","CORS_origins":[],"username":"freqAdmin","password":"REDACTED"},"bot_name":"freqtrade","initial_state":"running","force_entry_enable":false,"internals":{"process_throttle_secs":5,"heartbeat_interval":20,"loglevel":"DEBUG"},"config_files":["/freqtrade/config_examples/config_freqai.okx.json"]}
|
||||
1
result/backtest-result-2025-05-03_23-26-58.json
Normal file
1
result/backtest-result-2025-05-03_23-26-58.json
Normal file
File diff suppressed because one or more lines are too long
1
result/backtest-result-2025-05-03_23-26-58.meta.json
Normal file
1
result/backtest-result-2025-05-03_23-26-58.meta.json
Normal file
@ -0,0 +1 @@
|
||||
{"OKXRegressionStrategy":{"run_id":"1b652eca8bab161933a4d0dbeb6c5aabe3aa0f25","backtest_start_time":1746309788,"timeframe":"3m","timeframe_detail":null,"backtest_start_ts":1741996800,"backtest_end_ts":1744675200}}
|
||||
@ -11,6 +11,8 @@ from freqtrade.strategy import CategoricalParameter, DecimalParameter
|
||||
from xgboost import XGBRegressor
|
||||
import ccxt
|
||||
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class OKXRegressionStrategy(IStrategy):
|
||||
@ -51,6 +53,7 @@ class OKXRegressionStrategy(IStrategy):
|
||||
},
|
||||
"data_split_parameters": {
|
||||
"test_size": 0.2,
|
||||
"random_state": 42,
|
||||
"shuffle": False
|
||||
},
|
||||
"train_period_days": 90,
|
||||
@ -88,15 +91,18 @@ class OKXRegressionStrategy(IStrategy):
|
||||
# 成交量均线
|
||||
dataframe[f"%-%-volume_ma-{period}"] = ta.SMA(dataframe["volume"], timeperiod=period)
|
||||
|
||||
# OKX 订单簿特征(通过 CCXT)
|
||||
try:
|
||||
order_book = self.fetch_okx_order_book(metadata["pair"])
|
||||
dataframe[f"%-%-order_book_imbalance-{period}"] = (
|
||||
order_book["bids"] - order_book["asks"]
|
||||
) / (order_book["bids"] + order_book["asks"] + 1e-10)
|
||||
except Exception as e:
|
||||
logger.warning(f"获取 {metadata['pair']} 订单簿失败:{str(e)}")
|
||||
dataframe[f"%-%-order_book_imbalance-{period}"] = 0.0
|
||||
# 仅为 BTC/USDT 和 ETH/USDT 生成 order_book_imbalance
|
||||
#
|
||||
pair = metadata.get('pair', 'unknown')
|
||||
if pair in ["BTC/USDT", "ETH/USDT"]:
|
||||
try:
|
||||
order_book = self.fetch_okx_order_book(pair)
|
||||
dataframe[f"%-%-order_book_imbalance"] = (
|
||||
order_book["bids"] - order_book["asks"]
|
||||
) / (order_book["bids"] + order_book["asks"] + 1e-10)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch order book for {pair}: {str(e)}")
|
||||
dataframe[f"%-%-order_book_imbalance"] = 0.0
|
||||
|
||||
# 数据清洗
|
||||
dataframe = dataframe.replace([np.inf, -np.inf], np.nan)
|
||||
@ -131,28 +137,108 @@ class OKXRegressionStrategy(IStrategy):
|
||||
|
||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:
|
||||
"""
|
||||
设置回归模型的目标变量。
|
||||
设置回归模型的目标变量,为不同币对设置动态止损和ROI阈值。
|
||||
输入:dataframe(K线数据:close, high, low),metadata(交易对信息),config(FreqAI配置)
|
||||
输出:更新后的dataframe,包含目标标签
|
||||
"""
|
||||
label_period = self.freqai_config["feature_parameters"]["label_period_candles"]
|
||||
# 目标:未来价格变化
|
||||
dataframe["&-s_close"] = (
|
||||
dataframe["close"].shift(-label_period) - dataframe["close"]
|
||||
) / dataframe["close"]
|
||||
# 获取配置参数
|
||||
label_period = self.freqai_config["feature_parameters"]["label_period_candles"] # 标签预测周期(如5分钟K线的N根)
|
||||
pair = metadata["pair"] # 当前交易对(如DOGE/USDT)
|
||||
|
||||
# ROI 目标
|
||||
# 计算未来价格变化率(现有逻辑)
|
||||
dataframe["&-s_close"] = (dataframe["close"].shift(-label_period) - dataframe["close"]) / dataframe["close"]
|
||||
|
||||
# 计算不同时间窗口的ROI(现有逻辑)
|
||||
for minutes in [0, 15, 30]:
|
||||
candles = int(minutes / 5)
|
||||
candles = int(minutes / 5) # 假设5分钟K线
|
||||
if candles > 0:
|
||||
dataframe[f"&-roi_{minutes}"] = (
|
||||
dataframe["close"].shift(-candles) - dataframe["close"]
|
||||
) / dataframe["close"]
|
||||
dataframe[f"&-roi_{minutes}"] = (dataframe["close"].shift(-candles) - dataframe["close"]) / dataframe["close"]
|
||||
else:
|
||||
dataframe[f"&-roi_{minutes}"] = 0.0
|
||||
|
||||
# 动态阈值
|
||||
# 计算市场状态指标:ADX(14周期,与label_period_candles对齐)
|
||||
dataframe["adx"] = ta.ADX(dataframe["high"], dataframe["low"], dataframe["close"], timeperiod=14)
|
||||
|
||||
# 定义币对特定的ADX阈值和止损/ROI范围
|
||||
pair_thresholds = {
|
||||
"DOGE/USDT": {
|
||||
"adx_trend": 20, # 趋势市场ADX阈值
|
||||
"adx_oscillation": 15, # 震荡市场ADX阈值
|
||||
"stoploss_trend": -0.08, # 趋势市场止损:-8%
|
||||
"stoploss_oscillation": -0.04, # 震荡市场止损:-4%
|
||||
"stoploss_mid": -0.06, # 中间状态止损:-6%
|
||||
"roi_trend": 0.06, # 趋势市场ROI:6%
|
||||
"roi_oscillation": 0.025, # 震荡市场ROI:2.5%
|
||||
"roi_mid": 0.04 # 中间状态ROI:4%
|
||||
},
|
||||
"BTC/USDT": {
|
||||
"adx_trend": 25,
|
||||
"adx_oscillation": 20,
|
||||
"stoploss_trend": -0.03,
|
||||
"stoploss_oscillation": -0.015,
|
||||
"stoploss_mid": -0.02,
|
||||
"roi_trend": 0.03,
|
||||
"roi_oscillation": 0.015,
|
||||
"roi_mid": 0.02
|
||||
},
|
||||
"SOL/USDT": {
|
||||
"adx_trend": 22,
|
||||
"adx_oscillation": 18,
|
||||
"stoploss_trend": -0.06,
|
||||
"stoploss_oscillation": -0.03,
|
||||
"stoploss_mid": -0.045,
|
||||
"roi_trend": 0.045,
|
||||
"roi_oscillation": 0.02,
|
||||
"roi_mid": 0.03
|
||||
},
|
||||
"XRP/USDT": {
|
||||
"adx_trend": 22,
|
||||
"adx_oscillation": 18,
|
||||
"stoploss_trend": -0.06,
|
||||
"stoploss_oscillation": -0.03,
|
||||
"stoploss_mid": -0.045,
|
||||
"roi_trend": 0.045,
|
||||
"roi_oscillation": 0.02,
|
||||
"roi_mid": 0.03
|
||||
}
|
||||
}
|
||||
|
||||
# 动态化 &-stoploss_pred(基于市场状态和币对)
|
||||
dataframe["&-stoploss_pred"] = 0.0
|
||||
for index, row in dataframe.iterrows():
|
||||
thresholds = pair_thresholds.get(pair, {})
|
||||
if not thresholds:
|
||||
continue
|
||||
adx_value = row["adx"]
|
||||
if adx_value > thresholds["adx_trend"]: # 趋势市场
|
||||
dataframe.at[index, "&-stoploss_pred"] = thresholds["stoploss_trend"] # 宽松止损
|
||||
elif adx_value < thresholds["adx_oscillation"]: # 震荡市场
|
||||
dataframe.at[index, "&-stoploss_pred"] = thresholds["stoploss_oscillation"] # 严格止损
|
||||
else: # 中间状态
|
||||
dataframe.at[index, "&-stoploss_pred"] = thresholds["stoploss_mid"] # 中等止损
|
||||
# 风险控制:设置止损下限
|
||||
if dataframe.at[index, "&-stoploss_pred"] < -0.10:
|
||||
dataframe.at[index, "&-stoploss_pred"] = -0.10
|
||||
|
||||
# 动态化 &-roi_0_pred(基于市场趋势和币对)
|
||||
dataframe["&-roi_0_pred"] = 0.0
|
||||
for index, row in dataframe.iterrows():
|
||||
thresholds = pair_thresholds.get(pair, {})
|
||||
if not thresholds:
|
||||
continue
|
||||
adx_value = row["adx"]
|
||||
if adx_value > thresholds["adx_trend"]: # 强趋势市场
|
||||
dataframe.at[index, "&-roi_0_pred"] = thresholds["roi_trend"] # 高ROI
|
||||
elif adx_value < thresholds["adx_oscillation"]: # 震荡市场
|
||||
dataframe.at[index, "&-roi_0_pred"] = thresholds["roi_oscillation"] # 低ROI
|
||||
else: # 中间状态
|
||||
dataframe.at[index, "&-roi_0_pred"] = thresholds["roi_mid"] # 中等ROI
|
||||
# 风险控制:设置ROI上限
|
||||
if dataframe.at[index, "&-roi_0_pred"] > 0.10:
|
||||
dataframe.at[index, "&-roi_0_pred"] = 0.10
|
||||
|
||||
# 计算RSI预测(现有逻辑)
|
||||
dataframe["&-buy_rsi_pred"] = ta.RSI(dataframe["close"], timeperiod=14).rolling(20).mean()
|
||||
dataframe["&-stoploss_pred"] = -0.05
|
||||
dataframe["&-roi_0_pred"] = 0.03
|
||||
|
||||
# 数据清洗
|
||||
dataframe = dataframe.replace([np.inf, -np.inf], np.nan)
|
||||
@ -241,10 +327,17 @@ class OKXRegressionStrategy(IStrategy):
|
||||
|
||||
return dataframe
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: Dict) -> DataFrame:
|
||||
dataframe['atr'] = dataframe['ATR_14']
|
||||
# 确保 ATR 列存在
|
||||
if 'ATR_14' not in dataframe.columns:
|
||||
dataframe['ATR_14'] = 0.0
|
||||
|
||||
# 计算动态止损线
|
||||
dataframe['stop_loss_line'] = dataframe['entry_price'] - (dataframe['ATR_14'] * 2)
|
||||
|
||||
# 发送止损信息
|
||||
self.dp.send_msg(f"ATR: {dataframe['ATR_14'].iloc[-1]:.5f}, Stop Loss Line: {dataframe['stop_loss_line'].iloc[-1]:.5f}")
|
||||
|
||||
# 应用动态止损逻辑
|
||||
return self._dynamic_stop_loss(dataframe, metadata)
|
||||
|
||||
def custom_stake_amount(self, pair: str, current_time: 'datetime', current_rate: float,
|
||||
1
result/backtest-result-2025-05-03_23-26-58_config.json
Normal file
1
result/backtest-result-2025-05-03_23-26-58_config.json
Normal file
@ -0,0 +1 @@
|
||||
{"$schema":"https://schema.freqtrade.io/schema.json","trading_mode":"spot","margin_mode":"isolated","max_open_trades":4,"stake_currency":"USDT","stake_amount":150,"startup_candle_count":30,"tradable_balance_ratio":1,"fiat_display_currency":"USD","dry_run":true,"timeframe":"3m","dry_run_wallet":1000,"cancel_open_orders_on_exit":true,"stoploss":-0.05,"unfilledtimeout":{"entry":5,"exit":15},"exchange":{"name":"okx","key":"REDACTED","secret":"REDACTED","enable_ws":false,"ccxt_config":{"enableRateLimit":true,"rateLimit":500,"options":{"defaultType":"spot"}},"ccxt_async_config":{"enableRateLimit":true,"rateLimit":500,"timeout":20000},"pair_whitelist":["OKB/USDT","TON/USDT"],"pair_blacklist":[]},"entry_pricing":{"price_side":"same","use_order_book":true,"order_book_top":1,"price_last_balance":0.0,"check_depth_of_market":{"enabled":false,"bids_to_ask_delta":1}},"exit_pricing":{"price_side":"other","use_order_book":true,"order_book_top":1},"pairlists":[{"method":"StaticPairList"}],"freqai":{"enabled":true,"identifier":"test175","freqaimodel":"XGBoostRegressor","purge_old_models":2,"train_period_days":90,"backtest_period_days":10,"live_retrain_hours":0,"data_kitchen":{"fillna":"ffill","feature_parameters":{"DI_threshold":0.5,"weight_factor":0.9}},"feature_parameters":{"include_timeframes":["3m"],"include_corr_pairlist":["BTC/USDT","ETH/USDT"],"label_period_candles":12,"include_shifted_candles":3,"indicator_periods_candles":[10,20,50],"plot_feature_importances":1,"feature_selection":{"method":"none"}},"data_split_parameters":{"test_size":0.2,"shuffle":false,"random_state":42},"model_training_parameters":{"n_estimators":500,"learning_rate":0.015,"max_depth":6,"subsample":0.9,"colsample_bytree":0.9,"objective":"reg:squarederror","eval_metric":"rmse","early_stopping_rounds":150,"reg_alpha":0.1,"reg_lambda":1.0}},"api_server":{"enabled":true,"listen_ip_address":"0.0.0.0","listen_port":8080,"verbosity":"error","enable_openapi":false,"jwt_secret_key":"6a599ab046dbb419014807dffd7b8823bfa7e5df56b17d545485deb87331b4ca","ws_token":"6O5pBDiRigiZrmIsofaE2rkKMJtf9h8zVQ","CORS_origins":[],"username":"freqAdmin","password":"REDACTED"},"bot_name":"freqtrade","initial_state":"running","force_entry_enable":false,"internals":{"process_throttle_secs":5,"heartbeat_interval":20,"loglevel":"DEBUG"},"config_files":["/freqtrade/config_examples/config_freqai.okx.json"]}
|
||||
30789
result/output_filted.log
30789
result/output_filted.log
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user