k_sell和k_buy改成用线性函数映射

This commit is contained in:
zhangkun9038@dingtalk.com 2025-06-23 18:33:15 +08:00
parent db95f4bb58
commit e2e7a1acf3

View File

@ -95,6 +95,10 @@ class FreqaiPrimer(IStrategy):
"live_retrain_candles": 100,
}
@staticmethod
def linear_map(value, from_min, from_max, to_min, to_max):
return (value - from_min) / (from_max - from_min) * (to_max - to_min) + to_min
def __init__(self, config: dict, *args, **kwargs):
super().__init__(config, *args, **kwargs)
logger.setLevel(logging.DEBUG)
@ -242,22 +246,10 @@ class FreqaiPrimer(IStrategy):
labels_std = 0.01
logger.warning(f"[{pair}] labels_std 计算异常,使用默认值 0.01")
# 根据市场趋势动态调整买卖阈值
market_trend = self.get_market_trend()
k_buy = 1.0
k_sell = 1.2
if market_trend == 'bull':
k_buy = 0.8 # 放宽买入阈值
k_sell = 1.0 # 收紧卖出阈值
elif market_trend == 'bear':
k_buy = 1.2 # 收紧买入阈值
k_sell = 1.5 # 放宽卖出阈值
else:
k_buy = 1.0
k_sell = 1.2
if labels_mean > 0.015:
k_sell += 0.5
# 根据市场趋势得分动态调整买卖阈值
market_trend_score = self.get_market_trend()
k_buy = FreqaiPrimer.linear_map(market_trend_score, 0, 100, 1.2, 0.8)
k_sell = FreqaiPrimer.linear_map(market_trend_score, 0, 100, 1.5, 1.0)
self.buy_threshold = labels_mean - k_buy * labels_std
self.sell_threshold = labels_mean + k_sell * labels_std