sistemato salvataggio plot
This commit is contained in:
@@ -18,7 +18,7 @@ from __future__ import annotations
|
||||
from pathlib import Path
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from shared_utils import (
|
||||
detect_column,
|
||||
@@ -50,6 +50,24 @@ OUT_DEBUG_CSV = OUTPUT_DIR / "debug_daily_by_strategy.csv"
|
||||
PLOT_EQUITY = PLOT_DIR / "equity_by_strategy.png"
|
||||
PLOT_DD = PLOT_DIR / "drawdown_by_strategy.png"
|
||||
|
||||
DROPBOX_EXPORT_DIR = Path(r"C:\Users\Admin\Dropbox\Condivisa Lavoro\Segnali di trading su ETF")
|
||||
|
||||
def copy_to_dropbox(src: Path, dst_dir: Path = DROPBOX_EXPORT_DIR) -> bool:
|
||||
if not src or not dst_dir:
|
||||
return False
|
||||
if not src.exists():
|
||||
print(f"[WARN] file non trovato per copia Dropbox: {src}")
|
||||
return False
|
||||
try:
|
||||
dst_dir.mkdir(parents=True, exist_ok=True)
|
||||
dst = dst_dir / src.name
|
||||
shutil.copy2(src, dst)
|
||||
print(f"[DROPBOX] Copiato {src.name} in {dst_dir}")
|
||||
return True
|
||||
except Exception as exc:
|
||||
print(f"[WARN] impossibile copiare {src} su {dst_dir}: {exc}")
|
||||
return False
|
||||
|
||||
# Stored procedure
|
||||
SP_NAME_DEFAULT = "opt_RendimentoGiornaliero1_ALL"
|
||||
SP_N_DEFAULT = 1260
|
||||
@@ -65,8 +83,7 @@ else:
|
||||
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
|
||||
|
||||
DEFAULT_STRATEGIES = ["Equal_Weight", "Risk_Parity"]
|
||||
VALID_STRATEGIES = DEFAULT_STRATEGIES
|
||||
|
||||
@@ -300,6 +317,7 @@ def main():
|
||||
plt.tight_layout()
|
||||
plt.savefig(str(PLOT_EQUITY), dpi=150)
|
||||
plt.close()
|
||||
copy_to_dropbox(PLOT_EQUITY)
|
||||
|
||||
# Drawdown
|
||||
dd = equity / equity.cummax() - 1.0
|
||||
@@ -312,6 +330,7 @@ def main():
|
||||
plt.tight_layout()
|
||||
plt.savefig(str(PLOT_DD), dpi=150)
|
||||
plt.close()
|
||||
copy_to_dropbox(PLOT_DD)
|
||||
|
||||
print("Salvati:")
|
||||
print(" -", OUT_DAILY_CSV)
|
||||
@@ -319,6 +338,8 @@ def main():
|
||||
print(" -", OUT_DEBUG_CSV)
|
||||
print(" -", PLOT_EQUITY)
|
||||
print(" -", PLOT_DD)
|
||||
print(" -", DROPBOX_EXPORT_DIR / PLOT_EQUITY.name)
|
||||
print(" -", DROPBOX_EXPORT_DIR / PLOT_DD.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user