分段长度用freqai优化
This commit is contained in:
parent
32089fbf18
commit
2673588121
@ -1443,9 +1443,42 @@ class FreqaiPrimer(IStrategy):
|
||||
# 使用FreqAI模型预测
|
||||
predictions = self.freqai.predict(features, metadata)
|
||||
|
||||
# 调试:记录预测结果的类型和结构
|
||||
logger.debug(f"[{pair}] FreqAI预测结果类型: {type(predictions)}, 内容: {predictions}")
|
||||
|
||||
# 获取第一段长度预测值
|
||||
if 'trend_segment_length' in predictions:
|
||||
predicted_length = int(predictions['trend_segment_length'])
|
||||
predicted_length = 2 # 默认值
|
||||
try:
|
||||
if isinstance(predictions, dict):
|
||||
if 'trend_segment_length' in predictions:
|
||||
predicted_length = int(predictions['trend_segment_length'])
|
||||
elif 'prediction' in predictions:
|
||||
predicted_length = int(predictions['prediction'])
|
||||
else:
|
||||
# 尝试获取字典中的第一个数值
|
||||
for key, value in predictions.items():
|
||||
if isinstance(value, (int, float, np.number)):
|
||||
predicted_length = int(value)
|
||||
break
|
||||
elif isinstance(predictions, (list, tuple)) and len(predictions) > 0:
|
||||
# 如果是列表或元组,使用第一个预测值
|
||||
first_pred = predictions[0]
|
||||
if isinstance(first_pred, dict):
|
||||
if 'trend_segment_length' in first_pred:
|
||||
predicted_length = int(first_pred['trend_segment_length'])
|
||||
else:
|
||||
predicted_length = int(list(first_pred.values())[0])
|
||||
else:
|
||||
predicted_length = int(first_pred)
|
||||
elif hasattr(predictions, 'trend_segment_length'):
|
||||
# 如果是对象属性
|
||||
predicted_length = int(predictions.trend_segment_length)
|
||||
else:
|
||||
logger.warning(f"[{pair}] 无法识别的预测格式,使用默认段长2")
|
||||
|
||||
except (ValueError, IndexError, TypeError) as e:
|
||||
logger.error(f"[{pair}] 解析预测结果失败: {e}, 使用默认段长2")
|
||||
predicted_length = 2
|
||||
# 确保在有效范围内
|
||||
predicted_length = max(1, min(5, predicted_length))
|
||||
logger.info(f"[{pair}] FreqAI预测段长: {predicted_length} (比例: {predicted_length}:{predicted_length*3}:{predicted_length*5})")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user