mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-04 18:57:44 +00:00
fix: resolve dead code, shell injection risk, mutable defaults, and other bugs
- strategy_orchestrator.py: remove unreachable dead 'if not factor_values' after early return - strategy_orchestrator.py: eliminate duplicate OHLVC load in evaluate_strategy - env.py: escape single-quotes in Docker entry to prevent shell injection (CWE-78) - env.py: replace mutable default args with None pattern in DockerEnv subclasses - factor_runner.py: move pandarallel.initialize() from import-time to lazy init
This commit is contained in:
@@ -749,18 +749,15 @@ signal = signal.rolling(window=3, min_periods=1).mean().round().astype(int)
|
||||
}
|
||||
|
||||
# Align factor values with common index
|
||||
if not factor_values:
|
||||
df_factors = pd.DataFrame()
|
||||
else:
|
||||
# Find common index across all series
|
||||
common_idx = None
|
||||
for name, s in factor_values.items():
|
||||
if common_idx is None:
|
||||
common_idx = s.index
|
||||
else:
|
||||
common_idx = common_idx.intersection(s.index)
|
||||
# Find common index across all series
|
||||
common_idx = None
|
||||
for name, s in factor_values.items():
|
||||
if common_idx is None:
|
||||
common_idx = s.index
|
||||
else:
|
||||
common_idx = common_idx.intersection(s.index)
|
||||
|
||||
if common_idx is not None and len(common_idx) > 100:
|
||||
if common_idx is not None and len(common_idx) > 100:
|
||||
df_factors = pd.DataFrame({
|
||||
name: s.reindex(common_idx) for name, s in factor_values.items()
|
||||
}).dropna()
|
||||
@@ -826,16 +823,15 @@ signal = signal.rolling(window=3, min_periods=1).mean().round().astype(int)
|
||||
"factors_used": factor_names,
|
||||
}
|
||||
|
||||
if "signal" not in local_vars:
|
||||
signal = local_vars.get("signal")
|
||||
if signal is None or (isinstance(signal, pd.Series) and signal.empty):
|
||||
return {
|
||||
"strategy_name": strategy_name,
|
||||
"status": "rejected",
|
||||
"reason": "Strategy did not produce 'signal' variable",
|
||||
"reason": "Strategy did not produce valid 'signal' variable",
|
||||
"factors_used": factor_names,
|
||||
}
|
||||
|
||||
signal = local_vars["signal"]
|
||||
|
||||
logger.info(
|
||||
f"[DEBUG] {strategy_name}: signal stats: "
|
||||
f"len={len(signal)}, "
|
||||
@@ -852,7 +848,7 @@ signal = signal.rolling(window=3, min_periods=1).mean().round().astype(int)
|
||||
backtest_signal_ftmo,
|
||||
)
|
||||
|
||||
close = self.load_ohlcv_close()
|
||||
# Reuse the already-loaded close from above; create a synthetic proxy if unavailable
|
||||
if close is None:
|
||||
logger.warning("OHLCV data unavailable, using factor-mean proxy")
|
||||
proxy = df_factors.mean(axis=1).astype(float)
|
||||
|
||||
Reference in New Issue
Block a user