fix(portfolio): runner data_dir dedicata, no resize posizioni aperte, poll da config, +test cap/cluster_rp
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
-3
@@ -17,7 +17,7 @@ _STRAT_MODULE = {
|
||||
"MR07": "MR07_return_reversal", "SH01": "SH01_shape_ml",
|
||||
# DIP01/TR01/ROT02 sono honest a sé: vedi nota nel design (worker dedicati in fase 2)
|
||||
}
|
||||
DATA_DIR = Path("data/paper_trades")
|
||||
DATA_DIR = Path("data/portfolio_paper")
|
||||
|
||||
|
||||
def build_worker_for(spec: SleeveSpec, alloc_capital: float, leverage: float,
|
||||
@@ -50,11 +50,15 @@ def _worker_equity(w) -> float:
|
||||
|
||||
def rebalance_allocations(ledger: PortfolioLedger, workers: dict, weights: dict[str, float]):
|
||||
"""Ribilancio: total_capital = Σ equity sleeve; riallinea il capitale-base di ogni worker
|
||||
a peso×total. Le posizioni APERTE restano sul loro notional (approssimazione dichiarata)."""
|
||||
a peso×total. I worker con posizione APERTA NON vengono ritoccati (la posizione mantiene
|
||||
il suo notional, come da approssimazione dichiarata): il nuovo capitale-base si applica
|
||||
alla prossima posizione, quando il worker è flat."""
|
||||
ledger.total_capital = sum(_worker_equity(w) for w in workers.values())
|
||||
alloc = ledger.allocate(weights)
|
||||
for sid, w in workers.items():
|
||||
inner = getattr(w, "worker", w)
|
||||
if getattr(inner, "in_position", False):
|
||||
continue
|
||||
inner.capital = alloc.get(sid, inner.capital)
|
||||
ledger.save()
|
||||
|
||||
@@ -74,6 +78,10 @@ def run(config_path: str = "portfolios.yml"):
|
||||
|
||||
p: Portfolio = load_active_portfolio(config_path)
|
||||
|
||||
import yaml as _yaml
|
||||
_ov = (_yaml.safe_load(__import__("pathlib").Path(config_path).read_text()) or {}).get("overrides", {})
|
||||
poll = int(_ov.get("poll_seconds", 60))
|
||||
|
||||
def _supported(s):
|
||||
return s.kind == "pairs" or s.name in _STRAT_MODULE
|
||||
live_specs = [s for s in p.sleeves if _supported(s)]
|
||||
@@ -94,7 +102,6 @@ def run(config_path: str = "portfolios.yml"):
|
||||
|
||||
inst_map = dict(INSTRUMENT_MAP)
|
||||
last_day = ""
|
||||
poll = 60
|
||||
while True:
|
||||
try:
|
||||
keys = set()
|
||||
|
||||
Reference in New Issue
Block a user