fix: rsi NaN 错误
This commit is contained in:
@@ -478,6 +478,11 @@ class StockAnalyzer:
|
||||
latest = df.iloc[-1]
|
||||
prev = df.iloc[-2]
|
||||
|
||||
# 处理 RSI 的 NaN 值
|
||||
rsi_value = latest['RSI']
|
||||
if pd.isna(rsi_value):
|
||||
rsi_value = None
|
||||
|
||||
# 生成报告(保持原有格式)
|
||||
report = {
|
||||
'stock_code': stock_code,
|
||||
@@ -486,7 +491,7 @@ class StockAnalyzer:
|
||||
'price': latest['close'],
|
||||
'price_change': (latest['close'] - prev['close']) / prev['close'] * 100,
|
||||
'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',
|
||||
'volume_status': 'HIGH' if latest['Volume_Ratio'] > 1.5 else 'NORMAL',
|
||||
'recommendation': self.get_recommendation(score)
|
||||
|
||||
@@ -772,9 +772,9 @@
|
||||
<span class="text-gray-600">投资建议</span>
|
||||
<span class="font-medium text-purple-600">${result.recommendation}</span>
|
||||
</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="font-medium">${result.rsi.toFixed(2)}</span>
|
||||
<span class="font-medium">${result.rsi !== null ? result.rsi.toFixed(2) : '暂无数据'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user