Personal project · 2025–2026

QuantLite

A full-stack quantitative research platform for Chinese A-shares and global market narratives. It predicts cross-sectional returns, scores sector rotation, tests market-regime signals and tracks emerging macro narratives with a local LLM. It runs every day on one machine and serves one user.

PythonFastAPIPostgreSQL 17 SQLAlchemy · AlembicLightGBMpandas APSchedulerNext.js · ReactDocker Local LLM + embeddings

Architecture

Twelve scheduled jobs heal data gaps every night, and each one is safe to re-run. Model serving, research scripts and the dashboard all read from the same PostgreSQL store.

Data flows from Tushare and RSS feeds through schedulers into PostgreSQL, then to feature snapshots, models, research and a web dashboard. SOURCES INGESTION STORAGE & MODELS SERVING & RESEARCH Tushare API A-share prices, flows, margin 23 RSS / podcast feeds macro blogs, FT, EIA, BIS yfinance overseas equities & ETFs 12 schedulers APScheduler, misfire-safe, idempotent gap healing LLM claim extraction local model → claims embeddings → themes launchd backups pg_dump, verified, 8 kept PostgreSQL 17 20+ tables, Alembic migrations Feature snapshots 110 features, atomic Parquet writes LightGBM, 5 horizons walk-forward validated, calibrated, promotion gates FastAPI · 23 routers screening, portfolio, health Next.js dashboard rotation, radar, portfolio Research scripts backtests, significance tests, daily narrative brief

Cross-sectional return prediction

LightGBM models rank about 5,000 stocks by their expected excess return over 1 to 20 trading days. Each month below is scored out of sample by a model trained only on data before that month.

Monthly rank IC, walk-forward

Spearman correlation between predicted and realized excess return, one column per test month.

View as table

Serving calibration

The models were trained on rank metrics only, so their raw outputs were about 12× too large in level. A linear calibration is fitted against realized returns and only ships if its slope is stable across both halves of the sample and it lowers out-of-sample error.

Research that didn't ship

I backfilled 22 years of market-breadth data to test whether a "market strength" score could time exposure. The signal is real, but it does not survive realistic costs, so it was not connected to the risk model.

The signal exists

Mean next-20-day market return by quintile of today's strength score, 2004–2026.

View as table

But timing with it loses to doing nothing

Sharpe ratio of the timing strategy compared with a fixed position of the same average size. Includes 0.15% one-way cost.

Strength-timed exposure Fixed exposure, same average
View as table

Sector rotation

For each of 30 Shenwan level-1 sectors, the system compares market sentiment (price, flows, leverage) with fundamental expectations (earnings pre-announcements, analyst estimates). A large positive gap marks a sector whose fundamentals are running ahead of how the market is treating it.

Expectation minus sentiment, by sector

Expectations ahead of sentiment Sentiment ahead of expectations
View as table

Narrative Radar

Narrative Radar reads macro and markets writing three times a day. It pulls out explicit investment claims, groups them into themes and ranks the themes by momentum. Each theme is then mapped to the overseas stocks and ETFs it would affect.

Momentum weights are not calibrated yet. The score is being tested with non-overlapping forward windows and is not used for any position sizing. Scores are point-in-time: a past day is never rescored with knowledge from later theme merges, and new sources warm up for 28 days before they count toward growth.

Top themes by momentum

Engineering notes

Failures that taught me something, each one found in production on this system.

Scheduling

A sleeping laptop silently dropped a day of jobs

APScheduler skips any job that misses its trigger by more than one second. After the Mac woke up, more than a dozen jobs were dropped with no error. The container looked healthy and the main price table was still updating, but sector flows stopped for three days.

Fix: a 6-hour misfire grace period with coalescing, applied only to idempotent jobs. Model training keeps skip-on-miss.

Data correctness

A score that was a constant for 446 days

The "expectation" part of the rotation model had exactly one value per sector for almost two years. Report periods were hardcoded, and analyst estimates were stored against the wrong schema (wide instead of long), so the column was always empty. Nothing errored.

Fix: periods are now derived from the trade date, with a look-ahead filter on announcement dates. The check is now count(distinct score), not "did the job succeed".

Deployment

Green tests, crashed container

The local environment ran Python 3.14, which evaluates annotations lazily, while the container still ran 3.12. A lint autofix removed quotes from a self-referencing type hint. That passed every test locally but raised NameError on import in the container, so all 12 schedulers stopped.

Fix: rebuilt the image and added a runtime-version check to the verification checklist. When something is missing, check the container's status before looking at the data.

Backups

A TTY corrupted the database dump

Piping pg_dump through docker exec -t turned every \n into \r\n, and pg_restore then segfaulted on the archive.

Fix: dumps are now written inside the container, copied out and checked with a SHA-256 comparison and pg_restore -l. They run daily from launchd with rotation.