Skip to content

Commit abf7797

Browse files
fix: division by zero in RSI calculation and README formatting (ValueCell-ai#226)
This PR addresses two issues: 1. Critical bug fix: Division by zero in RSI calculation 2. Documentation fix: Missing bullet point in Traditional Chinese README ## Type of Change Type of Change: Bug Fix / Documentation Update ## Changes Made ### Critical Bug Fix - **File**: `python/valuecell/agents/auto_trading_agent/market_data.py` - **Issue**: Division by zero error in RSI calculation when loss is zero - **Impact**: Application crash during technical analysis when there are no downward price movements - **Solution**: Replace zero loss values with infinity, resulting in RSI = 100 (maximum strength) - **Why this is correct**: When there are no losses, all movement is gains, which means maximum relative strength ### Documentation Fix - **File**: `README.zh_Hant.md` - **Issue**: Missing bullet point marker before Trading Agents section - **Solution**: Added `-` marker for consistency with other language versions ## Testing - [x] Verified the markdown renders correctly - [x] Reviewed RSI calculation logic for edge cases - [x] Confirmed fix prevents ZeroDivisionError ## Checklist - [x] I have read the Code of Conduct - [x] I have followed the Contributing Guidelines - [x] My changes follow the project's coding style
1 parent 4573197 commit abf7797

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

README.zh_Hant.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ ValueCell 是一個社群驅動的多智能體金融應用平台。
6363

6464

6565
## 多智能體系統
66-
- **DeepResearch Agent**:獲取並分析股票的 SEC 文件輸出準確的數據與可解釋的總結
66+
- **DeepResearch Agent**:獲取並分析股票的 SEC 文件,輸出準確的數據與可解釋的總結
6767
- **Auto Trading Agent**:支援多種加密資產與 AI 自動交易策略
68-
**Trading Agents**: 專責市場分析、情緒分析、新聞分析與基本面分析的智能體協同運作
68+
- **Trading Agents**: 專責市場分析、情緒分析、新聞分析與基本面分析的智能體協同運作
6969
- **AI-Hedge-Fund**:智能體協作提供全面的金融洞見
7070
- **其他智能體**:更多智能體正在規劃中…
7171

python/valuecell/agents/auto_trading_agent/market_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def _calculate_rsi(df: pd.DataFrame, period: int = 14):
111111
delta = df["Close"].diff()
112112
gain = (delta.where(delta > 0, 0)).rolling(window=period).mean()
113113
loss = (-delta.where(delta < 0, 0)).rolling(window=period).mean()
114-
rs = gain / loss
114+
# Avoid division by zero: if loss is 0, RSI = 100 (maximum strength)
115+
rs = gain / loss.replace(0, float("inf"))
115116
df["rsi"] = 100 - (100 / (1 + rs))
116117

117118
@staticmethod

0 commit comments

Comments
 (0)