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
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
tinkle-community
2025-10-29 18:08:36 +08:00
parent b9ea3f68ea
commit 683ae58563

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)
}