marketcompiler-verifiable-d.../marketcompiler_verifiable_d.../backtest.py

26 lines
794 B
Python

"""Simple deterministic backtester for MVP"""
from __future__ import annotations
from typing import Dict, List, Any
from .core import LocalProblem
class Backtester:
@staticmethod
def run(lp: LocalProblem, prices: Dict[str, float] | None = None) -> Dict[str, Any]:
if prices is None:
prices = {a: 100.0 for a in lp.assets}
# Very small deterministic scoring: equal-weight returns based on price changes (simulated)
total = 0.0
for a in lp.assets:
p = prices.get(a, 100.0)
total += max(0.0, p - 100.0)
# Simple metrics
result = {
"assets": lp.assets,
"score": total,
"iterations": 1,
"timestamp": "2026-01-01T00:00:00Z",
}
return result