mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-06-06 05:51:19 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user