Relevant prompts are available here
A modern web application for managing investment portfolios, built with Flask, Apache, and MySQL in a Docker environment.
- Modern Web Interface: Clean, responsive design for portfolio management
- AI-Powered Trading: Bayesian investment strategies using PyMC3 and machine learning
- Paper Trading: Risk-free trading simulation using Alpaca API
- Database Integration: MySQL backend for data persistence
- Docker Environment: Easy setup and deployment with Docker Compose
- Apache Web Server: Production-ready web server configuration
Before you begin, ensure you have the following installed on your system:
- Docker (version 20.10 or higher)
- Docker Compose (version 2.0 or higher)
- Git (for version control)
# 1. Copy environment file
cp env.example .env
# 2. Build and start the application
docker-compose up -d --build
# 3. Access the application
# Web App: http://localhost:8080
# phpMyAdmin: http://localhost:8081git clone <your-repository-url>
cd curor-demoCopy the example environment file and configure your settings:
cp env.example .envQuick Setup (Optional): If you want to use default settings, you can skip editing the .env file for now. The application will work with the default values.
Edit the .env file with your preferred configuration:
# Database Configuration
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_DATABASE=investment_portfolio
MYSQL_USER=portfolio_user
MYSQL_PASSWORD=your_password
# Flask Configuration
FLASK_ENV=development
FLASK_DEBUG=1
SECRET_KEY=your_secret_key_here
# Application Configuration
APP_HOST=0.0.0.0
APP_PORT=5000
# Alpaca API Configuration (for paper trading)
ALPACA_API_KEY=your_alpaca_api_key
ALPACA_SECRET_KEY=your_alpaca_secret_key
ALPACA_BASE_URL=https://paper-api.alpaca.markets# Build the Docker images
docker-compose build
# Start all services
docker-compose up -d
# View logs (optional)
docker-compose logs -fOnce the containers are running, you can access the application at:
- Web Application: http://localhost:8080
- Database: localhost:3306 (MySQL)
The database will be automatically created on first run. If you need to reset the database:
# Stop the application
docker-compose down
# Remove the database volume
docker volume rm curor-demo_mysql_data
# Restart the application
docker-compose up -dcuror-demo/
βββ app/ # Flask application
β βββ __init__.py # Flask app initialization
β βββ routes.py # Application routes
β βββ models.py # Database models
β βββ bayesian_service.py # AI trading service
β βββ static/ # Static files (CSS, JS, images)
β βββ templates/ # HTML templates
β βββ index.html # Main landing page
β βββ dashboard.html # Portfolio dashboard
β βββ trading.html # AI trading dashboard
βββ docker/ # Docker configuration files
β βββ apache/ # Apache configuration
β βββ mysql/ # MySQL configuration
βββ docker-compose.yml # Docker Compose configuration
βββ docker-compose.dev.yml # Development overrides
βββ docker-compose.prod.yml # Production overrides
βββ Dockerfile # Flask application Dockerfile
βββ requirements.txt # Python dependencies
βββ env.example # Environment variables template
βββ README.md # This file
The application runs the following services:
- web: Apache web server with mod_wsgi for Flask
- app: Flask application container
- db: MySQL database server
- phpmyadmin: Database management interface (optional)
The project includes three Docker Compose files:
docker-compose.yml: Base configuration with all servicesdocker-compose.dev.yml: Development overrides (hot reload, additional ports)docker-compose.prod.yml: Production overrides (Gunicorn, resource limits, security)
# Start with development settings (includes hot reload and additional ports)
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
# Or start with basic configuration
docker-compose up -d# View all service logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f web
docker-compose logs -f app
docker-compose logs -f db# Stop all services
docker-compose down
# Stop and remove volumes (database data)
docker-compose down -v
# Stop development environment
docker-compose -f docker-compose.yml -f docker-compose.dev.yml downThe application follows a Model-View-Controller (MVC) pattern with the following key components:
Portfolio: Represents investment portfolios with relationships to investments and trading strategiesInvestment: Individual investment holdings with symbol, quantity, and purchase priceTradingStrategy: AI trading strategies with statistical parameters (alpha, beta, sigma)Trade: Individual paper trades with prediction data and performance metricsMarketData: Historical price data for analysis and backtesting
BayesianTradingService: Core service implementing statistical trading strategies- Market Data Integration: Fetches real-time data from Alpaca API using
alpaca-py - Statistical Analysis: Uses
scipy.stats.linregressfor return prediction - Signal Generation: Creates buy/sell signals based on predicted returns
- Paper Trading: Executes simulated trades with position sizing and risk management
- Market Data Integration: Fetches real-time data from Alpaca API using
index.html: Main landing page with navigation to trading dashboarddashboard.html: Portfolio management interfacetrading.html: AI trading dashboard with strategy creation and monitoring
The AI trading system uses a linear regression model for return prediction:
- Data Collection: Fetches historical price data from Alpaca API
- Return Calculation: Computes daily returns from price data
- Model Fitting: Fits linear regression to identify trends
- Prediction: Predicts next day's return using fitted model
- Signal Generation: Creates buy/sell signals based on predictions and confidence thresholds
- Alpaca API (
alpaca-py): Modern Python SDK for market data and paper trading - Trading Client: Handles order execution and account management
- Data Client: Retrieves historical market data for analysis
The application includes AI-powered trading strategies using statistical analysis:
- Statistical Model Fitting: Linear regression analysis for return prediction
- Paper Trading: Risk-free trading simulation using Alpaca API
- Real-time Analysis: Live market data analysis and prediction
- Strategy Management: Create, configure, and monitor trading strategies
- Access the Trading Dashboard: Navigate to
/tradingin the web application - Create Sample Data: Click "Create Sample Data" to populate the database with test data
- Create a Strategy: Set up a new trading strategy with your preferred parameters
- Configure Alpaca API: Add your Alpaca API credentials to the
.envfile for paper trading - Run Analysis: Use the "Analyze" feature to see predictions without executing trades
- Execute Trades: Run strategies to execute paper trades based on AI predictions
To enable paper trading functionality:
- Sign up for a free Alpaca account at alpaca.markets
- Get your API key and secret from the Alpaca dashboard
- Add them to your
.envfile:ALPACA_API_KEY=your_api_key_here ALPACA_SECRET_KEY=your_secret_key_here ALPACA_BASE_URL=https://paper-api.alpaca.markets
- Market Data Analysis: Historical price data analysis using Alpaca API
- Statistical Model Fitting: Linear regression models for return prediction
- Signal Generation: Buy/sell signals based on predicted returns
- Risk Management: Position sizing and confidence thresholds
- Performance Tracking: Win rate and P&L monitoring
-
Start the Application:
docker-compose up -d
-
Access the Web Interface:
- Open your browser and go to: http://localhost:8080
- You'll see the main landing page for "Investment Portfolio"
-
Navigate to Trading Dashboard:
- Click the "AI Trading Dashboard" button or go to: http://localhost:8080/trading
- This will take you to the AI trading interface
-
Create Sample Data:
- In the trading dashboard, click the "Create Sample Data" button
- This will populate the database with:
- Sample portfolio with $100,000 initial value
- Sample investments (AAPL, GOOGL, MSFT)
- Sample trading strategies
- Sample market data for analysis
-
Explore the Sample Portfolio:
- Portfolio Overview: View total value, investments, and performance
- Trading Strategies: See sample strategies with different parameters
- Recent Trades: View simulated trades with predictions and outcomes
- Market Data: Access historical price data for analysis
When you create sample data, the system generates:
- Portfolio: "Sample Portfolio" with $100,000 initial value
- Investments:
- AAPL: 50 shares at $150.00
- GOOGL: 30 shares at $2,800.00
- MSFT: 40 shares at $300.00
- Trading Strategies:
- "Conservative AAPL Strategy" (confidence: 0.1, position size: 0.05)
- "Aggressive GOOGL Strategy" (confidence: 0.05, position size: 0.1)
- Market Data: 100 days of historical price data for each symbol
- Analyze Strategies: Click "Analyze" on any strategy to see predictions
- Run Strategies: Click "Run Strategy" to execute paper trades
- View Results: Check the "Recent Trades" section to see trade outcomes
- Monitor Performance: Track win rates and P&L for each strategy
You can also view the sample data directly in the database:
# Access phpMyAdmin
# Open: http://localhost:8081
# Username: portfolio_user
# Password: your_password (from .env file)
# Or connect via command line
docker-compose exec db mysql -u portfolio_user -p investment_portfolio# Connect to MySQL container
docker-compose exec db mysql -u root -p
# Or use the provided credentials
docker-compose exec db mysql -u portfolio_user -p investment_portfolio# Create a backup
docker-compose exec db mysqldump -u root -p investment_portfolio > backup.sql
# Restore from backup
docker-compose exec -T db mysql -u root -p investment_portfolio < backup.sql- Update the
.envfile with production settings - Set
FLASK_ENV=productionandFLASK_DEBUG=0 - Use a production-ready secret key
- Configure proper database passwords
# Production build
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Or build and start in one command
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build- Port Already in Use: Change the port mappings in
docker-compose.yml - Database Connection Issues: Check the
.envfile configuration - Permission Errors: Ensure Docker has proper permissions
- Apache/Web Server Issues:
- Check if port 8080 is available
- Verify Apache configuration with
docker-compose logs web - Ensure the Flask app is running before Apache starts
# Rebuild containers
docker-compose build --no-cache
# Restart specific service
docker-compose restart app
# Check container status
docker-compose ps
# Access container shell
docker-compose exec app bash
# View specific service logs
docker-compose logs -f app
docker-compose logs -f db
docker-compose logs -f web
# Clean up everything (containers, volumes, networks)
docker-compose down -v --remove-orphans
docker system prune -f- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Review the Docker and Flask documentation
- Create an issue in the repository
Happy Coding! π