From 1d356be4022ce681a5dec182c76babca99d468a6 Mon Sep 17 00:00:00 2001 From: tinkle Date: Wed, 29 Oct 2025 18:08:36 +0800 Subject: [PATCH] Fix: Correct Sharpe Ratio calculation by using proper equity values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- logger/decision_logger.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/logger/decision_logger.go b/logger/decision_logger.go index 4237c35c..e5acba8b 100644 --- a/logger/decision_logger.go +++ b/logger/decision_logger.go @@ -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) }