Database Schema

TimescaleDB Schema

All persistent state lives in TimescaleDB (PostgreSQL 17 + time-series extension). Three tables are hypertables partitioned by time. All timestamps are UTC TIMESTAMPTZ.

Entity Relationship Diagram

HedgeVision Database ERD

Table Schemas

market_datahypertable

TimescaleDB hypertable — OHLCV + indicators per ticker per timestamp.

ColumnTypeNotes
tickerVARCHAR(20)e.g. SPY, BTC-USDT
timestampTIMESTAMPTZUTC — partition key
open / high / low / closeNUMERIC(18,8)OHLCV fields
volumeNUMERIC(18,2)
rsi / macd / bb_upper / bb_lowerNUMERIC(12,6)Pre-computed indicators
asset_classVARCHAR(20)crypto / forex / equity
signals

Trade signal records from the prediction engine, including ensemble breakdown.

ColumnTypeNotes
idUUID PK
tickerVARCHAR(20)
directionVARCHAR(10)LONG / SHORT / HOLD
confidenceNUMERIC(5,4)0.0 – 1.0
ensemble_breakdownJSONBPer-model scores + tier weights
statusVARCHAR(20)PENDING / APPROVED / REJECTED / EXPIRED
expires_atTIMESTAMPTZAuto-reject after 15 min if HIL pending
created_atTIMESTAMPTZ
orders

Placed orders with full lifecycle tracking from submission to fill.

ColumnTypeNotes
idUUID PK
signal_idUUID FK → signals
tickerVARCHAR(20)
sideVARCHAR(10)BUY / SELL
quantityNUMERIC(18,8)
priceNUMERIC(18,8)Limit or market fill price
brokerVARCHAR(30)binance / ibkr / mt4 / paper
statusVARCHAR(20)PENDING / FILLED / CANCELLED / FAILED
broker_order_idVARCHAR(100)External reference
created_at / filled_atTIMESTAMPTZ
positions

Open and closed positions with PnL tracking.

ColumnTypeNotes
idUUID PK
tickerVARCHAR(20)
sideVARCHAR(10)LONG / SHORT
sizeNUMERIC(18,8)
entry_price / current_priceNUMERIC(18,8)
unrealized_pnl / realized_pnlNUMERIC(18,8)
stop_loss / take_profitNUMERIC(18,8)
statusVARCHAR(20)OPEN / CLOSED
opened_at / closed_atTIMESTAMPTZ
pnl_snapshotshypertable

TimescaleDB hypertable — periodic NAV + PnL snapshots for portfolio tracking.

ColumnTypeNotes
timestampTIMESTAMPTZPartition key
total_navNUMERIC(18,2)Net Asset Value
daily_pnl / cumulative_pnlNUMERIC(18,8)
drawdownNUMERIC(8,6)Current drawdown fraction
open_positionsINTEGER
snapshot_typeVARCHAR(20)HOURLY / DAILY / EOD
model_metrics

Per-model performance scores used by the PPO meta-controller for weight adjustment.

ColumnTypeNotes
idUUID PK
model_nameVARCHAR(50)arima, xgboost, finbert, etc.
accuracy / sharpe / hit_rateNUMERIC(8,4)
current_weightNUMERIC(6,4)Runtime weight (PPO-adjusted)
computed_atTIMESTAMPTZ

Hypertable Configuration

TableChunk IntervalCompressionRetention
market_data7 daysAfter 7 days3 years
pnl_snapshots1 dayAfter 30 days5 years
microstructure_signals1 dayAfter 7 days1 year

Continuous Aggregates

Materialized ViewSourceIntervalRefresh
market_data_hourlymarket_data1 hourReal-time
market_data_dailymarket_data1 dayEOD
market_data_weeklymarket_data7 daysWeekly

Index Strategy

TableColumnsTypePurpose
market_data(ticker, timestamp)PK / HypertablePrimary lookup
market_data(asset_class, timestamp)BTREEAsset-class scans
orders(ticker, created_at)BTREEOrder history by ticker
orders(status, created_at)BTREEPENDING order monitoring
signals(ticker, created_at)BTREERecent signal lookup
signals(status, expires_at)BTREESignal expiry cleanup
positions(status, ticker)BTREEOpen position queries
model_metrics(model_name, computed_at)BTREEScorer lookups

JSONB Fields

signals.ensemble_breakdown stores per-model confidence scores and tier weights as JSONB — enabling flexible schema evolution without migrations as new models are added. orders.metadata holds broker-specific raw responses for audit trails.