Merge pull request #6 from fredmaloggia/codex/verifica-e-modifica-il-file-equity-from-log-9eqgrf

Allow configuring equity log strategy whitelist
This commit is contained in:
fredmaloggia
2025-11-18 14:30:06 +01:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

View File

@@ -31,5 +31,11 @@
"base_capital_per_strategy": 100.0,
"min_trade_notional": 0.01,
"risk_parity_lookback": 60
},
"equity_log": {
"strategy_whitelist": [
"Equal_Weight",
"Risk_Parity"
]
}
}

View File

@@ -46,6 +46,7 @@ SP_N_DEFAULT = 1305
PTF_CURR_DEFAULT = "EUR"
# prova a leggere il file di configurazione condiviso; se manca si usano i default
CONFIG = None
try:
CONFIG = load_config()
DB_CONFIG = require_section(CONFIG, "db")
@@ -59,6 +60,20 @@ else:
# Strategie valide (tutto il resto viene ignorato)
# "Aggressiva_Crypto" è stata rimossa perché non deve più essere processata
DEFAULT_STRATEGIES = ["Equal_Weight", "Risk_Parity"]
VALID_STRATEGIES = DEFAULT_STRATEGIES
try: # opzionale: sezione dedicata nel config per personalizzare la whitelist
EQUITY_CFG = CONFIG.get("equity_log", {}) if CONFIG else {}
except NameError: # pragma: no cover - CONFIG non definito se load_config fallisce
EQUITY_CFG = {}
if EQUITY_CFG:
raw_whitelist = EQUITY_CFG.get("strategy_whitelist")
if raw_whitelist:
whitelist = [str(x).strip() for x in raw_whitelist if str(x).strip()]
if whitelist:
VALID_STRATEGIES = whitelist
VALID_STRATEGIES = ["Equal_Weight", "Risk_Parity"]
# =============================================================================
@@ -245,7 +260,13 @@ def main():
# === filtro whitelist: solo strategie volute ===
audit["Strategy"] = audit["Strategy"].astype(str)
before = len(audit)
audit = audit[audit["Strategy"].isin(VALID_STRATEGIES)]
removed = before - len(audit)
if removed > 0:
print(
f"[INFO] Filtrate {removed} righe con strategie non incluse in {VALID_STRATEGIES}."
)
if audit.empty:
raise SystemExit(f"Nessuna riga con strategie in {VALID_STRATEGIES} nell'audit log.")