Skip to content

Latest commit

 

History

History
732 lines (496 loc) · 15.2 KB

File metadata and controls

732 lines (496 loc) · 15.2 KB

CLI Reference

Command-line interface reference for QuantumVest administration, data operations, and development tasks.

Table of Contents


Overview

QuantumVest provides CLI tools through shell scripts and Python scripts for administration, development, and operational tasks.

CLI Components

Component Location Purpose
Setup Scripts scripts/ Environment setup and installation
Backend CLI code/backend/ Database, API, and data operations
AI Model CLI code/ai_models/ Model training and evaluation
DevOps Scripts scripts/ Deployment and maintenance

Installation

No separate CLI installation required. Scripts are available after repository clone.

git clone https://github.com/quantsingularity/QuantumVest.git
cd QuantumVest
chmod +x scripts/*.sh  # Make scripts executable

Global Options

Most scripts support common options:

Option Description Example
--help Show help message ./script.sh --help
--verbose Enable verbose output ./script.sh --verbose
--config FILE Use custom config file ./script.sh --config custom.conf

Commands

Setup Commands

setup_quantumvest_env.sh

Complete environment setup for QuantumVest.

Usage:

./scripts/setup_quantumvest_env.sh [OPTIONS]

Description: Installs all dependencies, creates virtual environments, and configures the application.

What it does:

  • Creates Python virtual environment
  • Installs backend dependencies
  • Installs frontend dependencies
  • Sets up database connections
  • Initializes configuration files

Example:

# Standard setup
./scripts/setup_quantumvest_env.sh

# With verbose output
VERBOSE=1 ./scripts/setup_quantumvest_env.sh

env_setup.sh

Environment-specific configuration setup.

Usage:

./scripts/env_setup.sh [environment]

Arguments:

Argument Description Example
environment Target environment (dev/staging/prod) staging

Example:

# Setup development environment
./scripts/env_setup.sh dev

# Setup production environment
./scripts/env_setup.sh prod

Server Commands

run_quantumvest.sh

Start all QuantumVest services.

Usage:

./scripts/run_quantumvest.sh [OPTIONS]

Options:

Option Description Example
--backend-only Start only backend --backend-only
--frontend-only Start only frontend --frontend-only
--port PORT Custom port --port 8080

Example:

# Start all services
./scripts/run_quantumvest.sh

# Start backend only on port 8000
./scripts/run_quantumvest.sh --backend-only --port 8000

Backend Server (app.py)

Start Flask backend server directly.

Usage:

cd code/backend
source venv/bin/activate
python app.py [OPTIONS]

Environment Variables:

Variable Default Description
FLASK_APP app.py Application entry point
FLASK_ENV development Environment mode
FLASK_HOST 0.0.0.0 Server host
FLASK_PORT 5000 Server port

Example:

# Development server
FLASK_ENV=development python app.py

# Production with Gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:app

Database Commands

migrate_db.py

Database migration and initialization.

Usage:

cd code/backend
source venv/bin/activate
python migrate_db.py [COMMAND]

Commands:

Command Description Example
init Initialize database python migrate_db.py init
migrate Create migration python migrate_db.py migrate
upgrade Apply migrations python migrate_db.py upgrade
downgrade Revert migration python migrate_db.py downgrade
seed Seed default data python migrate_db.py seed

Examples:

# Initialize database
python migrate_db.py init

# Create migration for model changes
python migrate_db.py migrate -m "Add portfolio metrics table"

# Apply all pending migrations
python migrate_db.py upgrade

# Revert last migration
python migrate_db.py downgrade

# Seed database with default assets
python migrate_db.py seed

Data Pipeline Commands

Data Fetcher

Fetch market data for assets.

Usage:

cd code/backend
python -m data_pipeline.data_fetcher [OPTIONS]

Options:

Option Description Example
--symbol SYMBOL Asset symbol --symbol AAPL
--type TYPE Asset type (stock/crypto) --type stock
--days DAYS Historical days --days 365
--output FILE Output file --output data.csv

Examples:

# Fetch Apple stock data for 1 year
python -m data_pipeline.data_fetcher --symbol AAPL --type stock --days 365

# Fetch Bitcoin data
python -m data_pipeline.data_fetcher --symbol BTC --type crypto --days 180

# Fetch and save to file
python -m data_pipeline.data_fetcher --symbol TSLA --days 730 --output tsla_data.csv

Stock API

Direct stock data operations.

Usage:

python -c "from data_pipeline.stock_api import StockDataFetcher; \
fetcher = StockDataFetcher(); \
data = fetcher.get_stock_data('AAPL'); \
print(data)"

Example:

# Get current stock price
python -c "from data_pipeline.stock_api import StockDataFetcher; \
print(StockDataFetcher().get_stock_data('AAPL')['price'])"

# Get historical data
python -c "from data_pipeline.stock_api import StockDataFetcher; \
history = StockDataFetcher().get_historical_data('MSFT', period='1y'); \
print(history.head())"

Model Commands

Train Prediction Model

Train AI prediction models.

Usage:

cd code/ai_models
python train_prediction_model.py [OPTIONS]

Options:

Option Type Required Default Description Example
--asset_type string No stock Asset type --asset_type crypto
--symbol string Yes - Asset symbol --symbol AAPL
--epochs int No 100 Training epochs --epochs 200
--batch_size int No 32 Batch size --batch_size 64
--lookback int No 60 Lookback window --lookback 90
--output string No models/ Model output dir --output trained/

Examples:

# Train AAPL stock model
python train_prediction_model.py --symbol AAPL --epochs 150

# Train BTC crypto model with custom params
python train_prediction_model.py \
  --asset_type crypto \
  --symbol BTC \
  --epochs 200 \
  --batch_size 64 \
  --lookback 90

# Train and save to custom location
python train_prediction_model.py --symbol GOOGL --output ./trained_models/

Train Optimization Model

Train portfolio optimization models.

Usage:

cd code/ai_models
python train_optimization_model.py [OPTIONS]

Options:

Option Description Example
--data_path PATH Training data path --data_path ../resources/datasets/
--model_type TYPE Model type (rf/xgb/nn) --model_type xgb
--evaluate Run evaluation --evaluate

Example:

# Train optimization model
python train_optimization_model.py --data_path ../resources/datasets/

# Train with XGBoost
python train_optimization_model.py --model_type xgb --evaluate

# Evaluate existing model
python train_optimization_model.py --evaluate

Data Preprocessing

Preprocess data for model training.

Usage:

cd code/ai_models/training_scripts
python data_preprocessing.py [OPTIONS]

Options:

Option Description Example
--input FILE Input data file --input raw_data.csv
--output FILE Output file --output processed.csv
--features LIST Feature columns --features price,volume

Example:

# Preprocess raw data
python data_preprocessing.py \
  --input ../../resources/datasets/raw_stock_data.csv \
  --output ../../resources/datasets/processed_data.csv

# Select specific features
python data_preprocessing.py \
  --input raw.csv \
  --output processed.csv \
  --features price,volume,ma_50,ma_200

Testing Commands

run_all_tests.sh

Run complete test suite.

Usage:

./scripts/run_all_tests.sh [OPTIONS]

Options:

Option Description Example
--coverage Generate coverage report --coverage
--verbose Verbose output --verbose
--fast Skip slow tests --fast

Example:

# Run all tests
./scripts/run_all_tests.sh

# Run with coverage
./scripts/run_all_tests.sh --coverage

# Fast test run
./scripts/run_all_tests.sh --fast

run_backend_tests.sh

Run backend tests only.

Usage:

./scripts/run_backend_tests.sh

Example:

# Run backend tests
./scripts/run_backend_tests.sh

# Run specific test file
cd code/backend
pytest tests/test_endpoints.py -v

# Run with coverage
pytest --cov=. --cov-report=html

Pytest Commands

Direct pytest usage for backend.

Usage:

cd code/backend
pytest [OPTIONS] [PATH]

Common Options:

Option Description Example
-v Verbose output pytest -v
-k EXPR Run tests matching expression pytest -k "test_login"
--cov Coverage report pytest --cov=.
-x Stop on first failure pytest -x
--pdb Debug on failure pytest --pdb

Examples:

# Run all tests
pytest

# Run specific test file
pytest tests/test_endpoints.py

# Run tests matching pattern
pytest -k "test_portfolio"

# Run with coverage
pytest --cov=. --cov-report=html

# Stop on first failure
pytest -x

# Run in parallel (requires pytest-xdist)
pytest -n auto

Deployment Commands

deploy.sh

Deploy to environment.

Usage:

./scripts/deploy.sh [environment] [OPTIONS]

Arguments:

Argument Description Example
environment Target environment staging, production

Options:

Option Description Example
--skip-tests Skip test execution --skip-tests
--no-backup Skip database backup --no-backup
--force Force deployment --force

Examples:

# Deploy to staging
./scripts/deploy.sh staging

# Deploy to production with tests
./scripts/deploy.sh production

# Force deploy without backup
./scripts/deploy.sh production --force --no-backup

build_frontend.sh

Build frontend for production.

Usage:

./scripts/build_frontend.sh

Example:

# Build frontend
./scripts/build_frontend.sh

# The built files will be in web-frontend/build/

lint-all.sh

Run code quality checks.

Usage:

./scripts/lint-all.sh [OPTIONS]

Options:

Option Description Example
--fix Auto-fix issues --fix
--check-only Check without fixing --check-only

Example:

# Check code quality
./scripts/lint-all.sh

# Auto-fix issues
./scripts/lint-all.sh --fix

# Check only (CI mode)
./scripts/lint-all.sh --check-only

maintenance.sh

System maintenance operations.

Usage:

./scripts/maintenance.sh [COMMAND]

Commands:

Command Description Example
backup Backup database backup
restore Restore database restore
clean Clean old logs clean
optimize Optimize database optimize

Examples:

# Backup database
./scripts/maintenance.sh backup

# Restore from backup
./scripts/maintenance.sh restore

# Clean old logs
./scripts/maintenance.sh clean

# Optimize database
./scripts/maintenance.sh optimize

Command Cheat Sheet

Quick Reference

# Setup
./scripts/setup_quantumvest_env.sh

# Start services
./scripts/run_quantumvest.sh

# Database operations
cd code/backend && python migrate_db.py upgrade

# Fetch data
python -m data_pipeline.data_fetcher --symbol AAPL --days 365

# Train model
cd code/ai_models && python train_prediction_model.py --symbol AAPL

# Run tests
./scripts/run_all_tests.sh

# Deploy
./scripts/deploy.sh staging

# Lint code
./scripts/lint-all.sh --fix

# Maintenance
./scripts/maintenance.sh backup

Troubleshooting

Common Issues

1. Permission Denied

chmod +x scripts/*.sh

2. Virtual Environment Not Found

cd code/backend
python3 -m venv venv
source venv/bin/activate

3. Module Not Found

cd code/backend
source venv/bin/activate
pip install -r requirements.txt

4. Database Connection Failed

# Check PostgreSQL is running
sudo systemctl status postgresql

# Check connection string in .env
cat .env | grep DATABASE_URL

Next Steps


For script internals and customization, refer to inline script documentation