Fix: Correct Sharpe Ratio calculation by using proper equity values

Critical bug fix in Sharpe Ratio calculation logic:

Problem:
- Previously calculated equity as TotalBalance + TotalUnrealizedProfit
- This was incorrect because TotalBalance already stores TotalEquity
- TotalUnrealizedProfit actually stores TotalPnL (not unrealized profit)
- This caused: equity = 2 * TotalEquity - InitialBalance (wrong!)

Root cause:
- Field naming mismatch between AccountSnapshot and actual stored values
- TotalBalance field actually contains TotalEquity (wallet + unrealized)
- TotalUnrealizedProfit field actually contains TotalPnL (equity - initial)

Solution:
- Use TotalBalance directly as it already represents complete account equity
- Added clear comments explaining the field name vs content mismatch
- Sharpe Ratio now correctly calculates risk-adjusted returns

Impact:
- Sharpe Ratio values are now mathematically accurate
- AI performance assessment is now reliable
- No changes needed to data storage or API layer

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tinkle
2025-10-29 18:08:36 +08:00
parent a0ce1e20a9
commit 1d356be402

View File

@@ -494,9 +494,12 @@ func (l *DecisionLogger) calculateSharpeRatio(records []*DecisionRecord) float64
}
// 提取每个周期的账户净值
// 注意TotalBalance字段实际存储的是TotalEquity账户总净值
// TotalUnrealizedProfit字段实际存储的是TotalPnL相对初始余额的盈亏
var equities []float64
for _, record := range records {
equity := record.AccountState.TotalBalance + record.AccountState.TotalUnrealizedProfit
// 直接使用TotalBalance因为它已经是完整的账户净值
equity := record.AccountState.TotalBalance
if equity > 0 {
equities = append(equities, equity)
}