main.py
3.46 KB
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
import datetime
import Strategy
import Trading
import Verification
import sys
import DataProvider
def single():
record = [0]
# record = [18.91309, 17.8967, 17.14154, 16.07653, 16.03074]
strategy_record = [[3, 0.7000000000000001, 10, 18.91309], [3, 0.7000000000000001, 11, 17.8967],
[3, 0.8, 11, 17.14154], [4, 0.7000000000000001, 11, 16.07653],
[3, 0.7000000000000001, 5, 16.03074]]
st = Strategy.Strategy()
tr = Trading.Trading()
ve = Verification.Verification()
db = DataProvider.DataProvider()
if db.initialize():
print('db connection')
# print(db.findSP(['StockDate','Open'], '004990', '2019-04-11', '2019-12-31'))
st.db = db
st.setStrategy(10, 0, 1.5, 0)
if (st.searchData() == False):
print("st.searchData error")
sys.exit(-1)
if (st.setAdditionalData() == False):
print("st.setAdditionalData error")
sys.exit(-1)
tr.df_all = st.df_all
tr.db = db
tr.setTrading()
if (tr.doTrading() == False):
print("tr.doTrading error")
sys.exit(-1)
ve.TotalInvestmentAmount = tr.TotalInvestmentAmount
ve.df_all = tr.df_all
ve.setVerification()
ve.doVerification()
ve.saveResult()
# ve.saveResulToJSON()
r, Yield = ve.saveSummary(record, 0)
else:
print("db error")
db.close()
def multi():
start = datetime.datetime.now()
record = [0]
strategy_record = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
num = 0
st = Strategy.Strategy()
tr = Trading.Trading()
ve = Verification.Verification()
db = DataProvider.DataProvider()
for per in range(8):
pbr = 1
while pbr > 0.3:
for roe in range(10, 20):
if db.initialize():
print('db connection')
# print(db.findSP(['StockDate','Open'], '004990', '2019-04-11', '2019-12-31'))
st.db = db
else:
print("db error")
st.setStrategy(per, pbr, 1.2, roe)
if (st.searchData() == False):
print("st.searchData error")
sys.exit(-1)
if (st.setAdditionalData() == False):
print("st.setAdditionalData error")
sys.exit(-1)
tr.df_all = st.df_all
tr.db = db
tr.setTrading()
if (tr.doTrading() == False):
print("tr.doTrading error")
sys.exit(-1)
ve.TotalInvestmentAmount = tr.TotalInvestmentAmount
ve.df_all = tr.df_all
ve.setVerification()
ve.doVerification()
ve.saveResult()
# ve.saveResulToJSON()
r, Yield = ve.saveSummary(record, num)
if r:
for i in range(5):
if strategy_record[i][3] < Yield:
strategy_record.insert(i, [per, pbr, roe, Yield])
break
strategy_record.pop()
print(record, strategy_record)
num += 1
pbr -= 0.1
db.close()
end = datetime.datetime.now()
print('time: ', end - start)
print(strategy_record)
if __name__ == '__main__':
single()
# multi()