-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunRQ.py
123 lines (121 loc) · 5.03 KB
/
RunRQ.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from rqalpha import run_file
import os
from Test import find_model
from ta.momentum import *
from ta.volatility import *
from ta.trend import *
from ta.volume import *
from ta.others import *
from Util.Util import post_processor
indicators = [
('RSI', rsi, ['close']),
('MFI', money_flow_index, ['high', 'low', 'close', 'volume']),
('TSI', tsi, ['close']),
('UO', uo, ['high', 'low', 'close']),
('AO', ao, ['high', 'close']),
('MACDDI', macd_diff, ['close']),
('VIP', vortex_indicator_pos, ['high', 'low', 'close']),
('VIN', vortex_indicator_neg, ['high', 'low', 'close']),
('TRIX', trix, ['close']),
('MI', mass_index, ['high', 'low']),
('CCI', cci, ['high', 'low', 'close']),
('DPO', dpo, ['close']),
# ('KST', kst, ['close']),
# ('KSTS', kst_sig, ['close']),
('ARU', aroon_up, ['close']),
('ARD', aroon_down, ['close']),
# ('ARI', diff, ['ARU', 'ARD']),
('BBH', bollinger_hband, ['close']),
('BBL', bollinger_lband, ['close']),
('BBM', bollinger_mavg, ['close']),
# ('BBHI', bollinger_hband_indicator, ['close']),
# ('BBLI', bollinger_lband_indicator, ['close']),
# ('KCHI', keltner_channel_hband_indicator, ['high', 'low', 'close']),
# ('KCLI', keltner_channel_lband_indicator, ['high', 'low', 'close']),
# ('DCHI', donchian_channel_hband_indicator, ['close']),
# ('DCLI', donchian_channel_lband_indicator, ['close']),
# ('ADI', acc_dist_index, ['high', 'low', 'close', 'volume']),
# ('OBV', on_balance_volume, ['close', 'volume']),
('CMF', chaikin_money_flow, ['high', 'low', 'close', 'volume']),
# ('FI', force_index, ['close', 'volume']),
# ('EM', ease_of_movement, ['high', 'low', 'close', 'volume']),
# ('VPT', volume_price_trend, ['close', 'volume']),
# ('NVI', negative_volume_index, ['close', 'volume']),
('DR', daily_return, ['close']),
('DLR', daily_log_return, ['close'])
]
skip_suspended = True
id = "oalhl2pz"
type = "last"
path = './RQStrategyTest.py'
config = {
"base": {
"start_date": "2017-01-03",
"end_date": "2020-04-21",
"frequency": "1d",
"accounts": {
"stock": 1e5
},
},
"extra": {
"log_level": "verbose",
},
"mod": {
"sys_analyser": {
"enabled": True,
"plot": True
},
"sys_accounts": {
"enabled": True,
# 开启/关闭 股票 T+1, 默认开启
"stock_t1": True,
# 分红再投资
"dividend_reinvestment": False,
# 当持仓股票退市时,按照退市价格返还现金
"cash_return_by_stock_delisted": True,
# 股票下单因资金不足被拒时改为使用全部剩余资金下单
"auto_switch_order_value": True,
# 检查股票可平仓位是否充足
"validate_stock_position": True,
# 检查期货可平仓位是否充足
"validate_future_position": True,
},
"sys_simulation": {
"enabled": True,
"slippage": 0.0,
"matching_type": "next_bar",
}
}
}
if __name__ == '__main__':
folder_name, _, max_file_name = find_model(id, type)
import yaml
with open(os.path.join('./wandb', folder_name, 'config.yaml'), 'r') as f:
conf = f.read()
conf = yaml.load(conf)
conf['agent_config'] = conf['agent_config']['value']
conf['train_env_config'] = conf['train_env_config']['value']
conf['eval_env_config'] = conf['eval_env_config']['value']
if conf['train_env_config']['post_processor'] == 'post_processor':
conf['train_env_config']['post_processor'] = post_processor
else:
raise Exception("train_env_config:post_processor为不支持的类型{}".format(conf['train_env_config']['post_processor']))
if conf['eval_env_config']['post_processor'] == 'post_processor':
conf['eval_env_config']['post_processor'] = post_processor
else:
raise Exception("eval_env_config:post_processor为不支持的类型{}".format(conf['eval_env_config']['post_processor']))
globals().update(conf)
globals().update(conf['agent_config'])
for stock_code in conf['train_env_config']['stock_codes']:
stock_code = stock_code.replace("_", ".")
config['base']['benchmark'] = stock_code
plot_save_path = os.path.join(os.getcwd(), 'TestResult', folder_name, 'RQTest', max_file_name,
stock_code + ".png")
file_save_path = os.path.join(os.getcwd(), 'TestResult', folder_name, 'RQTest', max_file_name,
stock_code + ".pkl")
if not os.path.exists(os.path.join(os.getcwd(), 'TestResult', folder_name, 'RQTest', max_file_name, )):
os.makedirs(os.path.join(os.getcwd(), 'TestResult', folder_name, 'RQTest', max_file_name, ))
config['base']['stock_code'] = stock_code
config['mod']['sys_analyser']['plot_save_file'] = plot_save_path
config['mod']['sys_analyser']['output_file'] = file_save_path
run_file(path, config)