continuazione refactoring
This commit is contained in:
@@ -31,10 +31,18 @@ from shared_utils import (
|
||||
# PATH & OUTPUT
|
||||
# =============================================================================
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
OUTPUT_DIR = BASE_DIR / "output"
|
||||
PLOT_DIR = BASE_DIR / "plot"
|
||||
AUDIT_LOG_CSV = OUTPUT_DIR / "trades_audit_log.csv"
|
||||
CONNECTION_TXT = BASE_DIR / "connection.txt"
|
||||
CONFIG = None
|
||||
try:
|
||||
CONFIG = load_config()
|
||||
PATHS_CONFIG = require_section(CONFIG, "paths")
|
||||
except Exception as exc: # pragma: no cover - best effort
|
||||
print(f"[WARN] Config non disponibile ({exc}); uso i percorsi di default.")
|
||||
PATHS_CONFIG = {}
|
||||
|
||||
OUTPUT_DIR = BASE_DIR / PATHS_CONFIG.get("output_dir", "output")
|
||||
PLOT_DIR = BASE_DIR / PATHS_CONFIG.get("plot_dir", "plot")
|
||||
AUDIT_LOG_CSV = BASE_DIR / PATHS_CONFIG.get("audit_log_csv", OUTPUT_DIR / "trades_audit_log.csv")
|
||||
CONNECTION_TXT = BASE_DIR / PATHS_CONFIG.get("connection_txt", "connection.txt")
|
||||
|
||||
OUT_DAILY_CSV = OUTPUT_DIR / "daily_returns_by_strategy.csv"
|
||||
OUT_EQUITY_CSV = OUTPUT_DIR / "equity_by_strategy.csv"
|
||||
@@ -44,16 +52,13 @@ PLOT_DD = PLOT_DIR / "drawdown_by_strategy.png"
|
||||
|
||||
# Stored procedure
|
||||
SP_NAME_DEFAULT = "opt_RendimentoGiornaliero1_ALL"
|
||||
SP_N_DEFAULT = 1305
|
||||
SP_N_DEFAULT = 1260
|
||||
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")
|
||||
DB_CONFIG = require_section(CONFIG, "db") if CONFIG else {}
|
||||
except Exception as exc: # pragma: no cover - best effort
|
||||
print(f"[WARN] Config non disponibile ({exc}); uso i default interni.")
|
||||
print(f"[WARN] Config DB non disponibile ({exc}); uso i default interni.")
|
||||
DB_CONFIG = {}
|
||||
else:
|
||||
SP_NAME_DEFAULT = str(DB_CONFIG.get("stored_proc", SP_NAME_DEFAULT))
|
||||
@@ -61,24 +66,19 @@ else:
|
||||
PTF_CURR_DEFAULT = str(DB_CONFIG.get("ptf_curr", PTF_CURR_DEFAULT))
|
||||
|
||||
# Strategie valide (tutto il resto viene ignorato)
|
||||
# "Aggressiva_Crypto" è stata rimossa perché non deve più essere processata
|
||||
# "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"]
|
||||
EQUITY_CFG = CONFIG.get("equity_log", {}) if CONFIG else {}
|
||||
raw_whitelist = EQUITY_CFG.get("strategy_whitelist") if isinstance(EQUITY_CFG, dict) else None
|
||||
if raw_whitelist:
|
||||
whitelist = [str(x).strip() for x in raw_whitelist if str(x).strip()]
|
||||
if whitelist:
|
||||
VALID_STRATEGIES = whitelist
|
||||
|
||||
# =============================================================================
|
||||
|
||||
# FETCH RENDIMENTI DAL DB
|
||||
# =============================================================================
|
||||
def fetch_returns_from_db(isins, start_date, end_date) -> pd.DataFrame:
|
||||
|
||||
Reference in New Issue
Block a user