- forecast.py 数据处理、可视化、模型调用
- myutils.py 数据处理工具
- models.py 模型定义
- AMZN.csv 时间序列预测使用的数据集,为2010.01-2022.06的Amazon 股价变化情况,来自Kaggle
- backtest.py 回测
- draw_line.py 回测结果展示,backtest.py中自动调用
- 各月股票队列.xlsx 回测时使用的股票队列,日期范围为2020.04-2020.12,来自参考项目2
- 个股持有情况分析.xlsx 回测结果文件
- 持有期收益率情况图.html 回测结果图,需要pyecharts打开
- 每日资金情况图.html 回测结果图,需要pyecharts打开
需要python3.8,其他依赖使用pip install -r requirements.txt
命令安装
-
时间序列预测
运行命令python forecast.py --model $modelname
运行时将$modelname
替换为下面9种模型名称之一:linearRegression
DeterministProcess
RelativeStrengthIndex
ARIMA
DecisionTree
KNN
LSTM
Prophet
SVM
-
回测
运行命令python backtest.py
linearRegression:
Model train accuracy: 99.923%
Model test accuracy: 98.442%
Model train MAE: 0.424
Model train RMSE: 0.800
Model test MAE: 2.338
Model test RMSE: 3.252
DeterministProcess
Model train accuracy: 99.923%
Model test accuracy: 98.443%
Model train MAE: 0.425
Model train RMSE: 0.799
Model test MAE: 2.339
Model test RMSE: 3.251
ARIMA
Best model: ARIMA(0,1,0)(2,1,0)[12]
Total fit time: 47.517 seconds
Model test MAE: 73.689
Model test RMSE: 80.137
KNN
Model test MAE: 47.711
Model test RMSE: 53.677
LSTM
Model test MAE: 4.349
Model test RMSE: 5.701
Prophet
Model test MAE: 39.901
Model test RMSE: 44.794
SVM
accuracy=52.31%
DecisionTree
train accuracy: 0.550400
test accuracy: 0.476266
roc: 0.500000
RelativeStrengthIndex
{'超买市场(RSI>=80)且实际下跌': 131, '超买市场(RSI>=80)但实际上涨': 127, '强势市场(50<=RSI<80)且实际下跌': 760, '强势市场(50<=RSI<80)但实际上涨': 858, '弱式市场(50>RSI>=20)且实际上涨': 640, '弱式市场(50>RSI>=20)但实际下跌': 547, '超卖市场(RSI<20)且实际上涨': 32, '超卖市场(RSI<20)但实际下跌': 22}
Model | MAE | RMSE |
---|---|---|
linearRegression | 2.338 | 3.252 |
DeterministProcess | 2.339 | 3.251 |
ARIMA | 73.689 | 80.137 |
KNN | 47.711 | 53.677 |
LSTM | 4.349 | 5.701 |
Prophet | 39.901 | 44.794 |