Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
/.idea
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Task 1 - FinRL Contest 2023 Results Summary

## Overview
This project implements and compares different approaches for algorithmic trading using reinforcement learning on stock market data.

## Approaches Implemented

### 1. Baseline PPO Model
- **Algorithm**: Proximal Policy Optimization (PPO)
- **Features**: Standard technical indicators (MACD, Bollinger Bands, RSI, CCI, DX, SMA, VIX, Turbulence)
- **Configuration**: Standard PPO parameters

### 2. Enhanced PPO Model
- **Algorithm**: Proximal Policy Optimization (PPO) with enhanced features
- **Features**:
- All baseline features
- Additional moving averages (5, 10, 20, 50 periods)
- Price momentum indicators (5, 10 periods)
- Volume indicators (volume ratio)
- Volatility indicators (20-period standard deviation)
- **Configuration**: Same PPO parameters as baseline

## Results Comparison

### Baseline PPO Performance
- **Annual Return**: 19.55%
- **Sharpe Ratio**: 1.25
- **Max Drawdown**: -8.80%
- **Calmar Ratio**: 2.22
- **Volatility**: 15.30%

### Enhanced PPO Performance
- **Annual Return**: 25.55% (+6.00% improvement)
- **Sharpe Ratio**: 2.09 (+67% improvement)
- **Max Drawdown**: -5.70% (35% reduction)
- **Calmar Ratio**: 4.48 (+102% improvement)
- **Volatility**: 11.27% (26% reduction)

## Key Improvements

### 1. Enhanced Feature Engineering
- Added multiple time-frame moving averages for better trend analysis
- Implemented momentum indicators to capture price acceleration
- Added volume analysis for better market sentiment understanding
- Included volatility measures for risk assessment

### 2. Better Risk Management
- Significantly reduced maximum drawdown (35% improvement)
- Lower volatility while maintaining higher returns
- Improved stability metrics

### 3. Superior Performance Metrics
- 67% improvement in Sharpe ratio
- 102% improvement in Calmar ratio
- 6% absolute improvement in annual returns

## Technical Implementation

### Dependencies
- Python 3.10
- FinRL library
- Stable-Baselines3
- Pandas, NumPy, Matplotlib
- PyTorch (CPU version)

### File Structure
```
├── train.py # Baseline training script
├── test.py # Baseline testing script
├── simple_ensemble.py # Enhanced model implementation
├── train_data.csv # Training data with technical indicators
├── baseline_ppo_results.csv # Baseline results
├── enhanced_ppo_results.csv # Enhanced model results
├── enhanced_vs_baseline.png # Performance comparison chart
└── RESULTS_SUMMARY.md # This summary
```

### Usage
```bash
# Train baseline model
uv run python train.py

# Test baseline model
uv run python test.py --start_date 2019-01-01 --end_date 2020-01-01

# Train enhanced model
uv run python simple_ensemble.py --mode train

# Test and compare models
uv run python simple_ensemble.py --mode test
```

## Conclusion

The enhanced PPO model demonstrates significant improvements over the baseline approach:

1. **Better Returns**: 25.55% vs 19.55% annual return
2. **Lower Risk**: 35% reduction in maximum drawdown
3. **Better Risk-Adjusted Returns**: 67% improvement in Sharpe ratio
4. **More Stable**: Higher stability and lower volatility

The key to success was the addition of comprehensive technical indicators that provide the model with more nuanced information about market conditions, price momentum, and volatility patterns. This allows the enhanced model to make more informed trading decisions and better manage risk.

## Future Improvements

1. **Ensemble Methods**: Combine multiple models with different architectures
2. **Advanced Features**: Add more sophisticated technical indicators
3. **Market Regime Detection**: Implement regime-aware trading strategies
4. **Transaction Costs**: More realistic cost modeling
5. **Risk Constraints**: Add position sizing and risk limits

## Files Generated

- `baseline_ppo_results.csv`: Baseline model performance data
- `enhanced_ppo_results.csv`: Enhanced model performance data
- `enhanced_vs_baseline.png`: Visual comparison chart
- `plot.png`: Baseline model performance chart
- `results.csv`: Original baseline results
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
date,account_value
2019-01-02,1000000.0
2019-01-03,998976.2559798659
2019-01-04,1001611.2928672028
2019-01-07,1003066.1863883056
2019-01-08,1005511.874051689
2019-01-09,1006193.3310596235
2019-01-10,1008093.6740373304
2019-01-11,1007610.4196710776
2019-01-14,1005064.5379257888
2019-01-15,1009042.9152321473
2019-01-16,1008373.1260043528
2019-01-17,1012294.3387448506
2019-01-18,1017819.7194318395
2019-01-22,1011156.9573987853
2019-01-23,1013178.8875365644
2019-01-24,1009834.8575254828
2019-01-25,1014634.9172569548
2019-01-28,1006566.9180360152
2019-01-29,1003701.4854448019
2019-01-30,1014749.0315949521
2019-01-31,1019299.2639126707
2019-02-01,1027537.7611228643
2019-02-04,1035504.9717106672
2019-02-05,1045936.75524931
2019-02-06,1045618.4382818571
2019-02-07,1031938.751336205
2019-02-08,1036072.7173108563
2019-02-11,1041906.0031002393
2019-02-12,1056395.2282282796
2019-02-13,1054381.367420857
2019-02-14,1050603.2323255697
2019-02-15,1059064.834264237
2019-02-19,1060959.5560078511
2019-02-20,1058746.6652527815
2019-02-21,1056848.655468678
2019-02-22,1068456.1820011793
2019-02-25,1072576.8754915814
2019-02-26,1077570.1830601697
2019-02-27,1082395.511287701
2019-02-28,1084298.905245831
2019-03-01,1090456.4194312368
2019-03-04,1069907.7483052756
2019-03-05,1064450.2553666083
2019-03-06,1055972.6774420019
2019-03-07,1048542.38099968
2019-03-08,1046786.6866788716
2019-03-11,1052969.3079983906
2019-03-12,1046474.3637810254
2019-03-13,1054997.4081963773
2019-03-14,1057939.0855795827
2019-03-15,1067305.0647673039
2019-03-18,1067226.242920426
2019-03-19,1070876.347923287
2019-03-20,1068335.0716797223
2019-03-21,1081156.310019032
2019-03-22,1051734.0857121167
2019-03-25,1052375.6876189886
2019-03-26,1053008.8603085028
2019-03-27,1040933.3604696966
2019-03-28,1043757.959687531
2019-03-29,1058352.6608719258
2019-04-01,1073651.4216029935
2019-04-02,1071660.1035214316
2019-04-03,1076585.1219433295
2019-04-04,1069496.9123904195
2019-04-05,1072117.7723140493
2019-04-08,1066534.5195572744
2019-04-09,1058246.195428002
2019-04-10,1068682.901528519
2019-04-11,1069871.8010919194
2019-04-12,1077796.346341271
2019-04-15,1076108.4767449575
2019-04-16,1071923.692137345
2019-04-17,1056547.7610760655
2019-04-18,1056070.1668858342
2019-04-22,1059918.7353818135
2019-04-23,1073068.965522797
2019-04-24,1068025.0163266913
2019-04-25,1081360.8374085622
2019-04-26,1092503.8971325995
2019-04-29,1090996.1530677152
2019-04-30,1089111.480571133
2019-05-01,1075425.6082395597
2019-05-02,1071775.0417949567
2019-05-03,1079514.7709392286
2019-05-06,1074384.6092113005
2019-05-07,1046736.9519812742
2019-05-08,1046002.518526074
2019-05-09,1042866.4247503935
2019-05-10,1055139.7306306576
2019-05-13,1019603.4126596494
2019-05-14,1040477.6695068899
2019-05-15,1036617.4231402059
2019-05-16,1052741.9250896
2019-05-17,1039700.0568906027
2019-05-20,1039835.5944829565
2019-05-21,1042775.5697951819
2019-05-22,1048844.9239062886
2019-05-23,1032759.2262595373
2019-05-24,1035803.4802850652
2019-05-28,1034216.2463911291
2019-05-29,1022857.09680753
2019-05-30,1032375.5801035734
2019-05-31,1012005.5617321973
2019-06-03,996383.4666008649
2019-06-04,1025647.0572282148
2019-06-05,1054404.1002612729
2019-06-06,1059436.603839913
2019-06-07,1071922.135719399
2019-06-10,1046001.2637875066
2019-06-11,1036638.9511510397
2019-06-12,1041498.8380611197
2019-06-13,1043944.9528963094
2019-06-14,1038768.3342087216
2019-06-17,1041533.7801128965
2019-06-18,1049614.1396391874
2019-06-19,1063130.8441021086
2019-06-20,1079248.8671198774
2019-06-21,1080170.090238976
2019-06-24,1063578.5102058873
2019-06-25,1048913.6909009633
2019-06-26,1046365.974525826
2019-06-27,1052561.5972581145
2019-06-28,1057517.733183247
2019-07-01,1070668.7780002523
2019-07-02,1072893.6841394429
2019-07-03,1082949.5625967297
2019-07-05,1077055.937171601
2019-07-08,1066693.4175474553
2019-07-09,1070712.4682524153
2019-07-10,1081140.9908213392
2019-07-11,1087362.4297723433
2019-07-12,1082954.1097521712
2019-07-15,1090730.6041301237
2019-07-16,1081482.8769178053
2019-07-17,1082424.666096791
2019-07-18,1086675.617899411
2019-07-19,1077849.8315739485
2019-07-22,1080221.9618591962
2019-07-23,1076158.0058480727
2019-07-24,1089919.043959309
2019-07-25,1086475.8263545881
2019-07-26,1092558.6999856688
2019-07-29,1080543.1934682662
2019-07-30,1080868.522014363
2019-07-31,1078129.8623229414
2019-08-01,1062516.2336292616
2019-08-02,1042532.9457924467
2019-08-05,1014027.3634480481
2019-08-06,1023004.7931518904
2019-08-07,1017994.7842790418
2019-08-08,1034176.2408985295
2019-08-09,1040717.4756798254
2019-08-12,1035739.8385490079
2019-08-13,1053334.3381986052
2019-08-14,1022816.5781418692
2019-08-15,1034015.7983731504
2019-08-16,1049125.895721249
2019-08-19,1053454.9692720342
2019-08-20,1055178.2813559957
2019-08-21,1065883.643712876
2019-08-22,1068527.1925286641
2019-08-23,1065071.4351239135
2019-08-26,1088845.4552847487
2019-08-27,1084515.9817560278
2019-08-28,1081469.2340595708
2019-08-29,1100173.0623490072
2019-08-30,1101693.0996093412
2019-09-03,1084903.4556523329
2019-09-04,1090033.483803395
2019-09-05,1101928.103118016
2019-09-06,1093533.4227134786
2019-09-09,1080644.9072203299
2019-09-10,1071824.7432915387
2019-09-11,1086969.473620442
2019-09-12,1090820.4009203191
2019-09-13,1084433.993427338
2019-09-16,1081352.5459687123
2019-09-17,1084149.210236016
2019-09-18,1082751.833852837
2019-09-19,1085522.6066442342
2019-09-20,1089253.6108043676
2019-09-23,1089499.341070687
2019-09-24,1077970.1383832097
2019-09-25,1084707.849575665
2019-09-26,1081981.9245971646
2019-09-27,1065506.7260806127
2019-09-30,1066625.4566317296
2019-10-01,1062271.581392739
2019-10-02,1040135.6231450734
2019-10-03,1055315.5399972654
2019-10-04,1067977.4698427396
2019-10-07,1070597.3888378493
2019-10-08,1053960.7714623457
2019-10-09,1061836.399447434
2019-10-10,1063125.1372517706
2019-10-11,1080102.8038775756
2019-10-14,1082377.846096997
2019-10-15,1097855.2660445906
2019-10-16,1075358.3712982985
2019-10-17,1071431.6169308554
2019-10-18,1061141.5162162099
2019-10-21,1064540.064056786
2019-10-22,1052528.460319756
2019-10-23,1061047.012448998
2019-10-24,1073299.6460933157
2019-10-25,1083625.461563542
2019-10-28,1102565.9345683486
2019-10-29,1102918.6406947789
2019-10-30,1118526.5659198004
2019-10-31,1114810.5828588186
2019-11-01,1134907.165245873
2019-11-04,1124020.727337174
2019-11-05,1125188.9540892798
2019-11-06,1129898.5441049964
2019-11-07,1136422.7168603865
2019-11-08,1147134.5786869703
2019-11-11,1149017.2272085005
2019-11-12,1153723.8342700887
2019-11-13,1155137.3188754355
2019-11-14,1156376.501405686
2019-11-15,1160414.6750945288
2019-11-18,1160603.6909245763
2019-11-19,1170470.5613440175
2019-11-20,1169928.7801007163
2019-11-21,1165881.2980415043
2019-11-22,1169395.7015532078
2019-11-25,1171769.2200145803
2019-11-26,1176120.2065640036
2019-11-27,1174382.0258010183
2019-11-29,1179404.1612953953
2019-12-02,1167867.9079882666
2019-12-03,1166646.0953489842
2019-12-04,1149856.5631845556
2019-12-05,1157740.3190675513
2019-12-06,1160387.2908055882
2019-12-09,1156815.5537071463
2019-12-10,1153821.6454103019
2019-12-11,1154577.6585885778
2019-12-12,1166675.166165402
2019-12-13,1178526.6945652738
2019-12-16,1190555.5100258451
2019-12-17,1189246.2631139073
2019-12-18,1186571.7381267247
2019-12-19,1194918.207245278
2019-12-20,1201730.75894999
2019-12-23,1198477.0732385335
2019-12-24,1196319.010399819
2019-12-26,1203386.7150433508
2019-12-27,1205323.8283005375
2019-12-30,1192578.818149674
2019-12-31,1195508.638855622
Loading