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

Remove Aggressiva Crypto from whitelist
This commit is contained in:
fredmaloggia
2025-11-18 10:37:36 +01:00
committed by GitHub

View File

@@ -20,6 +20,13 @@ import pandas as pd
import numpy as np
import os
from shared_utils import (
detect_column,
load_config,
read_connection_txt,
require_section,
)
# =============================================================================
# PATH & OUTPUT
# =============================================================================
@@ -38,54 +45,22 @@ SP_NAME_DEFAULT = "opt_RendimentoGiornaliero1_ALL"
SP_N_DEFAULT = 1305
PTF_CURR_DEFAULT = "EUR"
# prova a leggere il file di configurazione condiviso; se manca si usano i default
try:
CONFIG = load_config()
DB_CONFIG = require_section(CONFIG, "db")
except Exception as exc: # pragma: no cover - best effort
print(f"[WARN] Config non disponibile ({exc}); uso i default interni.")
DB_CONFIG = {}
else:
SP_NAME_DEFAULT = str(DB_CONFIG.get("stored_proc", SP_NAME_DEFAULT))
SP_N_DEFAULT = int(DB_CONFIG.get("n_bars", SP_N_DEFAULT))
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
VALID_STRATEGIES = ["Equal_Weight", "Risk_Parity"]
# =============================================================================
# CONNESSIONE DB
# =============================================================================
def read_connection_txt(path: Path) -> str:
import pyodbc
params = {}
for line in path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or "=" not in line or line.startswith("#"):
continue
k, v = line.split("=", 1)
params[k.strip().lower()] = v.strip()
username = params.get("username")
password = params.get("password")
host = params.get("host")
port = params.get("port", "1433")
database = params.get("database")
if not all([username, password, host, database]):
raise ValueError("connection.txt incompleto: servono username/password/host/database.")
installed = [d for d in pyodbc.drivers()]
driver_q = (
"ODBC+Driver+18+for+SQL+Server"
if "ODBC Driver 18 for SQL Server" in installed
else "ODBC+Driver+17+for+SQL+Server"
)
return f"mssql+pyodbc://{username}:{password}@{host}:{port}/{database}?driver={driver_q}"
# =============================================================================
# UTILS
# =============================================================================
def _pick(df: pd.DataFrame, candidates):
low = {c.lower(): c for c in df.columns}
for c in candidates:
if c.lower() in low:
return low[c.lower()]
for col in df.columns:
lc = col.lower()
if any(tok.lower() in lc for tok in candidates):
return col
return None
# =============================================================================
# FETCH RENDIMENTI DAL DB
# =============================================================================
@@ -113,9 +88,9 @@ def fetch_returns_from_db(isins, start_date, end_date) -> pd.DataFrame:
if df.empty:
continue
col_date = _pick(df, ["Date", "Data", "Datetime", "Timestamp", "Time"])
col_ret = _pick(df, ["Ret", "Return", "Rendimento", "Rend", "Ret_%", "RET"])
col_px = _pick(df, ["Close", "AdjClose", "Price", "Px", "Last", "Prezzo", "Chiusura"])
col_date = detect_column(df, ["Date", "Data", "Datetime", "Timestamp", "Time"])
col_ret = detect_column(df, ["Ret", "Return", "Rendimento", "Rend", "Ret_%", "RET"])
col_px = detect_column(df, ["Close", "AdjClose", "Price", "Px", "Last", "Prezzo", "Chiusura"])
if not col_date:
continue