mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
Fix: Ensure Sharpe ratio is always visible to AI
Problem: When TotalTrades == 0 (no completed trades), formatPerformanceFeedback would return early, hiding Sharpe ratio and adaptive behavior recommendations from AI's prompt. This caused AI to say "no historical data" even though Sharpe ratio was calculated and displayed on frontend. Solution: - Display Sharpe ratio BEFORE checking TotalTrades - Don't return early when TotalTrades == 0 - Always show adaptive behavior recommendations if Sharpe ratio exists - Sharpe ratio is calculated from account equity changes, not just closed trades Impact: AI can now properly use Sharpe ratio for self-evolution, even in early stages before any trades are closed. Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
@@ -567,28 +567,28 @@ func formatPerformanceFeedback(perfInterface interface{}, accountEquity float64)
|
||||
|
||||
sb.WriteString("## 📊 历史表现反馈\n\n")
|
||||
|
||||
if perf.TotalTrades == 0 {
|
||||
sb.WriteString("暂无历史交易数据\n\n")
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// 整体统计
|
||||
sb.WriteString("### 整体表现\n")
|
||||
sb.WriteString(fmt.Sprintf("- **总交易数**: %d 笔 (盈利: %d | 亏损: %d)\n",
|
||||
perf.TotalTrades, perf.WinningTrades, perf.LosingTrades))
|
||||
sb.WriteString(fmt.Sprintf("- **胜率**: %.1f%%\n", perf.WinRate))
|
||||
sb.WriteString(fmt.Sprintf("- **平均盈利**: +%.2f%% | 平均亏损: %.2f%%\n",
|
||||
perf.AvgWin, perf.AvgLoss))
|
||||
if perf.ProfitFactor > 0 {
|
||||
sb.WriteString(fmt.Sprintf("- **盈亏比**: %.2f:1\n", perf.ProfitFactor))
|
||||
}
|
||||
|
||||
// 夏普比率(风险调整后收益)
|
||||
// 夏普比率(风险调整后收益)- 即使没有完成交易也要显示!
|
||||
if perf.SharpeRatio != 0 {
|
||||
sharpeStatus := interpretSharpeRatio(perf.SharpeRatio)
|
||||
sb.WriteString(fmt.Sprintf("- **夏普比率**: %.2f (%s)\n", perf.SharpeRatio, sharpeStatus))
|
||||
sb.WriteString(fmt.Sprintf("**夏普比率**: %.2f (%s)\n\n", perf.SharpeRatio, sharpeStatus))
|
||||
}
|
||||
|
||||
if perf.TotalTrades == 0 {
|
||||
sb.WriteString("暂无已完成交易(仅基于账户净值变化计算夏普比率)\n\n")
|
||||
// ⚠️ 不要提前返回!继续显示自适应建议
|
||||
} else {
|
||||
// 整体统计(有已完成交易时才显示)
|
||||
sb.WriteString("### 整体表现\n")
|
||||
sb.WriteString(fmt.Sprintf("- **总交易数**: %d 笔 (盈利: %d | 亏损: %d)\n",
|
||||
perf.TotalTrades, perf.WinningTrades, perf.LosingTrades))
|
||||
sb.WriteString(fmt.Sprintf("- **胜率**: %.1f%%\n", perf.WinRate))
|
||||
sb.WriteString(fmt.Sprintf("- **平均盈利**: +%.2f%% | 平均亏损: %.2f%%\n",
|
||||
perf.AvgWin, perf.AvgLoss))
|
||||
if perf.ProfitFactor > 0 {
|
||||
sb.WriteString(fmt.Sprintf("- **盈亏比**: %.2f:1\n", perf.ProfitFactor))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
|
||||
// 最近交易
|
||||
if len(perf.RecentTrades) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user