28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
from algebraic_portfolio_provenance_studio_ve.dsl import LocalAsset, Objective, RiskBudget, PlanDelta, SharedSignals, AuditLog
|
|
from algebraic_portfolio_provenance_studio_ve.simulator import DeterministicBacktest
|
|
|
|
|
|
def test_basic_dsl_construction_and_backtest():
|
|
# Build a tiny DSL example
|
|
a1 = LocalAsset(symbol="AAPL", asset_class="Equity", notional=50000.0)
|
|
a2 = LocalAsset(symbol="TBOND", asset_class="FixedIncome", notional=50000.0)
|
|
obj = Objective(target_return=0.08, target_vol=0.15)
|
|
rb = RiskBudget(max_drawdown=0.2, tail_risk=0.05, exposure_caps={"AAPL": 0.6, "TBOND": 0.5})
|
|
delta = PlanDelta(step=0, deltas={"AAPL": 0.5, "TBOND": 0.5})
|
|
|
|
# Run a tiny simulated backtest
|
|
backtest = DeterministicBacktest(
|
|
assets=[a1.symbol, a2.symbol],
|
|
initial_notional=a1.notional + a2.notional,
|
|
steps=3,
|
|
deltas=[{"AAPL": 0.6, "TBOND": 0.4}, {"AAPL": 0.4, "TBOND": 0.6}, {"AAPL": 0.5, "TBOND": 0.5}],
|
|
)
|
|
result = backtest.run()
|
|
assert isinstance(result, dict)
|
|
assert "history" in result
|
|
assert len(result["history"]) == 3
|
|
# sanity: history steps correspond to allocated weights that sum to 1.0
|
|
for st in result["history"]:
|
|
w = st["weights"]
|
|
assert abs(sum(w.values()) - 1.0) < 1e-6
|