How akisionov/reinforcement-learning-model-for-stock-market-data works
Scope and topology
This is a Python deep-reinforcement-learning trading project split into a model-development package and a paper-trading deployment package. The training side produces PPO model artifacts from engineered DJIA market data; the deployment side loads the model, obtains current market data, computes target weights, and paper-executes or simulates trades.
Key roots: Optimized_RL_Trading_Strategy/, RL_Paper_Trading_Deployment/, README.md.
Training and optimization entry points
Training is orchestrated as runnable Python/notebook workflows. train_optimized.py is the primary model-training entry point; evaluate.py evaluates trained policies; main.ipynb is an interactive workflow, with build_notebook.py supporting notebook construction.
Paths: Optimized_RL_Trading_Strategy/train_optimized.py, Optimized_RL_Trading_Strategy/evaluate.py, Optimized_RL_Trading_Strategy/main.ipynb.
Market-data and feature boundary
The offline pipeline consumes and prepares market dynamics for RL. The persisted engineered dataset contains DJIA assets and features such as HMM regimes, GARCH volatility, and Corwin-Schultz spreads. This dataset is the explicit contract between feature engineering and environment/training consumers.
Paths: Optimized_RL_Trading_Strategy/data_pipeline.py, Optimized_RL_Trading_Strategy/data/processed_market_dynamics.csv.
RL environment and learning contract
The custom environment is the central simulation boundary: it exposes a 567-dimensional observation space and encodes regime-based position clipping, circuit breakers, turnover penalties, transaction costs, and downside-risk-oriented rewards. PPO training interacts with this environment rather than directly with external brokers or live feeds.
Paths: Optimized_RL_Trading_Strategy/custom_env.py, Optimized_RL_Trading_Strategy/train_optimized.py.
Model artifacts and validation
Trained Stable-Baselines/PPO artifacts are committed and consumed across phases. Training produces final/best models and evaluation arrays; stress tooling provides a separate resilience-validation path. Deployment carries its own model copy, making artifact version alignment a material operational boundary.
Paths: Optimized_RL_Trading_Strategy/trained_models/final_model.zip, Optimized_RL_Trading_Strategy/trained_models/evaluations.npz, Optimized_RL_Trading_Strategy/stress_harness_m2.py, RL_Paper_Trading_Deployment/optimal_trading_model.zip.
Live inference and execution
trade_executor.py bridges offline policy output to current trading operations: it fetches real-time Yahoo Finance data, runs model inference for portfolio target weights, and sends paper orders to Alpaca when credentials exist. Without Alpaca keys, it falls back to local mock execution. This is the critical boundary between model decisions and external side effects.
Paths: RL_Paper_Trading_Deployment/trade_executor.py, RL_Paper_Trading_Deployment/.env.example, RL_Paper_Trading_Deployment/secrets_guide.md.
Operator interface and runtime infrastructure
The deployment is a local Streamlit application, launched through dashboard.py, for live portfolio performance, daily P&L, and market-regime visibility. Material runtime dependencies include Python, Stable-Baselines3, Yahoo Finance (yfinance), Streamlit, and Alpaca’s trading API. A scheduled GitHub Actions workflow is present for daily trading automation.
Paths: RL_Paper_Trading_Deployment/dashboard.py, RL_Paper_Trading_Deployment/requirements.txt, RL_Paper_Trading_Deployment/.streamlit/secrets.toml.example, .github/workflows/daily_trading.yml.
Main entry points: trade_executor.py Trade executor · final_model.zip Final PPO model · train_optimized.py PPO training · processed_market_dynamics.csv Engineered market data
Components 17
Model Development
- Feature pipeline · Builds engineered DJIA market dynamics.
Optimized_RL_Trading_Strategy/data_pipeline.py - Engineered market data · Feature contract for training and simulation.
Optimized_RL_Trading_Strategy/data/processed_market_dynamics.csv - Trading environment · 567-dimensional simulation with risk and trading constraints.
Optimized_RL_Trading_Strategy/custom_env.py - PPO training
Optimized_RL_Trading_Strategy/train_optimized.py - Interactive workflow
Optimized_RL_Trading_Strategy/main.ipynb - Final PPO model
Optimized_RL_Trading_Strategy/trained_models/final_model.zip - Evaluation results
Optimized_RL_Trading_Strategy/trained_models/evaluations.npz - Policy evaluation
Optimized_RL_Trading_Strategy/evaluate.py - Stress validation · Validates policy resilience separately from standard evaluation.
Optimized_RL_Trading_Strategy/stress_harness_m2.py
Paper Trading Deployment
- Deployment model copy · Operational artifact that must remain aligned with training output.
RL_Paper_Trading_Deployment/optimal_trading_model.zip - Trade executor · Computes target weights and submits or simulates paper trades.
RL_Paper_Trading_Deployment/trade_executor.py - Operator dashboard · Shows portfolio performance, daily P&L, and market regime.
RL_Paper_Trading_Deployment/dashboard.py - Credential setup · Defines Alpaca credential configuration.
RL_Paper_Trading_Deployment/.env.example - Daily trading schedule
.github/workflows/daily_trading.yml - Local mock execution · Used when Alpaca credentials are unavailable.
External Services
- Yahoo Finance · Supplies current market data through yfinance.
- Alpaca paper trading
Connections 16
- Feature pipeline → Engineered market data: writes
- Engineered market data → Trading environment: provides features
- Trading environment → PPO training: simulation interface
- Interactive workflow → PPO training: runs
- PPO training → Final PPO model: produces
- PPO training → Evaluation results: writes
- Final PPO model → Policy evaluation: evaluates
- Final PPO model → Stress validation: stress tests
- Final PPO model → Deployment model copy: version-aligned copy
- Deployment model copy → Trade executor: loads policy
- Yahoo Finance → Trade executor: current market data
- Credential setup → Trade executor: configures broker access
- Trade executor → Alpaca paper trading: paper orders
- Trade executor → Local mock execution: without credentials
- Operator dashboard → Trade executor: trading and portfolio view
- Daily trading schedule → Trade executor: runs daily