Complete installation instructions for RiskOptimizer across different platforms and environments.
- Prerequisites
- Installation Methods
- Platform-Specific Instructions
- Docker Installation
- Development Setup
- Verification
- Troubleshooting
Before installing RiskOptimizer, ensure you have the following installed:
| Software | Minimum Version | Purpose | Installation Check |
|---|---|---|---|
| Python | 3.8+ | Backend runtime | python --version |
| Node.js | 14+ | Frontend build | node --version |
| npm | 6+ | Package manager | npm --version |
| Git | 2.0+ | Version control | git --version |
| PostgreSQL | 12+ | Database (optional) | psql --version |
| Redis | 5+ | Caching (optional) | redis-cli --version |
| Resource | Minimum | Recommended | Notes |
|---|---|---|---|
| RAM | 4GB | 8GB+ | More for AI model training |
| CPU | 2 cores | 4+ cores | Multi-core for parallel processing |
| Storage | 10GB | 20GB+ | Includes data and models |
| OS | Linux/macOS/Windows | Ubuntu 20.04+, macOS 11+ | Windows requires WSL2 |
The automated setup script handles all dependencies and configuration:
# Clone the repository
git clone https://github.com/quantsingularity/RiskOptimizer.git
cd RiskOptimizer
# Run the setup script
./scripts/setup_environment.sh
# This script will:
# - Check system dependencies
# - Create Python virtual environment
# - Install backend dependencies
# - Install frontend dependencies
# - Set up environment configuration
# - Initialize the database (optional)For more control over the installation process:
git clone https://github.com/quantsingularity/RiskOptimizer.git
cd RiskOptimizercd code/backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install package in development mode
pip install -e .# Navigate to web frontend
cd ../../web-frontend
# Install dependencies
npm install
# Build for production (optional)
npm run buildcd ../code/blockchain
# Install Hardhat dependencies
npm install
# Compile smart contracts
npx hardhat compileUse Docker for containerized deployment:
# Clone repository
git clone https://github.com/quantsingularity/RiskOptimizer.git
cd RiskOptimizer
# Start all services
docker-compose up -d
# This starts:
# - Backend API (port 5000)
# - Frontend (port 3000)
# - PostgreSQL (port 5432)
# - Redis (port 6379)
# - Celery worker| OS / Platform | Recommended Install Command | Notes |
|---|---|---|
| Ubuntu 20.04+ | sudo apt-get update && sudo apt-get install -y python3.9 python3-pip nodejs npm postgresql redis-server |
Install system dependencies first |
| Ubuntu 22.04+ | sudo apt-get update && sudo apt-get install -y python3.10 python3-pip nodejs npm postgresql redis-server |
Python 3.10 recommended |
# Install system dependencies
sudo apt-get update
sudo apt-get install -y python3-pip python3-venv nodejs npm postgresql postgresql-contrib redis-server git
# Start services
sudo systemctl start postgresql redis-server
sudo systemctl enable postgresql redis-server
# Create database (optional)
sudo -u postgres createdb riskoptimizer
sudo -u postgres createuser -s $USER
# Continue with Method 1 or 2 above| OS / Platform | Recommended Install Command | Notes |
|---|---|---|
| macOS 11+ (Intel) | brew install python@3.10 node postgresql redis |
Use Homebrew package manager |
| macOS 11+ (Apple Silicon) | brew install python@3.10 node postgresql redis |
Native ARM support |
# Install Homebrew (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install dependencies
brew install python@3.10 node postgresql redis
# Start services
brew services start postgresql
brew services start redis
# Continue with Method 1 or 2 above| OS / Platform | Recommended Install Command | Notes |
|---|---|---|
| Windows 10/11 with WSL2 | Install WSL2, then follow Ubuntu instructions | Recommended approach |
| Windows 10/11 native | Download installers from official websites | PostgreSQL, Python, Node.js, Git for Windows |
Option A: WSL2 (Recommended)
# Install WSL2
wsl --install
# Follow Ubuntu instructions inside WSL2Option B: Native Windows
- Install Python 3.8+ from python.org
- Install Node.js 14+ from nodejs.org
- Install Git for Windows from git-scm.com
- Install PostgreSQL from postgresql.org (optional)
- Install Redis from redis.io or use WSL (optional)
- Continue with Method 2 (Manual Installation)
Create a .env file in the project root:
# Copy template
cp .env.example .env
# Edit with your configuration
# Required variables:
# - SECRET_KEY
# - JWT_SECRET_KEY
# - DATABASE_URL (if using PostgreSQL)
# - REDIS_URL (if using Redis)Example .env file:
# Application
ENVIRONMENT=development
SECRET_KEY=your-secret-key-here
JWT_SECRET_KEY=your-jwt-secret-here
# Database (optional - uses SQLite by default)
DB_USE_SQLITE=true
SQLITE_DB_PATH=riskoptimizer.db
# For PostgreSQL:
# DB_USE_SQLITE=false
# DB_HOST=localhost
# DB_PORT=5432
# DB_NAME=riskoptimizer
# DB_USER=postgres
# DB_PASSWORD=postgres
# Redis (optional)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
# Blockchain (optional)
BLOCKCHAIN_PROVIDER_URL=http://localhost:8545
PORTFOLIO_TRACKER_ADDRESS=
RISK_MANAGEMENT_ADDRESS=
# API
API_HOST=0.0.0.0
API_PORT=5000
CORS_ORIGINS=http://localhost:3000
# Celery (optional)
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0Verify your installation:
# Check backend
cd code/backend
python -c "import flask, pandas, numpy; print('Backend dependencies OK')"
# Check if app starts
python app.py &
sleep 3
curl http://localhost:5000/health
# Expected: {"status": "ok", ...}
kill %1
# Check frontend
cd ../../web-frontend
npm run build
# Should complete without errors
# Run tests
cd ../code/backend
pytest
# Expected: All tests passcd code/backend
python -c "from src.infrastructure.database.session import init_db; init_db()"# Sample historical data is in data/ directory
ls -lh data/
# You should see:
# - AAPL_historical.csv
# - MSFT_historical.csv
# - BTC_USD_historical.csv
# etc.# Use the convenience script
./scripts/run_riskoptimizer.sh
# Or start manually:
# Terminal 1: Backend
cd code/backend && python app.py
# Terminal 2: Frontend
cd web-frontend && npm start
# Terminal 3: Celery (optional)
cd code/backend && celery -A src.tasks.celery_app worker --loglevel=info- Web Interface: http://localhost:3000
- API Documentation: http://localhost:5000/apidocs
- Health Check: http://localhost:5000/health
- Docker Engine 20.10+
- Docker Compose 1.29+
# Clone repository
git clone https://github.com/quantsingularity/RiskOptimizer.git
cd RiskOptimizer
# Review docker-compose.yml
cat docker-compose.yml
# Start all services
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f backend
# Stop services
docker-compose down| Service | Port | Description |
|---|---|---|
| backend | 5000 | Flask API server |
| frontend | 3000 | React web app |
| postgres | 5432 | PostgreSQL database |
| redis | 6379 | Redis cache |
| celery-worker | - | Async task worker |
For active development:
# Run setup script with development options
./scripts/setup_dev_environment.sh
# This additionally:
# - Installs pre-commit hooks
# - Sets up linting tools
# - Configures IDE settings
# - Installs development dependenciesIssue: ModuleNotFoundError: No module named 'riskoptimizer'
Solution:
cd code/backend
pip install -e .Issue: Database connection failed
Solution:
# Use SQLite instead
export DB_USE_SQLITE=true
export SQLITE_DB_PATH=riskoptimizer.dbIssue: Redis connection failed
Solution:
# Redis is optional - application will work without it (no caching)
# Or start Redis:
redis-serverIssue: Port already in use
Solution:
# Change port in .env file
API_PORT=5001 # Instead of 5000For more troubleshooting, see TROUBLESHOOTING.md.
After successful installation:
- Read USAGE.md for usage instructions
- Check CONFIGURATION.md for advanced configuration
- Explore examples/ for code examples
- Review API.md for API documentation
To remove RiskOptimizer:
# Stop services
docker-compose down -v # If using Docker
# Remove virtual environment
rm -rf code/backend/venv
# Remove node modules
rm -rf web-frontend/node_modules
rm -rf mobile-frontend/node_modules
rm -rf code/blockchain/node_modules
# Remove database (optional)
sudo -u postgres dropdb riskoptimizer
# Remove project directory
cd ..
rm -rf RiskOptimizer