-
Notifications
You must be signed in to change notification settings - Fork 4
/
inv_normal.py
95 lines (88 loc) · 6.8 KB
/
inv_normal.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
key = {'time': ['2022-04-18', '2022-04-19', '2022-04-20', '2022-04-21', '2022-04-22', '2022-04-25', '2022-04-26',
'2022-04-27', '2022-04-28', '2022-04-29', '2022-05-05', '2022-05-06', '2022-05-09', '2022-05-10',
'2022-05-11', '2022-05-12', '2022-05-13', '2022-05-16', '2022-05-17', '2022-05-18', '2022-05-19',
'2022-05-20', '2022-05-23', '2022-05-24', '2022-05-25', '2022-05-26', '2022-05-27', '2022-05-30',
'2022-05-31', '2022-06-01', '2022-06-02', '2022-06-06', '2022-06-07', '2022-06-08', '2022-06-09',
'2022-06-10', '2022-06-13', '2022-06-14', '2022-06-15', '2022-06-16', '2022-06-17', '2022-06-20',
'2022-06-21', '2022-06-22', '2022-06-23', '2022-06-24', '2022-06-27', '2022-06-28', '2022-06-29',
'2022-06-30', '2022-07-01', '2022-07-04', '2022-07-05', '2022-07-06', '2022-07-07', '2022-07-08',
'2022-07-11', '2022-07-12', '2022-07-13', '2022-07-14', '2022-07-15', '2022-07-18', '2022-07-19',
'2022-07-20', '2022-07-21', '2022-07-22', '2022-07-25', '2022-07-26', '2022-07-27', '2022-07-28',
'2022-07-29', '2022-08-01', '2022-08-02', '2022-08-03', '2022-08-04', '2022-08-05', '2022-08-08',
'2022-08-09', '2022-08-10', '2022-08-11', '2022-08-12', '2022-08-15', '2022-08-16', '2022-08-17',
'2022-08-18', '2022-08-19', '2022-08-22', '2022-08-23', '2022-08-24', '2022-08-25', '2022-08-26',
'2022-08-29', '2022-08-30', '2022-08-31', '2022-09-01', '2022-09-02', '2022-09-05', '2022-09-06',
'2022-09-07', '2022-09-08', '2022-09-09', '2022-09-13', '2022-09-14', '2022-09-15', '2022-09-16',
'2022-09-19', '2022-09-20', '2022-09-21', '2022-09-22', '2022-09-23', '2022-09-26', '2022-09-27',
'2022-09-28', '2022-09-29', '2022-09-30', '2022-10-10', '2022-10-11', '2022-10-12', '2022-10-13',
'2022-10-14', '2022-10-17', '2022-10-18', '2022-10-19', '2022-10-20', '2022-10-21', '2022-10-24',
'2022-10-25', '2022-10-26', '2022-10-27', '2022-10-28', '2022-10-31', '2022-11-01', '2022-11-02',
'2022-11-03', '2022-11-04', '2022-11-07', '2022-11-08', '2022-11-09', '2022-11-10', '2022-11-11',
'2022-11-14', '2022-11-15', '2022-11-16', '2022-11-17', '2022-11-18', '2022-11-21', '2022-11-22',
'2022-11-23', '2022-11-24', '2022-11-25', '2022-11-28', '2022-11-29', '2022-11-30', '2022-12-01',
'2022-12-02', '2022-12-05', '2022-12-06', '2022-12-07', '2022-12-08', '2022-12-09', '2022-12-12',
'2022-12-13', '2022-12-14', '2022-12-15', '2022-12-16', '2022-12-19', '2022-12-20', '2022-12-21',
'2022-12-22', '2022-12-23', '2022-12-26', '2022-12-27', '2022-12-28', '2022-12-29', '2022-12-30',
'2022-12-31', '2023-01-03', '2023-01-04', '2023-01-05', '2023-01-06', '2023-01-09', '2023-01-10',
'2023-01-11', '2023-01-12', '2023-01-13', '2023-01-16', '2023-01-17', '2023-01-18', '2023-01-19',
'2023-01-20', '2023-01-30', '2023-01-31', '2023-02-01', '2023-02-02', '2023-02-03', '2023-02-06',
'2023-02-07', '2023-02-08', '2023-02-09', '2023-02-10'],
'price': ['2.7069', '2.7104', '2.6328', '2.5407', '2.5710', '2.4306', '2.4039', '2.5462', '2.5756', '2.6429',
'2.6177', '2.5446', '2.5498', '2.6147', '2.6994', '2.6806', '2.7312', '2.7152', '2.7762', '2.8411',
'2.8698', '2.9007', '2.8973', '2.7971', '2.8185', '2.8132', '2.8030', '2.8417', '2.9404', '2.9688',
'3.0149', '3.0890', '3.0664', '3.0721', '3.0223', '3.0854', '3.0677', '3.0989', '3.0683', '3.0524',
'3.1047', '3.1812', '3.1520', '3.1462', '3.2424', '3.2923', '3.2736', '3.3288', '3.1922', '3.2620',
'3.2321', '3.2775', '3.2760', '3.3101', '3.4179', '3.3542', '3.2806', '3.2149', '3.2564', '3.3124',
'3.2904', '3.3054', '3.2556', '3.2584', '3.2142', '3.2151', '3.1542', '3.1886', '3.2297', '3.2197',
'3.1979', '3.2050', '3.1252', '3.0526', '3.0546', '3.0661', '3.0868', '3.1019', '3.0734', '3.0908',
'3.0887', '3.1940', '3.2630', '3.3190', '3.3407', '3.3310', '3.3346', '3.3722', '3.2323', '3.2302',
'3.1651', '3.1866', '3.1721', '3.0506', '3.0310', '3.0414', '3.0545', '3.1294', '3.1802', '3.1927',
'3.1675', '3.1046', '3.0539', '2.8977', '2.8431', '2.8404', '2.8815', '2.8637', '2.8666', '2.8032',
'2.8377', '2.8514', '2.7591', '2.7242', '2.6665', '2.6060', '2.6817', '2.7328', '2.7578', '2.7999',
'2.7732', '2.8168', '2.8066', '2.7229', '2.7613', '2.6721', '2.7168', '2.7478', '2.6584', '2.5033',
'2.4837', '2.5625', '2.5895', '2.6266', '2.7721', '2.7863', '2.7685', '2.7437', '2.6756', '2.7306',
'2.6992', '2.7433', '2.7095', '2.6798', '2.6807', '2.7098', '2.6667', '2.7282', '2.7394', '2.6960',
'2.6964', '2.7018', '2.7155', '2.7140', '2.6835', '2.7002', '2.7012', '2.6877', '2.6940', '2.7061',
'2.6614', '2.6267', '2.6217', '2.6569', '2.6415', '2.6140', '2.5787', '2.5538', '2.5163', '2.4866',
'2.5512', '2.5699', '2.6828', '2.6916', '2.6972', '2.6971', '2.7765', '2.7742', '2.8056', '2.8964',
'2.8627', '2.8829', '2.8336', '2.8539', '2.8356', '2.8594', '2.8350', '2.8659', '2.8573', '2.8908',
'2.8755', '2.9068', '2.9361', '2.9410', '2.9088', '2.8678', '2.9244', '2.9345', '2.9568', '2.9457']}
# 按照不同的类型计算收益率
def cal_income_per_flag(value, money, flag):
total_stock = 0
total_amount = 0
times = 0
for i in range(len(value) - 1):
times += 1
if flag == 'day':
total_stock += int(money) / float(value[i])
total_amount += int(money)
elif flag == 'week':
if times % 7 == 0:
total_stock += int(money) / float(value[i])
total_amount += int(money)
elif flag == 'month':
if times % 20 == 0:
total_stock += int(money) / float(value[i])
total_amount += int(money)
total = total_stock * float(value[len(value) - 1])
data = {
'total': total,
'total_amount': total_amount,
'per': '{:.2f}'.format((total / total_amount - 1) * 100)
}
return data
# 返回规范化的数据
def invest(key, money):
value = key['price']
day = cal_income_per_flag(value, money, 'day')
week = cal_income_per_flag(value, money, 'week')
month = cal_income_per_flag(value, money, 'month')
a = [day['total'], week['total'], month['total']]
b = [day['total_amount'], week['total_amount'], month['total_amount']]
c = [day['per'], week['per'], month['per']]
return {
'data1': a,
'data2': b,
'data3': c
}