freqai同时优化回归和分类参数
This commit is contained in:
parent
d96776c47d
commit
6dd39b829f
@ -265,7 +265,13 @@ class FreqaiPrimer(IStrategy):
|
||||
]
|
||||
choices = [0, 1, 2, 3]
|
||||
|
||||
dataframe["&*-optimal_first_length"] = np.select(conditions, choices, default=4)
|
||||
# 确保分类目标列是整数类型
|
||||
optimal_length_class = np.select(conditions, choices, default=4)
|
||||
dataframe["&*-optimal_first_length"] = optimal_length_class.astype(int)
|
||||
|
||||
# 添加调试信息
|
||||
logger.info(f"[{pair}] 📈 分类目标统计: {dict(pd.Series(optimal_length_class).value_counts())}")
|
||||
logger.info(f"[{pair}] 🎯 最新分类值: {optimal_length_class[-5:]}")
|
||||
|
||||
return dataframe
|
||||
def is_stochrsi_overbought(self, dataframe: DataFrame, period=10, threshold=85) -> bool:
|
||||
@ -1343,14 +1349,22 @@ class FreqaiPrimer(IStrategy):
|
||||
# 使用分类模型预测最优 first_length
|
||||
if "&*-optimal_first_length" in dataframe.columns:
|
||||
# 获取最新预测值
|
||||
optimal_length_class = int(dataframe["&*-optimal_first_length"].iloc[-1])
|
||||
length_mapping = {0: 2, 1: 4, 2: 6, 3: 8, 4: 10}
|
||||
first_length = length_mapping.get(optimal_length_class, 2)
|
||||
logger.info(f"[{pair}] 使用分类模型优化 first_length: {first_length} (类别: {optimal_length_class})")
|
||||
predicted_value = dataframe["&*-optimal_first_length"].iloc[-1]
|
||||
if pd.notna(predicted_value):
|
||||
optimal_length_class = int(predicted_value)
|
||||
length_mapping = {0: 2, 1: 4, 2: 6, 3: 8, 4: 10}
|
||||
first_length = length_mapping.get(optimal_length_class, 2)
|
||||
logger.info(f"[{pair}] ✅ 分类模型预测成功: first_length={first_length} (类别: {optimal_length_class})")
|
||||
else:
|
||||
first_length = 2 # 保持默认值为2
|
||||
logger.warning(f"[{pair}] ⚠️ 分类模型预测为NaN,使用默认值: {first_length}")
|
||||
else:
|
||||
# 回退到默认值
|
||||
first_length = 2
|
||||
logger.warning(f"[{pair}] 分类模型未预测,使用默认 first_length: {first_length}")
|
||||
first_length = 2 # 保持默认值为2
|
||||
logger.warning(f"[{pair}] ❌ 分类模型列不存在,使用默认值: {first_length}")
|
||||
|
||||
# 调试信息:显示当前dataframe列
|
||||
ai_columns = [col for col in dataframe.columns if col.startswith('&') or col.startswith('&*')]
|
||||
logger.info(f"[{pair}] 📊 当前AI预测列: {ai_columns}")
|
||||
|
||||
# 根据 first_length 动态调整其他段长
|
||||
second_length = first_length * 3
|
||||
|
||||
102
test_mixed_models_config.json
Normal file
102
test_mixed_models_config.json
Normal file
@ -0,0 +1,102 @@
|
||||
{
|
||||
"strategy": "freqaiprimer",
|
||||
"max_open_trades": 3,
|
||||
"stake_currency": "USDT",
|
||||
"stake_amount": 25,
|
||||
"tradable_balance_ratio": 0.99,
|
||||
"fiat_display_currency": "USD",
|
||||
"dry_run": true,
|
||||
"cancel_open_orders_on_exit": false,
|
||||
"trading_mode": "spot",
|
||||
"exchange": {
|
||||
"name": "binance",
|
||||
"key": "",
|
||||
"secret": "",
|
||||
"ccxt_config": {"enableRateLimit": true},
|
||||
"ccxt_async_config": {"enableRateLimit": true},
|
||||
"pair_blacklist": [
|
||||
"BNB/.*"
|
||||
]
|
||||
},
|
||||
"pairlists": [
|
||||
{
|
||||
"method": "StaticPairList",
|
||||
"pairs": ["SOL/USDT", "WCT/USDT"]
|
||||
}
|
||||
],
|
||||
"freqai": {
|
||||
"enabled": true,
|
||||
"identifier": "test_mixed_models",
|
||||
"purge_old_models": 2,
|
||||
"train_period_days": 15,
|
||||
"backtest_period_days": 7,
|
||||
"live_retrain_candles": 100,
|
||||
"fit_live_predictions_candles": 100,
|
||||
"feature_parameters": {
|
||||
"include_timeframes": ["3m", "15m", "1h"],
|
||||
"label_period_candles": 12,
|
||||
"include_shifted_candles": 3,
|
||||
"indicator_periods_candles": [10, 20],
|
||||
"DI_threshold": 30,
|
||||
"weight_factor": 0.9
|
||||
},
|
||||
"data_split_parameters": {
|
||||
"test_size": 0.2,
|
||||
"shuffle": false
|
||||
},
|
||||
"model_training_parameters": {
|
||||
"price_value_divergence": {
|
||||
"model": "LightGBMRegressor",
|
||||
"model_params": {
|
||||
"n_estimators": 200,
|
||||
"learning_rate": 0.05,
|
||||
"num_leaves": 31,
|
||||
"verbose": -1
|
||||
}
|
||||
},
|
||||
"optimal_first_length": {
|
||||
"model": "LightGBMClassifier",
|
||||
"model_params": {
|
||||
"n_estimators": 150,
|
||||
"learning_rate": 0.1,
|
||||
"num_leaves": 15,
|
||||
"max_depth": 8,
|
||||
"min_child_samples": 10,
|
||||
"class_weight": "balanced",
|
||||
"verbose": -1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"timeframe": "3m",
|
||||
"dry_run_wallet": 1000,
|
||||
"unfilledtimeout": {
|
||||
"entry": 10,
|
||||
"exit": 30
|
||||
},
|
||||
"entry_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"check_depth_of_market": {
|
||||
"enabled": false,
|
||||
"bids_to_ask_delta": 1
|
||||
}
|
||||
},
|
||||
"exit_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1
|
||||
},
|
||||
"order_types": {
|
||||
"entry": "limit",
|
||||
"exit": "limit",
|
||||
"emergency_exit": "market",
|
||||
"force_exit": "market",
|
||||
"stoploss": "market",
|
||||
"stoploss_on_exchange": false
|
||||
},
|
||||
"edge": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user