ci: fix lint baseline and stabilize failing main tests
This commit is contained in:
@@ -90,9 +90,7 @@ class ABTester:
|
||||
sharpe_ratio = None
|
||||
if len(pnls) > 1:
|
||||
mean_return = avg_pnl
|
||||
std_return = (
|
||||
sum((p - mean_return) ** 2 for p in pnls) / (len(pnls) - 1)
|
||||
) ** 0.5
|
||||
std_return = (sum((p - mean_return) ** 2 for p in pnls) / (len(pnls) - 1)) ** 0.5
|
||||
if std_return > 0:
|
||||
sharpe_ratio = mean_return / std_return
|
||||
|
||||
@@ -198,8 +196,7 @@ class ABTester:
|
||||
|
||||
if meets_criteria:
|
||||
logger.info(
|
||||
"Strategy '%s' meets deployment criteria: "
|
||||
"win_rate=%.2f%%, trades=%d, avg_pnl=%.2f",
|
||||
"Strategy '%s' meets deployment criteria: win_rate=%.2f%%, trades=%d, avg_pnl=%.2f",
|
||||
result.winner,
|
||||
winning_perf.win_rate,
|
||||
winning_perf.total_trades,
|
||||
|
||||
@@ -60,9 +60,7 @@ class DailyReviewer:
|
||||
if isinstance(scenario_match, dict) and scenario_match:
|
||||
matched += 1
|
||||
scenario_match_rate = (
|
||||
round((matched / total_decisions) * 100, 2)
|
||||
if total_decisions
|
||||
else 0.0
|
||||
round((matched / total_decisions) * 100, 2) if total_decisions else 0.0
|
||||
)
|
||||
|
||||
trade_stats = self._conn.execute(
|
||||
|
||||
@@ -80,26 +80,26 @@ class EvolutionOptimizer:
|
||||
# Convert to dict format for analysis
|
||||
failures = []
|
||||
for decision in losing_decisions:
|
||||
failures.append({
|
||||
"decision_id": decision.decision_id,
|
||||
"timestamp": decision.timestamp,
|
||||
"stock_code": decision.stock_code,
|
||||
"market": decision.market,
|
||||
"exchange_code": decision.exchange_code,
|
||||
"action": decision.action,
|
||||
"confidence": decision.confidence,
|
||||
"rationale": decision.rationale,
|
||||
"outcome_pnl": decision.outcome_pnl,
|
||||
"outcome_accuracy": decision.outcome_accuracy,
|
||||
"context_snapshot": decision.context_snapshot,
|
||||
"input_data": decision.input_data,
|
||||
})
|
||||
failures.append(
|
||||
{
|
||||
"decision_id": decision.decision_id,
|
||||
"timestamp": decision.timestamp,
|
||||
"stock_code": decision.stock_code,
|
||||
"market": decision.market,
|
||||
"exchange_code": decision.exchange_code,
|
||||
"action": decision.action,
|
||||
"confidence": decision.confidence,
|
||||
"rationale": decision.rationale,
|
||||
"outcome_pnl": decision.outcome_pnl,
|
||||
"outcome_accuracy": decision.outcome_accuracy,
|
||||
"context_snapshot": decision.context_snapshot,
|
||||
"input_data": decision.input_data,
|
||||
}
|
||||
)
|
||||
|
||||
return failures
|
||||
|
||||
def identify_failure_patterns(
|
||||
self, failures: list[dict[str, Any]]
|
||||
) -> dict[str, Any]:
|
||||
def identify_failure_patterns(self, failures: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
"""Identify patterns in losing decisions.
|
||||
|
||||
Analyzes:
|
||||
@@ -143,12 +143,8 @@ class EvolutionOptimizer:
|
||||
total_confidence += failure.get("confidence", 0)
|
||||
total_loss += failure.get("outcome_pnl", 0.0)
|
||||
|
||||
patterns["avg_confidence"] = (
|
||||
round(total_confidence / len(failures), 2) if failures else 0.0
|
||||
)
|
||||
patterns["avg_loss"] = (
|
||||
round(total_loss / len(failures), 2) if failures else 0.0
|
||||
)
|
||||
patterns["avg_confidence"] = round(total_confidence / len(failures), 2) if failures else 0.0
|
||||
patterns["avg_loss"] = round(total_loss / len(failures), 2) if failures else 0.0
|
||||
|
||||
# Convert Counters to regular dicts for JSON serialization
|
||||
patterns["markets"] = dict(patterns["markets"])
|
||||
@@ -197,7 +193,8 @@ class EvolutionOptimizer:
|
||||
|
||||
prompt = (
|
||||
"You are a quantitative trading strategy developer.\n"
|
||||
"Analyze these failed trades and their patterns, then generate an improved strategy.\n\n"
|
||||
"Analyze these failed trades and their patterns, "
|
||||
"then generate an improved strategy.\n\n"
|
||||
f"Failure Patterns:\n{json.dumps(patterns, indent=2)}\n\n"
|
||||
f"Sample Failed Trades (first 5):\n"
|
||||
f"{json.dumps(failures[:5], indent=2, default=str)}\n\n"
|
||||
@@ -214,7 +211,8 @@ class EvolutionOptimizer:
|
||||
|
||||
try:
|
||||
response = await self._client.aio.models.generate_content(
|
||||
model=self._model_name, contents=prompt,
|
||||
model=self._model_name,
|
||||
contents=prompt,
|
||||
)
|
||||
body = response.text.strip()
|
||||
except Exception as exc:
|
||||
@@ -280,9 +278,7 @@ class EvolutionOptimizer:
|
||||
logger.info("Strategy validation PASSED")
|
||||
return True
|
||||
else:
|
||||
logger.warning(
|
||||
"Strategy validation FAILED:\n%s", result.stdout + result.stderr
|
||||
)
|
||||
logger.warning("Strategy validation FAILED:\n%s", result.stdout + result.stderr)
|
||||
# Clean up failing strategy
|
||||
strategy_path.unlink(missing_ok=True)
|
||||
return False
|
||||
|
||||
@@ -187,9 +187,7 @@ class PerformanceTracker:
|
||||
|
||||
return metrics
|
||||
|
||||
def calculate_improvement_trend(
|
||||
self, metrics_history: list[StrategyMetrics]
|
||||
) -> dict[str, Any]:
|
||||
def calculate_improvement_trend(self, metrics_history: list[StrategyMetrics]) -> dict[str, Any]:
|
||||
"""Calculate improvement trend from historical metrics.
|
||||
|
||||
Args:
|
||||
@@ -229,9 +227,7 @@ class PerformanceTracker:
|
||||
"period_count": len(metrics_history),
|
||||
}
|
||||
|
||||
def generate_dashboard(
|
||||
self, strategy_name: str | None = None
|
||||
) -> PerformanceDashboard:
|
||||
def generate_dashboard(self, strategy_name: str | None = None) -> PerformanceDashboard:
|
||||
"""Generate a comprehensive performance dashboard.
|
||||
|
||||
Args:
|
||||
@@ -260,9 +256,7 @@ class PerformanceTracker:
|
||||
improvement_trend=improvement_trend,
|
||||
)
|
||||
|
||||
def export_dashboard_json(
|
||||
self, dashboard: PerformanceDashboard
|
||||
) -> str:
|
||||
def export_dashboard_json(self, dashboard: PerformanceDashboard) -> str:
|
||||
"""Export dashboard as JSON string.
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user