- Location
- stock_screener.py:96
- Finding
- Fabricated Financial Metrics and Trading Results Presented as Analysis## Vulnerability Details
**File Location**: `stock_screener.py:96-108`
**Vulnerability Type**: Fabricated financial analytics and nondeterministic trading output
**Risk Level**: High
### Vulnerable Code
The stock screener generates random fundamentals:
```python
def get_financial_data(self, symbol):
"""获取财务数据(简化版)"""
try:
# 这里需要更复杂的财务数据获取
# 暂时返回模拟数据
return {
'ROE': np.random.uniform(-10, 20), # 模拟ROE
'current_ratio': np.random.uniform(0.3, 2.0), # 流动比率
'market_cap': np.random.uniform(10, 500) * 100000000, # 市值(元)
}
except:
# 如果获取失败,返回默认值
return {
'ROE': 0,
'current_ratio': 1.0,
'market_cap': 10000000000,
}
```
Those random values are used as screening criteria at `stock_screener.py:210-309`, including:
```python
financials = self.get_financial_data(symbol)
roe = financials['ROE']
if not (-20 < roe < 15):
passed = False
current_ratio = financials['current_ratio']
if current_ratio < 0.4:
passed = False
market_cap = financials['market_cap']
if market_cap >= 100 * 100000000:
passed = False
```
Strategy performance is randomly generated at `strategy_gen.py:94-101`:
```python
base_strategy["performance"] = {
"win_rate": random.uniform(0.55, 0.75),
"profit_factor": random.uniform(1.2, 2.0),
"total_return": random.uniform(0.1, 0.3),
"max_drawdown": random.uniform(0.08, 0.15)
}
```
Backtest results are randomly generated at `strategy_gen.py:209-239`:
```python
return {
"success": True,
"strategy_name": strategy_name,
"symbol": symbol,
"period": f"{days}天",
"results": {
"total_trades": random.randint(10, 30),
"winning_trades": random.randint(7, 20),
"losing_trades": random.randint(3, 10),
"win_rate": round(random.uniform(0.6, 0.8) * 100, 1),
"total_return": round(random.uniform(0.15, 0.35) * 100, 1),
"annual_return": round(r
...[truncated 3205 chars]
- Remediation
- ## Remediation Suggestions
1. Remove random values from all production screening, strategy, backtest, and automatic-trading paths.
2. Retrieve fundamentals from a documented, validated data source and record source timestamps.
3. Implement deterministic backtesting over actual historical data, including fees, slippage, survivorship bias, and data-adjustment policy.
4. Derive signals from explicit strategy conditions and verified prices rather than random selection.
5. Validate consistency among total, winning, and losing trade counts.
6. Clearly separate demo mode from production mode at the API and user-interface levels.
7. If synthetic data is retained, require explicit opt-in and label every response prominently as synthetic and unsuitable for investment decisions.
8. Block demo-generated results from automatic execution.
9. Add reproducibility tests and retain input datasets, strategy versions, parameters, and calculation logs.
10. Fail closed when required financial data is unavailable instead of supplying plausible-looking defaults.