How maxnardone/scalable-cloud-api-for-trading-analysis works
Project Type and Purpose
• Cloud-native, multi-cloud Flask API for trading-strategy risk/profit analysis
• Uses Monte Carlo simulations for risk, integrates AWS Lambda (serverless), EC2 (heavy compute), and Google App Engine (Flask hosting + static/chart storage)
File Structure
• EC2 instance code/monte_carlo.py → compute logic deployed on EC2
• Lambda functions/
• MonteCarloSimulation1.py – warm-up parallel simulation
• create_audit.py, read_audit.py – audit log operations
• create_ec2_instance.py, terminate_instances.py – EC2 lifecycle management
• Root
• index.py – Flask app (API endpoints)
• app.yaml – GAE deployment config
• requirements.txt – Python dependencies
• static/ (generated_risk_chart.html, styles.css)
• templates/ (risk_chart.html)
README for Insights
• 15 REST endpoints for orchestration (/warmup, /analyse, /get_*, /terminate, etc.)
• Charts stored temporarily on GAE
• Auditing, cost/time reporting
Main Components
a. Client Layer
• Browser or HTTP client consuming the REST API
b. API Layer (Google App Engine)
• Flask (index.py)
• Static assets & templates for risk chart
c. Serverless Orchestration (AWS Lambda)
• MonteCarloSimulation1 – warm-up & invocation
• create_ec2_instance, terminate_instances – EC2 management
• create_audit, read_audit – audit database operations
d. Compute Layer (EC2 Instances)
• Run monte_carlo.py for heavy Monte Carlo simulations
e. Data & Storage
• Audit log store (e.g. DynamoDB or GAE Datastore)
• Generated chart files in GAE static storage
f. External Services
• AWS API Gateway (or HTTPS) fronting Lambdas
• IAM roles networking
Relationships & Interactions
• Client → HTTP → GAE Flask API
• /warmup → Flask → AWS API Gateway → MonteCarloSimulation1 Lambda
• MonteCarloSimulation1 may ➔ create_ec2_instance Lambda ➔ EC2 spin-up
• EC2 runs monte_carlo.py ➔ returns results to Lambda ➔ create_audit Lambda logs results
• Flask /analyse and /get_* endpoints call relevant Lambda (or read DB) for data
• /get_chart_url returns the GAE static URL of generated risk_chart.html
• /terminate → Flask → terminate_instances Lambda ➔ EC2 scale-down
Architectural Patterns
• Microservices / serverless functions for orchestration
• Serverful EC2 for long-running compute
• Clear separation: API, orchestration, compute, storage