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:
@@ -2,12 +2,24 @@ from src.portfolio.runner import rebalance_allocations
|
||||
from src.portfolio.ledger import PortfolioLedger
|
||||
|
||||
|
||||
def test_rebalance_resizes_to_total(tmp_path):
|
||||
L = PortfolioLedger("PX", total_capital=1000.0, data_dir=tmp_path)
|
||||
class FakeWorker:
|
||||
def __init__(self, cap, in_position=False):
|
||||
self.capital = cap
|
||||
self.in_position = in_position
|
||||
|
||||
class FakeWorker:
|
||||
def __init__(self, cap): self.capital = cap
|
||||
workers = {"a": FakeWorker(700.0), "b": FakeWorker(500.0)}
|
||||
|
||||
def test_rebalance_resizes_flat_workers(tmp_path):
|
||||
L = PortfolioLedger("PX", total_capital=1000.0, data_dir=tmp_path)
|
||||
workers = {"a": FakeWorker(700.0), "b": FakeWorker(500.0)} # equity 1200, both flat
|
||||
rebalance_allocations(L, workers, {"a": 0.5, "b": 0.5})
|
||||
assert L.total_capital == 1200.0
|
||||
assert workers["a"].capital == 600.0 and workers["b"].capital == 600.0
|
||||
|
||||
|
||||
def test_rebalance_skips_in_position_worker(tmp_path):
|
||||
L = PortfolioLedger("PX", total_capital=1000.0, data_dir=tmp_path)
|
||||
workers = {"a": FakeWorker(700.0, in_position=True), "b": FakeWorker(500.0)}
|
||||
rebalance_allocations(L, workers, {"a": 0.5, "b": 0.5})
|
||||
assert L.total_capital == 1200.0
|
||||
assert workers["a"].capital == 700.0 # invariato: posizione aperta
|
||||
assert workers["b"].capital == 600.0 # flat: riallineato
|
||||
|
||||
Reference in New Issue
Block a user