MarketLens AI

AI-powered stock decision support analyzing market trends and real-world signals — FastAPI serving a Random Forest + LightGBM ensemble over a PostgreSQL data layer.

FastAPIPythonPostgreSQLRandom ForestLightGBM
GitHub
01

System Architecture

REQUESTGET /signals/AAPL/decisiontracing
storetraining datatrainrecent datainferMarket FeedsPrices · fundamentalsEXTSignal SourcesNews · real-world eventsEXTClientDashboardCLIENTIngest WorkersNormalize · dedupeSVCFastAPIDecision endpointsSVCPostgreSQLMarket · signal storeDATAFeature PipelineWindows · indicatorsSVCModel EnsembleRandom Forest · LightGBMSVC

Ingest workers normalize market feeds and real-world signals into PostgreSQL. The feature pipeline builds training windows for the Random Forest + LightGBM ensemble. At request time, FastAPI pulls recent data, runs inference, and returns a scored decision.

02

Database Design

SCHEMA5 tables · 4 relationshover a table
instrumentsPostgreSQLiduuidsymbolvarcharexchangevarcharsectorvarcharcreated_attimestampmarket_dataPostgreSQLiduuidinstrument_iduuidtstimestampopennumericclosenumericvolumebigintsignalsPostgreSQLiduuidinstrument_iduuidsourcevarcharkindvarcharweightfloatobserved_attimestamppredictionsPostgreSQLiduuidinstrument_iduuidmodel_version_iduuidhorizonintervaldirectionenumconfidencefloatmodel_versionsPostgreSQLiduuidalgoenumversionvarchartrained_attimestampmetricsjsonb

Time-series market data and external signals key off instruments; predictions link back to both the instrument and the exact model version that produced them.

03

Engineering Challenges

01

Signal fusion

Market prices and unstructured real-world signals are normalized into one comparable feature space.

02

Training pipeline

Windowed feature generation and scheduled retraining keep the ensemble current as market regimes shift.

03

Fast inference

Model loading, caching, and lean feature queries keep decision endpoints responsive.

04

Explainability

Tree-based models expose feature importance, so a decision can always be traced to its drivers.

04

Trade-offs & Decisions

ChoseOverBecause
PostgreSQLMongoDBTime-series joins across instruments, signals, and predictions are fundamentally relational.
FastAPIFlaskAsync IO and typed contracts fit ML serving; OpenAPI docs come free.
RF + LightGBMDeep learningOn tabular financial data, gradient boosting wins on accuracy per unit of training cost — and stays explainable.