Skip to content

About

AI-powered investment analytics platform: Flask backend, on-chain data insights, portfolio optimization, React/RN UI.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

QuantumVest

CI/CD Status License: MIT Python 3.11+ Node 20+

QuantumVest is a predictive investment analytics platform: a Flask backend for portfolios, watchlists, risk metrics, AI price forecasts, and on-chain data, paired with a React web dashboard, a React Native (Expo) mobile app, Truffle smart contracts, and an ai_models package that provides forecasting, portfolio optimization, and risk models to the backend.

QuantumVest HomePage

Table of Contents

Overview

Topic Summary
Portfolios Create portfolios, record transactions, and view performance, with scipy-based optimization (efficient frontier) and VaR, CVaR, and stress-test risk metrics.
AI code/ai_models trains and serves forecasting models on demand through the backend's /predictions routes, and also provides an AI-based portfolio risk assessment.
On-chain A web3.py service reads and writes the Solidity contracts, including a Chainlink price feed. It reports itself as disconnected when no node is reachable.
Clients A React web dashboard and a React Native mobile app, both talking to the same REST API.
Tests 233 backend, 84 AI model, 47 smart contract, 31 web, and 28 mobile tests. All five suites run in CI.

Architecture

flowchart TD
    web["web-frontend (React, Vite)"] -->|"HTTP/JSON"| api
    mobile["mobile-frontend (React Native, Expo)"] -->|"HTTP/JSON"| api
    api["Flask backend: /api/v1 (auth, portfolios, watchlists, assets, risk, predictions, blockchain)"] --> db[("PostgreSQL, SQLite for local dev")]
    api -->|"in-process import"| ai["ai_models: forecasting, optimization, risk"]
    ai -->|"yfinance"| market["Market data"]
    api -->|"web3.py"| chain["Truffle contracts: PortfolioManager, TrendAnalysis, Oracle, Token, Governance, Staking, DataTracking"]
Loading
Compose service Image or build Host port Role
backend code/Dockerfile 5000 Flask API served by Gunicorn, with ai_models bundled
db postgres:15-alpine 5432 Primary database
redis redis:7-alpine 6379 Cache (password protected)
ganache trufflesuite/ganache 8545 Local chain (Compose profile blockchain)
blockchain-migrate node:20-alpine None One-shot contract deployment (Compose profile blockchain)

See docs/ARCHITECTURE.md for detail.

Project Structure

Path Purpose
code/backend Flask application: routes, services, models, security, data pipeline, and tests
code/ai_models Forecasting, optimization, and risk package: models, serving, training, and tests
code/blockchain Truffle project: Solidity contracts, migrations, and tests
web-frontend React (Vite) dashboard
mobile-frontend React Native (Expo) app
infrastructure Docker, Kubernetes (Helm), Terraform, Ansible, and monitoring configuration
scripts Setup, run, build, test, and deployment scripts
docs Project documentation
.github CI/CD workflow and its documentation

Feature Status

Component Details
API Flask backend with /api/v1 endpoints for auth, portfolios, watchlists, assets, risk, AI predictions, and blockchain, plus /api/v1/health and a Prometheus /metrics endpoint.
Auth JWT sessions (PyJWT) with bcrypt password hashing, account lockout settings, and an MFA module in app/core/security.py. Set SECRET_KEY and JWT_SECRET_KEY for any use beyond local development; a development default applies when they are unset.
Portfolio optimization A scipy-based efficient frontier and minimum-variance optimizer, plus Sharpe ratio, max drawdown, and beta calculations, served by POST /portfolios/{id}/optimize.
Risk service VaR (historical and parametric), CVaR, stress testing, and concentration-risk calculations, run in-process.
AI predictions /predictions/{symbol} returns a forecast, training a model on demand from yfinance data when none is stored (configurable with AI_AUTO_TRAIN). /portfolios/{id}/risk returns an AI-based risk assessment.
AI package Forecasting models (XGBoost, LightGBM, random forest, CatBoost ensemble; LSTM and Transformer), a constrained portfolio optimizer, VaR and expected-shortfall risk models, walk-forward backtests, and training command-line tools.
Compliance and alerts Portfolio compliance checks and a user-alerting service, backed by SQLAlchemy models.
Smart contracts PortfolioManager, TrendAnalysis (reads a Chainlink AggregatorV3Interface price feed), QuantumVestOracle, QuantumVestToken, QuantumVestGovernance, QuantumVestStaking, and DataTracking, on OpenZeppelin and Solidity 0.8.19.
Web dashboard React app (JavaScript, Vite, Chart.js, Framer Motion, React Router) with Home, Dashboard, Portfolios and Portfolio Detail, Watchlist, Risk Analytics, Predictions, Blockchain, Profile, Settings, and authentication pages, plus Contact, Privacy, and Terms.
Mobile app React Native (Expo) app with Home, Dashboard, Portfolios, Portfolio Detail, Predictions, Blockchain, Profile, and authentication screens, using React Navigation and React Native Paper.

Technology Stack

Area Technology
Backend API Python 3.11, Flask 2.3, Flask-SQLAlchemy, Flask-CORS, Flask-Caching, Gunicorn
Auth PyJWT, bcrypt, an in-house MFA module
Data layer SQLAlchemy 2, PostgreSQL (SQLite for local development), prometheus-client (/metrics)
Quant NumPy, SciPy, pandas, scikit-learn
ML XGBoost, LightGBM; optional CatBoost and TensorFlow (LSTM and Transformer)
Market data yfinance
Blockchain Solidity 0.8.19, OpenZeppelin 4.9, Chainlink contracts, Truffle, Ganache, web3.py
Web frontend React 18, JavaScript, Vite 5, Chart.js, Framer Motion, React Router, axios
Mobile frontend React Native, Expo (SDK 52), React Navigation, React Native Paper, react-native-chart-kit
Infrastructure Docker, Docker Compose, Kubernetes (Helm chart), Terraform (AWS), Ansible
Monitoring Prometheus, Grafana
CI/CD GitHub Actions
Testing pytest (backend and AI models), Truffle (contracts), Jest (web and mobile)

Installation and Setup

Prerequisites: Python 3.11+ and Node.js 20+. Docker is optional.

git clone https://github.com/quantsingularity/QuantumVest.git
cd QuantumVest

# Blockchain
cd code/blockchain
npm install

# Backend
cd ../backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

# Web frontend
cd ../../web-frontend
npm install --legacy-peer-deps

# Mobile frontend
cd ../mobile-frontend
npm install --legacy-peer-deps

The default AI ensemble (XGBoost, LightGBM, random forest) works with the backend requirements. For CatBoost, LSTM, and Transformer models, also install code/ai_models/requirements-dev.txt.

For an automated setup:

git clone https://github.com/quantsingularity/QuantumVest.git
cd QuantumVest
./scripts/setup_quantumvest_env.sh
./scripts/run_quantumvest.sh

Full, environment-specific instructions are in docs/INSTALLATION.md.

Running the Stack

# 1) Local chain (from code/blockchain)
npx ganache --port 8545 --chain.chainId 1337 --chain.networkId 1337 --wallet.deterministic

# 2) Deploy the contracts (from code/blockchain, second terminal)
npx truffle migrate --network development

# 3) Backend (from code/backend, venv active)
FLASK_ENV=development python wsgi.py       # http://0.0.0.0:5000, health check at /api/v1/health

# 4) Web dashboard (from web-frontend)
npm run dev                                # http://localhost:3000

# 5) Mobile app (from mobile-frontend)
npm start                                  # press w for web, a for Android, i for iOS

Local development uses SQLite, so no database is needed. The blockchain service reads WEB3_PROVIDER_URI (default http://localhost:8545), the build output in BLOCKCHAIN_ARTIFACTS_DIR, and the deployed contract addresses from the environment.

Or run the backend with PostgreSQL and Redis in Docker (from code/):

cd code
docker compose up --build backend

Add --profile blockchain to also start Ganache and deploy the contracts. For anything beyond local use, set SECRET_KEY, JWT_SECRET_KEY, DB_PASSWORD, and REDIS_PASSWORD in the environment first. See docs/USAGE.md and docs/CONFIGURATION.md.

API Surface

Base URL http://localhost:5000/api/v1. All routes except health, register, login, refresh, and the password-reset flow need a bearer token.

Group Endpoints
Health GET health
Auth POST register, login, logout, refresh, forgot-password, reset-password, change-password, and GET or PUT profile
Portfolios List and create, {id} (GET, DELETE), {id}/transactions (GET, POST), {id}/performance, {id}/optimize, {id}/risk
Assets GET assets, GET assets/search
Watchlists List and create, {id} (GET, DELETE), {id}/items (POST), {id}/items/{item_id} (DELETE)
Risk POST risk/var, POST risk/metrics
Predictions GET predictions/models, GET predictions/{symbol}, POST predictions/{symbol}/train
Blockchain status, trend, market-data, market-data/{ticker}, token/balance/{address}, oracle/{asset_address}

Full request and response shapes are in docs/API.md.

Testing

Suite Directory Tests Run locally
Backend code/backend 233 pytest
AI models code 84 python -m pytest ai_models
Contracts code/blockchain 47 npx truffle test (Ganache running)
Web web-frontend 31 npm test
Mobile mobile-frontend 28 npm test

Run each command from the directory shown. All five suites run in CI. The AI model tests need code/ai_models/requirements-dev.txt installed. End-to-end specs for the web (web-frontend/src/tests/e2e) and mobile (mobile-frontend/e2e, Detox) are separate and not run in CI. See CI/CD Pipeline.

CI/CD Pipeline

GitHub Actions (.github/workflows/cicd.yml) runs on pushes and pull requests to main and develop, and on manual dispatch. Every job after the first depends on Code Quality Checks, so the other eight run in parallel once formatting passes.

# Job Depends on What it does
1 Code Quality Checks None autoflake and black --check on Python, plus a repository-wide Prettier check (JS, TS, JSON, HTML, CSS, Markdown, Solidity, YAML)
2 Backend Test & Build Code Quality Checks Runs pytest with coverage, builds the backend image, checks it runs as non-root, and smoke tests /api/v1/health and /metrics
3 AI Models Test & Validation Code Quality Checks Byte-compiles ai_models, verifies its public API and sub-packages import, and runs its tests with coverage
4 Web-Frontend Test & Build Code Quality Checks npm ci, the Jest suite, the production Vite build, and a build upload
5 Mobile-Frontend Test & Build Code Quality Checks npm ci, the Jest suite with coverage, the Expo web export, and a bundle upload
6 Blockchain Contracts Code Quality Checks Compiles the contracts with Truffle, runs the tests on Ganache, verifies a full migration, and uploads the build output
7 Docs Validation Code Quality Checks markdownlint, offline link and anchor checks, code-sample syntax checks, docs and scripts consistency checks, and an advisory external link check
8 Infrastructure Validation Code Quality Checks Terraform, the Helm chart for all three environments, and Ansible validation, plus yamllint, Compose and Dockerfile checks, two image builds, and a secret scan
9 Scripts Validation Code Quality Checks ShellCheck, syntax, shebang, and executable-bit checks on every shell script, plus a --help smoke test for the CLI scripts

Coverage reports and build artifacts are kept for 7 to 30 days. The step-by-step breakdown of each job is in .github/readme/README.md.

Documentation

Document Contents
docs/README.md Documentation index
docs/ARCHITECTURE.md System architecture
docs/API.md REST API reference
docs/INSTALLATION.md Setup for all components
docs/CONFIGURATION.md Environment variables and config
docs/USAGE.md Running and using the platform
docs/CLI.md Helper scripts reference
docs/FEATURE_MATRIX.md Feature status, implemented vs planned
docs/TROUBLESHOOTING.md Common issues and fixes
docs/CONTRIBUTING.md Contribution guide
docs/examples/ai-prediction.md Example: requesting AI forecasts
docs/examples/portfolio-management.md Example: creating and managing portfolios
docs/examples/risk-analysis.md Example: running risk calculations

Contributing

See docs/CONTRIBUTING.md.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

AI-powered investment analytics platform: Flask backend, on-chain data insights, portfolio optimization, React/RN UI.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages