algograph-algebraic-portfol.../tests/test_graph.py

25 lines
822 B
Python

import numpy as np
from algograph_algebraic_portfolio_compiler_f.graph import PortfolioBlock, SignalMorphism, PlanDelta, DualVariables
def test_portfolio_block_creation():
block = PortfolioBlock(id="pb1", assets=["AAPL", "GOOGL"], objective={"type": "quad", "Q": [[1, 0], [0, 1]], "c": [0, 0]})
assert block.id == "pb1"
assert block.assets == ["AAPL", "GOOGL"]
assert block.signals == {}
def test_signal_morphism_basic():
s = SignalMorphism(name="price_channel")
s.push("AAPL", 150.0)
assert s.payload["AAPL"] == 150.0
def test_plan_delta_and_dual_variables():
pv = PlanDelta(delta={"allocate": [0.1, 0.9]}, timestamp=1.0, author="tester")
dv = DualVariables()
dv.update("lambda", 0.5)
assert pv.delta["allocate"] == [0.1, 0.9]
assert dv.multipliers["lambda"] == 0.5