fix: rsi NaN 错误

This commit is contained in:
兰志宏
2025-03-05 09:34:20 +08:00
parent bbf01ac5fe
commit af6ff20f8c
2 changed files with 8 additions and 3 deletions

View File

@@ -478,6 +478,11 @@ class StockAnalyzer:
latest = df.iloc[-1] latest = df.iloc[-1]
prev = df.iloc[-2] prev = df.iloc[-2]
# 处理 RSI 的 NaN 值
rsi_value = latest['RSI']
if pd.isna(rsi_value):
rsi_value = None
# 生成报告(保持原有格式) # 生成报告(保持原有格式)
report = { report = {
'stock_code': stock_code, 'stock_code': stock_code,
@@ -486,7 +491,7 @@ class StockAnalyzer:
'price': latest['close'], 'price': latest['close'],
'price_change': (latest['close'] - prev['close']) / prev['close'] * 100, 'price_change': (latest['close'] - prev['close']) / prev['close'] * 100,
'ma_trend': 'UP' if latest['MA5'] > latest['MA20'] else 'DOWN', 'ma_trend': 'UP' if latest['MA5'] > latest['MA20'] else 'DOWN',
'rsi': latest['RSI'], 'rsi': rsi_value, # 使用处理后的 RSI 值
'macd_signal': 'BUY' if latest['MACD'] > latest['Signal'] else 'SELL', 'macd_signal': 'BUY' if latest['MACD'] > latest['Signal'] else 'SELL',
'volume_status': 'HIGH' if latest['Volume_Ratio'] > 1.5 else 'NORMAL', 'volume_status': 'HIGH' if latest['Volume_Ratio'] > 1.5 else 'NORMAL',
'recommendation': self.get_recommendation(score) 'recommendation': self.get_recommendation(score)

View File

@@ -774,7 +774,7 @@
</div> </div>
<div class="flex justify-between items-center p-3 bg-gray-50 rounded"> <div class="flex justify-between items-center p-3 bg-gray-50 rounded">
<span class="text-gray-600">RSI指标</span> <span class="text-gray-600">RSI指标</span>
<span class="font-medium">${result.rsi.toFixed(2)}</span> <span class="font-medium">${result.rsi !== null ? result.rsi.toFixed(2) : '暂无数据'}</span>
</div> </div>
</div> </div>
</div> </div>