Make analytics granular - individual tools + selective analyze_report

**Granular Analytics Tools (8 new tools):**
- analyze_monthly_pnl - Monthly profit/loss breakdown
- analyze_drawdown_events - Drawdown events from balance curve
- analyze_top_losses - Top N worst losses with grid depth
- analyze_loss_sequences - Consecutive loss streaks analysis
- analyze_position_pairs - Entry/exit position pairs
- analyze_direction_bias - Long vs Short performance stats
- analyze_streaks - Win/loss streaks with dates
- analyze_concurrent_peak - Peak concurrent open positions

**Updated analyze_report:**
- Now supports selective analytics via 'analytics' array parameter
- Runs all analytics by default (backward compatible)
- Optional top_losses_limit parameter
- Returns list of analytics that were run

**Changes:**
- analytics/analyze.rs: Made all analysis methods public
- tools/definitions.rs: Added 8 new tool definitions + updated analyze_report schema
- tools/handlers/mod.rs: Added dispatch for new tools
- tools/handlers/analysis.rs: Added helper load_report_data() + 8 granular handlers + selective analyze_report logic
This commit is contained in:
Devid HW
2026-04-19 02:13:33 +07:00
parent e94ec8153d
commit 1f63505cb9
4 changed files with 339 additions and 17 deletions
+123 -1
View File
@@ -6,6 +6,14 @@ pub fn get_tools_list() -> Value {
tool_run_optimization(),
tool_get_optimization_results(),
tool_analyze_report(),
tool_analyze_monthly_pnl(),
tool_analyze_drawdown_events(),
tool_analyze_top_losses(),
tool_analyze_loss_sequences(),
tool_analyze_position_pairs(),
tool_analyze_direction_bias(),
tool_analyze_streaks(),
tool_analyze_concurrent_peak(),
tool_compare_baseline(),
tool_compile_ea(),
tool_verify_setup(),
@@ -109,7 +117,121 @@ fn tool_get_optimization_results() -> Value {
fn tool_analyze_report() -> Value {
json!({
"name": "analyze_report",
"description": "Read and summarize a completed backtest report",
"description": "Run comprehensive analytics on a backtest report. By default runs all analytics. Use 'analytics' array to run specific ones: monthly_pnl, drawdown_events, top_losses, loss_sequences, position_pairs, direction_bias, streak_analysis, concurrent_peak",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string", "description": "Path to report directory containing deals.csv" },
"analytics": {
"type": "array",
"description": "Optional: specific analytics to run. If omitted, runs all.",
"items": {
"type": "string",
"enum": ["monthly_pnl", "drawdown_events", "top_losses", "loss_sequences", "position_pairs", "direction_bias", "streak_analysis", "concurrent_peak"]
}
},
"top_losses_limit": { "type": "integer", "description": "Number of top losses to return (default: 10)" }
}
}
})
}
fn tool_analyze_monthly_pnl() -> Value {
json!({
"name": "analyze_monthly_pnl",
"description": "Analyze monthly profit/loss breakdown from a backtest report",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string", "description": "Path to report directory containing deals.csv" }
}
}
})
}
fn tool_analyze_drawdown_events() -> Value {
json!({
"name": "analyze_drawdown_events",
"description": "Analyze drawdown events reconstructed from balance curve",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string" }
}
}
})
}
fn tool_analyze_top_losses() -> Value {
json!({
"name": "analyze_top_losses",
"description": "Get top N worst losses with grid depth analysis",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string" },
"limit": { "type": "integer", "description": "Number of losses to return (default: 10)", "default": 10 }
}
}
})
}
fn tool_analyze_loss_sequences() -> Value {
json!({
"name": "analyze_loss_sequences",
"description": "Analyze consecutive loss streaks and their impact",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string" }
}
}
})
}
fn tool_analyze_position_pairs() -> Value {
json!({
"name": "analyze_position_pairs",
"description": "Analyze entry/exit position pairs and their performance",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string" }
}
}
})
}
fn tool_analyze_direction_bias() -> Value {
json!({
"name": "analyze_direction_bias",
"description": "Analyze long vs short performance bias",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string" }
}
}
})
}
fn tool_analyze_streaks() -> Value {
json!({
"name": "analyze_streaks",
"description": "Analyze win/loss streaks with dates and current streak",
"inputSchema": {
"type": "object",
"properties": {
"report_dir": { "type": "string" }
}
}
})
}
fn tool_analyze_concurrent_peak() -> Value {
json!({
"name": "analyze_concurrent_peak",
"description": "Find peak number of concurrent open positions",
"inputSchema": {
"type": "object",
"properties": {