Add local backtest snapshot runner
This commit is contained in:
@@ -247,6 +247,50 @@ cd frontend
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Local Backtest Snapshots
|
||||
|
||||
For research loops, run the production backtest locally from a SQLite snapshot
|
||||
instead of deploying and clicking the Admin job. The snapshot contains only the
|
||||
tables needed by `run_backtest`: tickers, OHLCV bars, SPY benchmark closes, and
|
||||
activation/recommendation settings. Secrets and cached reports are not copied.
|
||||
|
||||
1. Open an SSH tunnel to the production Postgres instance:
|
||||
|
||||
```bash
|
||||
ssh -N -L 15432:127.0.0.1:5432 deploy@your-server
|
||||
```
|
||||
|
||||
2. In another terminal, create or refresh the snapshot:
|
||||
|
||||
```bash
|
||||
# macOS/Linux
|
||||
python scripts/create_backtest_snapshot.py \
|
||||
--database-url "postgresql+asyncpg://stock_backend:PASSWORD@127.0.0.1:15432/stock_data_backend" \
|
||||
--output backtest_snapshots/prod.sqlite \
|
||||
--force
|
||||
|
||||
# Windows PowerShell
|
||||
.venv\Scripts\python.exe scripts\create_backtest_snapshot.py `
|
||||
--database-url "postgresql+asyncpg://stock_backend:PASSWORD@127.0.0.1:15432/stock_data_backend" `
|
||||
--output backtest_snapshots\prod.sqlite `
|
||||
--force
|
||||
```
|
||||
|
||||
3. Run the backtest fully offline from the snapshot:
|
||||
|
||||
```bash
|
||||
# macOS/Linux
|
||||
python scripts/run_backtest_snapshot.py backtest_snapshots/prod.sqlite --workers 8
|
||||
|
||||
# Windows PowerShell
|
||||
.venv\Scripts\python.exe scripts\run_backtest_snapshot.py backtest_snapshots\prod.sqlite --workers 12 --allow-spawn
|
||||
```
|
||||
|
||||
The runner writes `reports/backtest-<timestamp>.json` and prints the headline
|
||||
metrics. Keep the SSH tunnel open only while creating the snapshot; the backtest
|
||||
run itself is local/offline. `backtest_snapshots/` and generated backtest reports
|
||||
are git-ignored.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Configure in `.env` (copy from `.env.example`):
|
||||
|
||||
Reference in New Issue
Block a user