mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 15:37:44 +00:00
fix: harmonize risk field names and case-insensitive DB column check
- vbt_backtest: unify risk_* → riskmgmt_* field names in _apply_risk_mask - results_db: case-insensitive column existence check - test_ftmo_oos: update test assertions to match renamed fields
This commit is contained in:
@@ -97,7 +97,7 @@ class ResultsDatabase:
|
||||
c = self.conn.cursor()
|
||||
c.execute("SELECT name FROM pragma_table_info(?)", (table,))
|
||||
existing = {row[0] for row in c.fetchall()}
|
||||
if column not in existing:
|
||||
if column.lower() not in {name.lower() for name in existing}:
|
||||
c.execute(f"ALTER TABLE {table} ADD COLUMN {column} {col_type}")
|
||||
|
||||
def add_factor(self, name: str, type: str = "unknown") -> int:
|
||||
|
||||
@@ -333,10 +333,10 @@ def _apply_risk_mask(
|
||||
masked.at[ts] = 0
|
||||
|
||||
return masked, {
|
||||
"risk_daily_breaches": daily_breaches,
|
||||
"risk_total_breached": total_breached,
|
||||
"risk_total_breach_ts": str(total_breach_ts) if total_breach_ts else None,
|
||||
"risk_compliant": not total_breached and daily_breaches == 0,
|
||||
"riskmgmt_daily_breaches": daily_breaches,
|
||||
"riskmgmt_total_breached": total_breached,
|
||||
"riskmgmt_total_breach_ts": str(total_breach_ts) if total_breach_ts else None,
|
||||
"riskmgmt_compliant": not total_breached and daily_breaches == 0,
|
||||
}
|
||||
|
||||
|
||||
@@ -533,13 +533,13 @@ def backtest_signal_risk(
|
||||
)
|
||||
|
||||
result.update(risk_metrics)
|
||||
result["risk_leverage"] = round(leverage, 2)
|
||||
result["risk_risk_pct"] = risk_pct
|
||||
result["risk_stop_pips"] = stop_pips
|
||||
result["riskmgmt_leverage"] = round(leverage, 2)
|
||||
result["riskmgmt_risk_pct"] = risk_pct
|
||||
result["riskmgmt_stop_pips"] = stop_pips
|
||||
|
||||
# Re-scale reported equity metrics to INITIAL_CAPITAL
|
||||
result["risk_end_equity"] = INITIAL_CAPITAL * (1 + result.get("total_return", 0))
|
||||
result["risk_monthly_profit"] = INITIAL_CAPITAL * result.get("monthly_return", 0)
|
||||
result["riskmgmt_end_equity"] = INITIAL_CAPITAL * (1 + result.get("total_return", 0))
|
||||
result["riskmgmt_monthly_profit"] = INITIAL_CAPITAL * result.get("monthly_return", 0)
|
||||
|
||||
# Walk-forward OOS split
|
||||
if oos_start is not None:
|
||||
|
||||
Reference in New Issue
Block a user