mirror of
https://github.com/triqbit/mt5-ai-xauusd-trader.git
synced 2026-11-02 06:56:15 +00:00
* 🧬 Jules02: Synthetic test scenarios — Operational lifecycle and execution quality This change enhances the synthetic data generation capabilities to support broader and safer testing of operational recovery and execution quality. Key improvements: - Enhanced ScenarioGenerator with deterministic spread_pips and movement-correlated volume. - Added LifecycleScenarioBuilder for testing multi-stage system transitions (Failure -> Recovery). - Added ExecutionQualityScenarioBuilder for validating performance guards and slippage logic. - Robust test coverage for all new generators. Co-authored-by: xnessom <255288032+xnessom@users.noreply.github.com> * feat: 🧬 Jules02: Synthetic test scenarios — Operational lifecycle and execution quality This change enhances the synthetic data generation capabilities to support broader and safer testing of operational recovery and execution quality. Key improvements: - Enhanced ScenarioGenerator with deterministic spread_pips and movement-correlated volume. - Added LifecycleScenarioBuilder for testing multi-stage system transitions (Failure -> Recovery). - Added ExecutionQualityScenarioBuilder for validating performance guards and slippage logic. - Updated documentation in docs/testing/SYNTHETIC_DATA.md. - Upgraded python-socketio to 5.14.0 to resolve security vulnerability GHSA-g8c6-8fjj-2r4m. - Full test coverage for new features (tests/test_lifecycle_scenarios.py). Co-authored-by: xnessom <255288032+xnessom@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: xnessom <255288032+xnessom@users.noreply.github.com>
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
import os
|
|
import sys
|
|
from datetime import datetime, timedelta
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
# Ensure src is in path
|
|
sys.path.append(os.getcwd())
|
|
|
|
from src.core.audit_log import AuditLogger
|
|
from src.core.feature_engineering import FeatureEngineer
|
|
from src.trading.backtester import BacktestEngine
|
|
|
|
|
|
def create_synthetic_data(n_bars=3000):
|
|
start_time = datetime.now()
|
|
times = [start_time + timedelta(minutes=i*5) for i in range(n_bars)]
|
|
data = {
|
|
"time": times,
|
|
"open": np.random.uniform(2300, 2400, n_bars),
|
|
"high": np.random.uniform(2300, 2400, n_bars),
|
|
"low": np.random.uniform(2300, 2400, n_bars),
|
|
"close": np.random.uniform(2300, 2400, n_bars),
|
|
"tick_volume": np.random.randint(100, 1000, n_bars),
|
|
}
|
|
df = pd.DataFrame(data)
|
|
# Ensure high is highest, low is lowest
|
|
df["high"] = df[["open", "high", "low", "close"]].max(axis=1)
|
|
df["low"] = df[["open", "high", "low", "close"]].min(axis=1)
|
|
df.set_index("time", inplace=True)
|
|
return df
|
|
|
|
class MockModel:
|
|
def predict(self, obs):
|
|
from src.core.schemas import TradeSignal
|
|
# Always return a HOLD signal to keep it fast
|
|
return TradeSignal(symbol="XAUUSD", direction=0, confidence=0.0)
|
|
|
|
def main():
|
|
print("Initializing AuditLogger...")
|
|
audit_db = "audit.db"
|
|
if os.path.exists(audit_db):
|
|
os.remove(audit_db)
|
|
|
|
# Initialize singleton
|
|
AuditLogger(db_url=f"sqlite:///{audit_db}")
|
|
|
|
print("Creating synthetic data...")
|
|
data = create_synthetic_data()
|
|
|
|
print("Running backtest...")
|
|
fe = FeatureEngineer(base_timeframe="M5", timeframes=["M15", "H1"])
|
|
engine = BacktestEngine(symbol="XAUUSD", feature_engineer=fe)
|
|
model = MockModel()
|
|
|
|
# Run with small windows for speed
|
|
engine.run_walk_forward(data, model, train_window=500, test_window=100, step_size=100)
|
|
|
|
print("Backtest finished.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|