feat: add autonomous paper-trading and calibration pipeline

This commit is contained in:
ImBenji
2026-08-03 14:03:27 +01:00
parent 5a9a2e4c6d
commit c4028cc394
46 changed files with 2246 additions and 115 deletions
+46
View File
@@ -1,5 +1,6 @@
const Database = require("better-sqlite3");
const sqliteVec = require("sqlite-vec");
const { initAutonomySchema } = require("../src/autonomy/schema");
let archiveDb = null;
let intelligenceDb = null;
@@ -17,6 +18,7 @@ function getIntelligenceDb(dbPath) {
if (!intelligenceDb) {
intelligenceDb = new Database(dbPath);
intelligenceDb.pragma("journal_mode = WAL");
initAutonomySchema(intelligenceDb);
}
return intelligenceDb;
}
@@ -109,6 +111,7 @@ function runMigrations(db) {
function runColumnMigrations(db) {
try { db.exec("ALTER TABLE event_predictions ADD COLUMN event_date TEXT"); } catch (_) {}
try { db.exec("ALTER TABLE event_knowledge ADD COLUMN event_date TEXT"); } catch (_) {}
try { db.exec("ALTER TABLE event_predictions ADD COLUMN probability REAL"); } catch (_) {}
db.exec(`
CREATE TABLE IF NOT EXISTS worker_events (
@@ -137,6 +140,49 @@ function runColumnMigrations(db) {
);
`);
// tracks last-processed state per event so augor doesnt redundantly re-run on every new article
db.exec(`
CREATE TABLE IF NOT EXISTS event_processing_state (
event_id INTEGER PRIMARY KEY,
last_processed_at DATETIME,
articles_at_last_run INTEGER NOT NULL DEFAULT 0
);
`);
// cached daily price snapshots so the augor prompt can include real market context
db.exec(`
CREATE TABLE IF NOT EXISTS price_snapshots (
ticker TEXT NOT NULL,
as_of TEXT NOT NULL,
price REAL,
price_30d_ago REAL,
price_90d_ago REAL,
vol_30d REAL,
fetched_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (ticker, as_of)
);
`);
// outcomes — actual realized returns for each prediction, populated by the outcome worker
db.exec(`
CREATE TABLE IF NOT EXISTS prediction_outcomes (
prediction_id INTEGER PRIMARY KEY,
company_id INTEGER,
ticker TEXT,
event_date TEXT,
price_0 REAL,
price_5d REAL,
price_10d REAL,
r5 REAL,
r10 REAL,
correct_5d INTEGER,
correct_10d INTEGER,
evaluated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_prediction_outcomes_company ON prediction_outcomes (company_id);
`);
// prune rows older than 1 hour so the table doesnt grow unbounded
db.exec(`DELETE FROM worker_events WHERE completed_at < datetime('now', '-1 hour')`);
}