Advanced automated trading system leveraging deep learning ensemble for Korean stock market (KOSPI/KOSDAQ). Combines LSTM sequence learning, multi-model gradient boosting, meta-fusion network, and adversarial training for robust performance.
Backtest Performance (2020-2023, Samsung Electronics)
| Metric | Value |
|---|---|
| Total Return | 57.98% |
| Annualized Return | 12.18% |
| Sharpe Ratio | 0.76 |
| Maximum Drawdown | -33.33% |
| Win Rate | 100% |
| Total Trades | 10 |

Portfolio value evolution from 10M KRW initial capital, compared with buy-and-hold benchmark.

Strategy returns vs benchmark over the full backtest period.

Peak-to-trough decline showing maximum drawdown of -33.33%.
AI Ensemble System (80%) Traditional (20%)
┌──────────────────────────────────┐ ┌───────────────┐
│ LSTM (30%) │ │ Momentum │
│ XGBoost (25%) │ │ Indicators │
│ LightGBM (15%) │ │ │
│ CatBoost (10%) │ └───────┬───────┘
│ │ │
│ ┌────────────────────┐ │ │
│ │ Meta-Fusion │◄─────────┼───────────────┤
│ │ Network │ │ │
│ └────────────────────┘ │ ▼
│ + Market Context │ ┌─────────────┐
└──────────────────────────────────┘ │ Signal │
│ + Position │
└─────────────┘
Core Components:
- LSTM Sequence Learner (30%) - Temporal pattern recognition in 20-day windows
- Multi-Model Gradient Boosting (50%) - XGBoost, LightGBM, CatBoost ensemble
- Meta-Fusion Network - Neural network for optimal model combination
- Adversarial Training - Robustness enhancement
- Momentum Support (20%) - Traditional technical indicators
git clone <repository-url>
cd ai-automated-trade
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt# Train all models (LSTM + XGBoost + LightGBM + CatBoost + Meta-Fusion)
python train.py --config config.yaml --device cpu
# With GPU (if available)
python train.py --device cudaTraining Time: 2-3 hours on GPU, 5-6 hours on CPU
# Run integration test
python test.py
# Run backtest
python backtest.pyai-automated-trade/
├── train.py # Training pipeline
├── test.py # Integration test
├── backtest.py # Backtesting script
├── config.yaml # Configuration
├── requirements.txt # Dependencies
│
├── src/
│ ├── data/
│ │ ├── pipeline.py # Data loading and preprocessing
│ │ └── sequences.py # LSTM sequence preparation
│ ├── features/
│ │ └── indicators.py # Technical indicators + market context
│ ├── models/
│ │ ├── lstm_predictor.py # LSTM sequence learner
│ │ ├── feature_learner.py # Neural feature extraction
│ │ ├── gb_ensemble.py # Multi-model gradient boosting
│ │ └── meta_fusion.py # Meta-fusion network
│ └── utils/
│ └── config.py # Configuration utilities
│
├── models/ # Trained model storage
├── results/ # Backtest results and charts
└── data/ # Market data cache
- LSTM Architecture: 2-layer LSTM with 128 hidden units
- Sequence Length: 20-day temporal patterns
- Feature Learning: Auto-extraction from raw OHLCV data
- Parameters: 220,859 trainable parameters
- XGBoost: 200 estimators, all features (25% weight)
- LightGBM: 300 estimators, top 70% features (15% weight)
- CatBoost: 250 iterations, random 80% features (10% weight)
- Feature Diversity: Each model sees different feature subsets
- Meta-Fusion Network: 13 → 32 → 16 → 3 architecture
- Inputs: 4 model predictions + 5 market context features
- Learning: Optimal combination learned from historical data
- Adaptability: Adjusts to changing market conditions
- Adversarial Training: Hard example mining and noise injection
- Early Stopping: Prevents overfitting during training
- Validation: Comprehensive out-of-sample testing
Edit config.yaml to customize:
models:
lstm:
sequence_length: 20
hidden_size: 128
num_layers: 2
dropout: 0.3
learning_rate: 0.001
num_epochs: 100
xgboost:
n_estimators: 200
max_depth: 6
learning_rate: 0.1
lightgbm:
n_estimators: 300
feature_fraction: 0.7
catboost:
iterations: 250
depth: 4
meta_fusion:
hidden_dims: [32, 16]
dropout: 0.2
weights:
lstm: 0.30
xgboost: 0.25
lightgbm: 0.15
catboost: 0.10
momentum: 0.20
data:
ticker: "005930.KS" # Samsung Electronics
start_date: "2015-01-01"
end_date: "2023-12-31"Deep Learning:
torch>=2.0.0(LSTM, Meta-Fusion)xgboost>=2.0.0lightgbm>=4.0.0catboost>=1.2.0
Data & Utilities:
pandas,numpypandas-ta(Technical indicators)yfinance(Market data)scikit-learn(Preprocessing)
See requirements.txt for complete list.
# Run all tests
pytest tests/ -v
# Integration test
python test.py
# Full backtest
python backtest.pyInput: (batch, 20, 18) # 20 days, 18 features
↓
LSTM Layer 1: 128 units, dropout 0.3
↓
LSTM Layer 2: 128 units, dropout 0.3
↓
FC Layers: 128 → 64 → 3 (Buy/Hold/Sell)
Input: 13 features
- 4 models × 2 (signal, confidence) = 8
- 5 market context features = 5
↓
Dense: 13 → 32, ReLU, Dropout(0.2)
↓
Dense: 32 → 16, ReLU
↓
Output: 16 → 3 (Buy/Hold/Sell probabilities)
Deep Learning:
- Hochreiter & Schmidhuber (1997). "Long Short-Term Memory"
- Goodfellow et al. (2014). "Explaining and Harnessing Adversarial Examples"
Gradient Boosting:
- Chen & Guestrin (2016). "XGBoost: A Scalable Tree Boosting System"
- Ke et al. (2017). "LightGBM: A Highly Efficient Gradient Boosting Decision Tree"
- Prokhorenkova et al. (2018). "CatBoost: Unbiased Boosting with Categorical Features"
Financial Machine Learning:
- López de Prado (2018). "Advances in Financial Machine Learning"
This software is for educational and research purposes only. Trading involves significant financial risk. Past performance does not guarantee future results. Never risk capital you cannot afford to lose.