forked from ailabx/ailabx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (40 loc) · 1.29 KB
/
main.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
'''
@author: 魏佳斌
@license: (C) Copyright 2018-2025, ailabx.com.
@contact: [email protected]
@file: main.py
@time: 2018-10-22 17:46
@desc:
'''
import os
from quant.engine.trading_env import TradingEnv
from quant.engine.datafeed import DataFeed
from quant.engine.algos import *
def main():
path = os.path.abspath(os.path.join(os.getcwd(), "quant/data"))
feed = DataFeed(data_path=path)
feed.download_or_get_data(['AAPL', ], 2006, 2006)
buy_and_hold = Strategy([
RunOnce(),
PrintBar(),
SelectAll(),
WeighEqually(),
], name='买入并持有-基准策略')
long_expr = 'cross_up(ma(close,5),ma(close,10))'
flat_expr = 'cross_down(ma(close,5),ma(close,10))'
ma_cross = Strategy([
SelectByExpr(long_expr=long_expr, flat_expr=flat_expr),
WeighEqually(),
], name='均线交叉策略')
env_benchmark = TradingEnv(strategy=buy_and_hold, feed=feed)
env_benchmark.run_strategy()
env = TradingEnv(strategy=ma_cross, feed=feed)
env.run_strategy()
bench_stats = env_benchmark.get_statistics()
stra_stats = env.get_statistics()
stats = [bench_stats, stra_stats]
from quant.engine.trading_env import EnvUtils
utils = EnvUtils(stats=stats)
utils.show_stats()
if __name__ == '__main__':
main()