mns-scheduler 1.0.6.8__py3-none-any.whl → 1.0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mns-scheduler might be problematic. Click here for more details.
- mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +4 -3
- mns_scheduler/irm/stock_irm_cninfo_service.py +20 -2
- mns_scheduler/k_line/clean/daily/__init__.py +7 -0
- mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +434 -0
- mns_scheduler/k_line/clean/daily/daily_k_line_service.py +109 -0
- mns_scheduler/k_line/clean/k_line_info_clean_impl.py +7 -496
- mns_scheduler/k_line/clean/{k_line_info_clean_service.py → k_line_info_clean_task.py} +6 -1
- mns_scheduler/k_line/clean/week_month/__init__.py +7 -0
- mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +117 -0
- mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +47 -0
- mns_scheduler/k_line/hot_stocks/__init__.py +7 -0
- mns_scheduler/zz_task/data_sync_task.py +1 -1
- {mns_scheduler-1.0.6.8.dist-info → mns_scheduler-1.0.7.1.dist-info}/METADATA +1 -1
- {mns_scheduler-1.0.6.8.dist-info → mns_scheduler-1.0.7.1.dist-info}/RECORD +17 -10
- /mns_scheduler/k_line/{clean → hot_stocks}/recent_hot_stocks_clean_service.py +0 -0
- {mns_scheduler-1.0.6.8.dist-info → mns_scheduler-1.0.7.1.dist-info}/WHEEL +0 -0
- {mns_scheduler-1.0.6.8.dist-info → mns_scheduler-1.0.7.1.dist-info}/top_level.txt +0 -0
|
@@ -6,21 +6,13 @@ end = file_path.index('mns') + 17
|
|
|
6
6
|
project_path = file_path[0:end]
|
|
7
7
|
sys.path.append(project_path)
|
|
8
8
|
|
|
9
|
-
import mns_common.utils.data_frame_util as data_frame_util
|
|
10
9
|
import pandas as pd
|
|
11
10
|
from mns_common.db.MongodbUtil import MongodbUtil
|
|
12
|
-
import mns_common.utils.date_handle_util as date_handle_util
|
|
13
|
-
import mns_common.component.k_line.patterns.k_line_patterns_service_api as k_line_patterns_service
|
|
14
|
-
import mns_common.component.k_line.clean.sh_small_normal_zt_k_line_check_api as sh_small_normal_zt_k_line_check_api
|
|
15
|
-
import mns_common.component.classify.symbol_classify_api as symbol_classify_api
|
|
16
11
|
import mns_common.component.k_line.common.k_line_common_service_api as k_line_common_service_api
|
|
17
|
-
import mns_scheduler.k_line.clean.
|
|
12
|
+
import mns_scheduler.k_line.clean.week_month.normal_week_month_k_line_service as week_month_k_line_service
|
|
13
|
+
import mns_scheduler.k_line.clean.daily.daily_k_line_service as daily_k_line_service
|
|
18
14
|
|
|
19
15
|
mongodb_util = MongodbUtil('27017')
|
|
20
|
-
# 排除最近10天有三个连板的股票
|
|
21
|
-
EXCLUDE_DAYS = 10
|
|
22
|
-
|
|
23
|
-
MAX_CONTINUE_BOARDS = 3
|
|
24
16
|
|
|
25
17
|
|
|
26
18
|
# 日线 周线 月线 成交量 筹码信息
|
|
@@ -32,491 +24,10 @@ def calculate_k_line_info(str_day, symbol, diff_days):
|
|
|
32
24
|
'symbol',
|
|
33
25
|
'diff_days'
|
|
34
26
|
])
|
|
35
|
-
|
|
36
|
-
k_line_info = handle_week_line(k_line_info, str_day, symbol)
|
|
37
|
-
k_line_info = handle_day_line(k_line_info, str_day, symbol)
|
|
38
|
-
return k_line_info
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# 处理月线
|
|
42
|
-
def handle_month_line(k_line_info, str_day, symbol):
|
|
43
|
-
month_begin_day = str_day[0:7] + '-01'
|
|
44
|
-
query = {"symbol": symbol,
|
|
45
|
-
'date': {"$lt": date_handle_util.no_slash_date(month_begin_day)}}
|
|
46
|
-
stock_hfq_monthly = mongodb_util.descend_query(query, 'stock_qfq_monthly', 'date', 2)
|
|
47
|
-
month_num = stock_hfq_monthly.shape[0]
|
|
48
|
-
k_line_info['month_num'] = month_num
|
|
49
|
-
if month_num > 0:
|
|
50
|
-
k_line_info['sum_month'] = round(sum(stock_hfq_monthly['chg']), 2)
|
|
51
|
-
else:
|
|
52
|
-
k_line_info['sum_month'] = 0
|
|
53
|
-
|
|
54
|
-
if month_num == 0:
|
|
55
|
-
k_line_info['month01'] = 0
|
|
56
|
-
k_line_info['month02'] = 0
|
|
57
|
-
k_line_info['month01_date'] = '19890729'
|
|
58
|
-
k_line_info['month02_date'] = '19890729'
|
|
59
|
-
elif month_num == 1:
|
|
60
|
-
k_line_info['month01'] = stock_hfq_monthly.iloc[0].chg
|
|
61
|
-
k_line_info['month02'] = 0
|
|
62
|
-
k_line_info['month01_date'] = stock_hfq_monthly.iloc[0].date
|
|
63
|
-
k_line_info['month02_date'] = '19890729'
|
|
64
|
-
elif month_num == 2:
|
|
65
|
-
k_line_info['month01'] = stock_hfq_monthly.iloc[0].chg
|
|
66
|
-
k_line_info['month02'] = stock_hfq_monthly.iloc[1].chg
|
|
67
|
-
k_line_info['month01_date'] = stock_hfq_monthly.iloc[0].date
|
|
68
|
-
k_line_info['month02_date'] = stock_hfq_monthly.iloc[1].date
|
|
69
|
-
|
|
70
|
-
return k_line_info
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
# 处理周线
|
|
74
|
-
def handle_week_line(k_line_info, str_day, symbol):
|
|
75
|
-
month_begin_day = str_day[0:7] + '-01'
|
|
76
|
-
query = {"symbol": symbol,
|
|
77
|
-
'$and': [{'date': {"$gte": date_handle_util.no_slash_date(month_begin_day)}},
|
|
78
|
-
{'date': {"$lt": date_handle_util.no_slash_date(str_day)}}]}
|
|
79
|
-
stock_hfq_weekly = mongodb_util.find_query_data('stock_qfq_weekly', query)
|
|
80
|
-
week_num = stock_hfq_weekly.shape[0]
|
|
81
|
-
if week_num > 0:
|
|
82
|
-
stock_hfq_weekly = stock_hfq_weekly.sort_values(by=['date'], ascending=False)
|
|
83
|
-
k_line_info['sum_week'] = round(sum(stock_hfq_weekly['chg']), 2)
|
|
84
|
-
else:
|
|
85
|
-
k_line_info['sum_week'] = 0
|
|
86
|
-
k_line_info['week_num'] = week_num
|
|
87
|
-
if week_num == 1:
|
|
88
|
-
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
89
|
-
k_line_info['week02'] = 0
|
|
90
|
-
k_line_info['week03'] = 0
|
|
91
|
-
k_line_info['week04'] = 0
|
|
92
|
-
elif week_num == 2:
|
|
93
|
-
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
94
|
-
k_line_info['week02'] = stock_hfq_weekly.iloc[1].chg
|
|
95
|
-
k_line_info['week03'] = 0
|
|
96
|
-
k_line_info['week04'] = 0
|
|
97
|
-
elif week_num == 3:
|
|
98
|
-
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
99
|
-
k_line_info['week02'] = stock_hfq_weekly.iloc[1].chg
|
|
100
|
-
k_line_info['week03'] = stock_hfq_weekly.iloc[2].chg
|
|
101
|
-
k_line_info['week04'] = 0
|
|
102
|
-
elif week_num >= 4:
|
|
103
|
-
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
104
|
-
k_line_info['week02'] = stock_hfq_weekly.iloc[1].chg
|
|
105
|
-
k_line_info['week03'] = stock_hfq_weekly.iloc[2].chg
|
|
106
|
-
k_line_info['week04'] = stock_hfq_weekly.iloc[3].chg
|
|
107
|
-
elif week_num == 0:
|
|
108
|
-
k_line_info['week01'] = 0
|
|
109
|
-
k_line_info['week02'] = 0
|
|
110
|
-
k_line_info['week03'] = 0
|
|
111
|
-
k_line_info['week04'] = 0
|
|
112
|
-
k_line_info['week_last_day'] = month_begin_day
|
|
113
|
-
k_line_info['sum_week'] = 0
|
|
114
|
-
return k_line_info
|
|
115
|
-
stock_hfq_weekly = stock_hfq_weekly.sort_values(by=['date'], ascending=False)
|
|
116
|
-
stock_hfq_weekly_last = stock_hfq_weekly.iloc[0:1]
|
|
117
|
-
k_line_info['week_last_day'] = list(stock_hfq_weekly_last['date'])[0]
|
|
118
|
-
|
|
119
|
-
return k_line_info
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# 处理日线
|
|
123
|
-
def handle_day_line(k_line_info, str_day, symbol):
|
|
27
|
+
# 交易天数
|
|
124
28
|
deal_days = k_line_common_service_api.get_deal_days(str_day, symbol)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
#
|
|
128
|
-
|
|
129
|
-
stock_qfq_daily = mongodb_util.descend_query(query, 'stock_qfq_daily', 'date', 60)
|
|
130
|
-
if stock_qfq_daily.shape[0] == 0:
|
|
131
|
-
return k_line_info
|
|
132
|
-
k_line_info = init_day_line_data(k_line_info, stock_qfq_daily)
|
|
133
|
-
k_line_info = calculate_30_day_max_chg(stock_qfq_daily, k_line_info)
|
|
134
|
-
|
|
135
|
-
stock_qfq_daily = calculate_exchange_avg_param(stock_qfq_daily)
|
|
136
|
-
stock_qfq_daily_one = stock_qfq_daily.iloc[0:1]
|
|
137
|
-
stock_qfq_daily_one = set_k_line_patterns(stock_qfq_daily_one.copy())
|
|
138
|
-
stock_qfq_daily_one = set_history_list(stock_qfq_daily_one.copy(), stock_qfq_daily.copy())
|
|
139
|
-
k_line_info = k_line_field_fix(k_line_info.copy(), stock_qfq_daily_one.copy())
|
|
140
|
-
|
|
141
|
-
k_line_info.loc[:, 'deal_days'] = deal_days
|
|
142
|
-
|
|
143
|
-
k_line_info.loc[k_line_info['deal_days'] > 5, 'sum_five_chg'] = k_line_info['daily01'] \
|
|
144
|
-
+ k_line_info['daily02'] \
|
|
145
|
-
+ k_line_info['daily03'] \
|
|
146
|
-
+ k_line_info['daily04'] \
|
|
147
|
-
+ k_line_info['daily05']
|
|
148
|
-
k_line_info.loc[k_line_info['deal_days'] <= 5, 'sum_five_chg'] = 0
|
|
149
|
-
|
|
150
|
-
# 计算开盘涨幅
|
|
151
|
-
k_line_info = calculate_open_chg(stock_qfq_daily, k_line_info)
|
|
152
|
-
# 排除最近有三板以上的股票
|
|
153
|
-
k_line_info = check_recent_zt_stock(str_day, k_line_info)
|
|
154
|
-
# 计算 昨日最高点到开盘涨幅差值 and # 昨日最高点到当日收盘涨幅之间的差值
|
|
155
|
-
k_line_info = calculate_chg_diff_value(k_line_info)
|
|
156
|
-
|
|
157
|
-
recent_hot_stocks_clean_service.calculate_recent_hot_stocks(stock_qfq_daily, symbol, str_day)
|
|
158
|
-
|
|
159
|
-
return k_line_info
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
# 计算涨幅差值
|
|
163
|
-
def calculate_chg_diff_value(result):
|
|
164
|
-
# 昨日最高点到开盘涨幅差值
|
|
165
|
-
result['diff_chg_from_open_last'] = round(
|
|
166
|
-
result['max_chg_last'] - result['open_chg_last'], 2)
|
|
167
|
-
|
|
168
|
-
# 昨日最高点到当日收盘涨幅之间的差值
|
|
169
|
-
result['diff_chg_high_last'] = round(
|
|
170
|
-
result['max_chg_last'] - result['chg_last'], 2)
|
|
171
|
-
|
|
172
|
-
return result
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
def init_day_line_data(k_line_info, stock_qfq_daily):
|
|
176
|
-
daily_num = stock_qfq_daily.shape[0]
|
|
177
|
-
if daily_num == 0:
|
|
178
|
-
k_line_info['max_chg_daily01'] = 0
|
|
179
|
-
k_line_info['daily01'] = 0
|
|
180
|
-
k_line_info['daily02'] = 0
|
|
181
|
-
k_line_info['daily03'] = 0
|
|
182
|
-
k_line_info['daily04'] = 0
|
|
183
|
-
k_line_info['daily05'] = 0
|
|
184
|
-
elif daily_num == 1:
|
|
185
|
-
k_line_info['max_chg_daily01'] = stock_qfq_daily.iloc[0].max_chg
|
|
186
|
-
k_line_info['daily01'] = stock_qfq_daily.iloc[0].chg
|
|
187
|
-
k_line_info['daily02'] = 0
|
|
188
|
-
k_line_info['daily03'] = 0
|
|
189
|
-
k_line_info['daily04'] = 0
|
|
190
|
-
k_line_info['daily05'] = 0
|
|
191
|
-
elif daily_num == 2:
|
|
192
|
-
k_line_info['max_chg_daily01'] = stock_qfq_daily.iloc[0].max_chg
|
|
193
|
-
k_line_info['daily01'] = stock_qfq_daily.iloc[0].chg
|
|
194
|
-
k_line_info['daily02'] = stock_qfq_daily.iloc[1].chg
|
|
195
|
-
k_line_info['daily03'] = 0
|
|
196
|
-
k_line_info['daily04'] = 0
|
|
197
|
-
k_line_info['daily05'] = 0
|
|
198
|
-
elif daily_num == 3:
|
|
199
|
-
k_line_info['max_chg_daily01'] = stock_qfq_daily.iloc[0].max_chg
|
|
200
|
-
k_line_info['daily01'] = stock_qfq_daily.iloc[0].chg
|
|
201
|
-
k_line_info['daily02'] = stock_qfq_daily.iloc[1].chg
|
|
202
|
-
k_line_info['daily03'] = stock_qfq_daily.iloc[2].chg
|
|
203
|
-
k_line_info['daily04'] = 0
|
|
204
|
-
k_line_info['daily05'] = 0
|
|
205
|
-
elif daily_num == 4:
|
|
206
|
-
k_line_info['max_chg_daily01'] = stock_qfq_daily.iloc[0].max_chg
|
|
207
|
-
k_line_info['daily01'] = stock_qfq_daily.iloc[0].chg
|
|
208
|
-
k_line_info['daily02'] = stock_qfq_daily.iloc[1].chg
|
|
209
|
-
k_line_info['daily03'] = stock_qfq_daily.iloc[2].chg
|
|
210
|
-
k_line_info['daily04'] = stock_qfq_daily.iloc[3].chg
|
|
211
|
-
k_line_info['daily05'] = 0
|
|
212
|
-
elif daily_num >= 5:
|
|
213
|
-
k_line_info['max_chg_daily01'] = stock_qfq_daily.iloc[0].max_chg
|
|
214
|
-
k_line_info['daily01'] = stock_qfq_daily.iloc[0].chg
|
|
215
|
-
k_line_info['daily02'] = stock_qfq_daily.iloc[1].chg
|
|
216
|
-
k_line_info['daily03'] = stock_qfq_daily.iloc[2].chg
|
|
217
|
-
k_line_info['daily04'] = stock_qfq_daily.iloc[3].chg
|
|
218
|
-
k_line_info['daily05'] = stock_qfq_daily.iloc[4].chg
|
|
219
|
-
|
|
220
|
-
return k_line_info
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
# 计算30天最大涨幅
|
|
224
|
-
def calculate_30_day_max_chg(stock_qfq_daily, k_line_info):
|
|
225
|
-
stock_qfq_daily_30 = stock_qfq_daily.iloc[0:29]
|
|
226
|
-
|
|
227
|
-
deal_days = stock_qfq_daily_30.shape[0]
|
|
228
|
-
|
|
229
|
-
if stock_qfq_daily_30.shape[0] < 30:
|
|
230
|
-
stock_qfq_daily_30 = stock_qfq_daily_30[0: deal_days - 1]
|
|
231
|
-
if stock_qfq_daily_30.shape[0] == 0:
|
|
232
|
-
k_line_info['max_chg_30'] = 0
|
|
233
|
-
return k_line_info
|
|
234
|
-
|
|
235
|
-
stock_qfq_daily_30['date_time'] = pd.to_datetime(stock_qfq_daily_30['date'])
|
|
236
|
-
# 找出最高点和最低点的行
|
|
237
|
-
max_row = stock_qfq_daily_30[stock_qfq_daily_30['high'] == stock_qfq_daily_30['high'].max()]
|
|
238
|
-
min_row = stock_qfq_daily_30[stock_qfq_daily_30['low'] == stock_qfq_daily_30['low'].min()]
|
|
239
|
-
|
|
240
|
-
# 获取最高点和最低点的值以及对应的日期
|
|
241
|
-
max_high = max_row['high'].values[0]
|
|
242
|
-
min_low = min_row['low'].values[0]
|
|
243
|
-
date_of_max_high = max_row['date_time'].values[0]
|
|
244
|
-
date_of_min_low = min_row['date_time'].values[0]
|
|
245
|
-
max_chg_30 = round((max_high - min_low) * 100 / min_low, 2)
|
|
246
|
-
if date_of_max_high < date_of_min_low:
|
|
247
|
-
max_chg_30 = -max_chg_30
|
|
248
|
-
k_line_info['max_chg_30'] = max_chg_30
|
|
249
|
-
return k_line_info
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
# 计算平均值
|
|
253
|
-
def calculate_exchange_avg_param(stock_qfq_daily):
|
|
254
|
-
stock_qfq_daily = stock_qfq_daily.sort_values(by=['date'], ascending=True)
|
|
255
|
-
|
|
256
|
-
# exchange
|
|
257
|
-
# 计算每个日期的前10天的均值
|
|
258
|
-
stock_qfq_daily['exchange_mean'] = round(
|
|
259
|
-
stock_qfq_daily['exchange'].rolling(window=10, min_periods=1).mean(), 2)
|
|
260
|
-
|
|
261
|
-
# stock_qfq_daily['exchange_mean_ewm'] = round(
|
|
262
|
-
# stock_qfq_daily['exchange'].ewm(span=10).mean(), 2)
|
|
263
|
-
|
|
264
|
-
stock_qfq_daily['exchange_mean_yesterday'] = stock_qfq_daily['exchange_mean']
|
|
265
|
-
|
|
266
|
-
# 昨日平均值 向当前移位
|
|
267
|
-
stock_qfq_daily['exchange_mean_yesterday'] = stock_qfq_daily['exchange_mean_yesterday'].shift(1)
|
|
268
|
-
|
|
269
|
-
stock_qfq_daily['exchange_difference'] = round(
|
|
270
|
-
stock_qfq_daily['exchange'] - stock_qfq_daily['exchange_mean_yesterday'], 2)
|
|
271
|
-
|
|
272
|
-
stock_qfq_daily['exchange_chg_percent'] = round(
|
|
273
|
-
stock_qfq_daily['exchange'] / stock_qfq_daily['exchange_mean_yesterday'], 2)
|
|
274
|
-
|
|
275
|
-
# pct_chg
|
|
276
|
-
|
|
277
|
-
# 计算每个日期的前10天的均值
|
|
278
|
-
stock_qfq_daily['pct_chg_mean'] = round(stock_qfq_daily['pct_chg'].rolling(window=10, min_periods=1).mean(),
|
|
279
|
-
2)
|
|
280
|
-
|
|
281
|
-
stock_qfq_daily['pct_chg_mean_yesterday'] = stock_qfq_daily['pct_chg_mean']
|
|
282
|
-
|
|
283
|
-
stock_qfq_daily['pct_chg_mean_yesterday'] = stock_qfq_daily['pct_chg_mean_yesterday'].shift(1)
|
|
284
|
-
|
|
285
|
-
stock_qfq_daily['pct_chg_difference'] = round(
|
|
286
|
-
stock_qfq_daily['pct_chg'] - stock_qfq_daily['pct_chg_mean_yesterday'],
|
|
287
|
-
2)
|
|
288
|
-
|
|
289
|
-
# 计算五日均线
|
|
290
|
-
|
|
291
|
-
stock_qfq_daily['avg_five'] = round(stock_qfq_daily['close'].rolling(window=5, min_periods=1).mean(),
|
|
292
|
-
2)
|
|
293
|
-
# 计算十日均线
|
|
294
|
-
stock_qfq_daily['avg_ten'] = round(stock_qfq_daily['close'].rolling(window=10, min_periods=1).mean(),
|
|
295
|
-
2)
|
|
296
|
-
# 计算二十日均线
|
|
297
|
-
stock_qfq_daily['avg_twenty'] = round(stock_qfq_daily['close'].rolling(window=20, min_periods=1).mean(),
|
|
298
|
-
2)
|
|
299
|
-
|
|
300
|
-
# 计算三十日均线
|
|
301
|
-
stock_qfq_daily['avg_thirty'] = round(stock_qfq_daily['close'].rolling(window=30, min_periods=1).mean(),
|
|
302
|
-
2)
|
|
303
|
-
|
|
304
|
-
# 计算六十日均线
|
|
305
|
-
stock_qfq_daily['avg_sixty'] = round(stock_qfq_daily['close'].rolling(window=60, min_periods=1).mean(),
|
|
306
|
-
2)
|
|
307
|
-
|
|
308
|
-
# 与均线差值
|
|
309
|
-
stock_qfq_daily['close_difference_five'] = round(
|
|
310
|
-
100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_five']) / stock_qfq_daily['close'],
|
|
311
|
-
2)
|
|
312
|
-
|
|
313
|
-
stock_qfq_daily['close_difference_ten'] = round(
|
|
314
|
-
100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_ten']) / stock_qfq_daily['close'],
|
|
315
|
-
2)
|
|
316
|
-
|
|
317
|
-
stock_qfq_daily['close_difference_twenty'] = round(
|
|
318
|
-
100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_twenty']) / stock_qfq_daily['close'],
|
|
319
|
-
2)
|
|
320
|
-
|
|
321
|
-
stock_qfq_daily['close_difference_thirty'] = round(
|
|
322
|
-
100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_thirty']) / stock_qfq_daily['close'],
|
|
323
|
-
2)
|
|
324
|
-
|
|
325
|
-
stock_qfq_daily['close_difference_sixty'] = round(
|
|
326
|
-
100 * (stock_qfq_daily['close'] - stock_qfq_daily['avg_sixty']) / stock_qfq_daily['close'],
|
|
327
|
-
2)
|
|
328
|
-
|
|
329
|
-
stock_qfq_daily = stock_qfq_daily[[
|
|
330
|
-
"symbol",
|
|
331
|
-
"name",
|
|
332
|
-
"industry",
|
|
333
|
-
"chg",
|
|
334
|
-
"max_chg",
|
|
335
|
-
"pct_chg",
|
|
336
|
-
"pct_chg_mean",
|
|
337
|
-
"exchange",
|
|
338
|
-
"exchange_mean",
|
|
339
|
-
"exchange_mean_yesterday",
|
|
340
|
-
"exchange_difference",
|
|
341
|
-
'exchange_chg_percent',
|
|
342
|
-
"pct_chg_mean_yesterday",
|
|
343
|
-
"pct_chg_difference",
|
|
344
|
-
"close_difference_five",
|
|
345
|
-
"close_difference_ten",
|
|
346
|
-
"close_difference_twenty",
|
|
347
|
-
"close_difference_thirty",
|
|
348
|
-
"close_difference_sixty",
|
|
349
|
-
"amount_level",
|
|
350
|
-
"flow_mv",
|
|
351
|
-
"flow_mv_sp",
|
|
352
|
-
"volume",
|
|
353
|
-
"amount",
|
|
354
|
-
"change",
|
|
355
|
-
"last_price",
|
|
356
|
-
"open",
|
|
357
|
-
"close",
|
|
358
|
-
"high",
|
|
359
|
-
"low",
|
|
360
|
-
"avg_five",
|
|
361
|
-
"avg_ten",
|
|
362
|
-
"avg_twenty",
|
|
363
|
-
'avg_thirty',
|
|
364
|
-
'avg_sixty',
|
|
365
|
-
"classification",
|
|
366
|
-
"_id",
|
|
367
|
-
"date"
|
|
368
|
-
]]
|
|
369
|
-
stock_qfq_daily = stock_qfq_daily.sort_values(by=['date'], ascending=False)
|
|
370
|
-
stock_qfq_daily = stock_qfq_daily.fillna(0)
|
|
371
|
-
|
|
372
|
-
return stock_qfq_daily
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
def set_history_list(stock_qfq_daily_one, stock_qfq_daily):
|
|
376
|
-
stock_qfq_daily = stock_qfq_daily[[
|
|
377
|
-
"date",
|
|
378
|
-
"exchange",
|
|
379
|
-
"exchange_mean",
|
|
380
|
-
"exchange_mean_yesterday",
|
|
381
|
-
"exchange_difference",
|
|
382
|
-
"exchange_chg_percent",
|
|
383
|
-
"pct_chg_mean_yesterday",
|
|
384
|
-
"pct_chg_difference",
|
|
385
|
-
"pct_chg",
|
|
386
|
-
"pct_chg_mean",
|
|
387
|
-
"max_chg",
|
|
388
|
-
"chg",
|
|
389
|
-
"amount_level",
|
|
390
|
-
"close_difference_five",
|
|
391
|
-
"close_difference_ten",
|
|
392
|
-
"close_difference_twenty",
|
|
393
|
-
"close_difference_thirty",
|
|
394
|
-
'open',
|
|
395
|
-
'close',
|
|
396
|
-
'high',
|
|
397
|
-
'low'
|
|
398
|
-
]]
|
|
399
|
-
# 删除index 转str
|
|
400
|
-
stock_qfq_daily_one.loc[:, 'history_data'] = stock_qfq_daily.to_string(index=False)
|
|
401
|
-
|
|
402
|
-
daily_num = stock_qfq_daily.shape[0]
|
|
403
|
-
std_amount_ten = 0
|
|
404
|
-
mean_amount_ten = 0
|
|
405
|
-
std_amount_thirty = 0
|
|
406
|
-
mean_amount_thirty = 0
|
|
407
|
-
std_amount_sixty = 0
|
|
408
|
-
mean_amount_sixty = 0
|
|
409
|
-
|
|
410
|
-
if daily_num >= 10:
|
|
411
|
-
stock_qfq_daily_ten = stock_qfq_daily.iloc[0:10]
|
|
412
|
-
# 计算 amount 的标准差
|
|
413
|
-
std_amount_ten = round(stock_qfq_daily_ten['amount_level'].std(), 2)
|
|
414
|
-
# 计算 amount 的平均值
|
|
415
|
-
mean_amount_ten = round(stock_qfq_daily_ten['amount_level'].mean(), 2)
|
|
416
|
-
|
|
417
|
-
if daily_num >= 30:
|
|
418
|
-
stock_qfq_daily_thirty = stock_qfq_daily.iloc[0:30]
|
|
419
|
-
# 计算 amount 的标准差
|
|
420
|
-
std_amount_thirty = round(stock_qfq_daily_thirty['amount_level'].std(), 2)
|
|
421
|
-
# 计算 amount 的平均值
|
|
422
|
-
mean_amount_thirty = round(stock_qfq_daily_thirty['amount_level'].mean(), 2)
|
|
423
|
-
if daily_num >= 60:
|
|
424
|
-
std_amount_sixty = round(stock_qfq_daily['amount_level'].std(), 2)
|
|
425
|
-
# 计算 amount 的平均值
|
|
426
|
-
mean_amount_sixty = round(stock_qfq_daily['amount_level'].mean(), 2)
|
|
427
|
-
|
|
428
|
-
# text = list(stock_qfq_daily_one['history_data'])[0]
|
|
429
|
-
# history_data_df = pd.read_csv(StringIO(text), delim_whitespace=True)
|
|
430
|
-
|
|
431
|
-
stock_qfq_daily_one.loc[:, 'std_amount_ten'] = std_amount_ten
|
|
432
|
-
stock_qfq_daily_one.loc[:, 'mean_amount_ten'] = mean_amount_ten
|
|
433
|
-
stock_qfq_daily_one.loc[:, 'std_amount_thirty'] = std_amount_thirty
|
|
434
|
-
stock_qfq_daily_one.loc[:, 'mean_amount_thirty'] = mean_amount_thirty
|
|
435
|
-
stock_qfq_daily_one.loc[:, 'std_amount_sixty'] = std_amount_sixty
|
|
436
|
-
stock_qfq_daily_one.loc[:, 'mean_amount_sixty'] = mean_amount_sixty
|
|
437
|
-
|
|
438
|
-
return stock_qfq_daily_one
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
# k线形态
|
|
442
|
-
def set_k_line_patterns(stock_qfq_daily_one):
|
|
443
|
-
open = list(stock_qfq_daily_one['open'])[0]
|
|
444
|
-
close = list(stock_qfq_daily_one['close'])[0]
|
|
445
|
-
high = list(stock_qfq_daily_one['high'])[0]
|
|
446
|
-
low = list(stock_qfq_daily_one['low'])[0]
|
|
447
|
-
max_chg = list(stock_qfq_daily_one['max_chg'])[0]
|
|
448
|
-
chg = list(stock_qfq_daily_one['chg'])[0]
|
|
449
|
-
|
|
450
|
-
k_line_pattern = k_line_patterns_service.k_line_patterns_classify(open, close, high, low, max_chg, chg)
|
|
451
|
-
stock_qfq_daily_one.loc[:, 'k_line_pattern'] = k_line_pattern.value
|
|
452
|
-
return stock_qfq_daily_one
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
# 字段选择
|
|
456
|
-
def k_line_field_fix(k_line_info, stock_qfq_daily_one):
|
|
457
|
-
k_line_info['classification'] = stock_qfq_daily_one['classification']
|
|
458
|
-
k_line_info['amount_level_last'] = stock_qfq_daily_one['amount_level']
|
|
459
|
-
k_line_info['name'] = stock_qfq_daily_one['name']
|
|
460
|
-
k_line_info['exchange_last'] = stock_qfq_daily_one['exchange']
|
|
461
|
-
k_line_info['exchange_mean_last'] = stock_qfq_daily_one['exchange_mean']
|
|
462
|
-
k_line_info['exchange_mean_last_02'] = stock_qfq_daily_one['exchange_mean_yesterday']
|
|
463
|
-
k_line_info['exchange_difference_last'] = stock_qfq_daily_one['exchange_difference']
|
|
464
|
-
k_line_info['exchange_chg_percent_last'] = stock_qfq_daily_one['exchange_chg_percent']
|
|
465
|
-
k_line_info['pct_chg_mean_last'] = stock_qfq_daily_one['pct_chg_mean_yesterday']
|
|
466
|
-
k_line_info['pct_chg_difference_last'] = stock_qfq_daily_one['pct_chg_difference']
|
|
467
|
-
|
|
468
|
-
k_line_info['close_difference_five_last'] = stock_qfq_daily_one['close_difference_five']
|
|
469
|
-
k_line_info['close_difference_ten_last'] = stock_qfq_daily_one['close_difference_ten']
|
|
470
|
-
k_line_info['close_difference_twenty_last'] = stock_qfq_daily_one['close_difference_twenty']
|
|
471
|
-
k_line_info['close_difference_thirty_last'] = stock_qfq_daily_one['close_difference_thirty']
|
|
472
|
-
k_line_info['close_difference_sixty_last'] = stock_qfq_daily_one['close_difference_sixty']
|
|
473
|
-
|
|
474
|
-
k_line_info['pct_chg_last'] = stock_qfq_daily_one['pct_chg']
|
|
475
|
-
k_line_info['pct_chg_mean_last'] = stock_qfq_daily_one['pct_chg_mean']
|
|
476
|
-
k_line_info['max_chg_last'] = stock_qfq_daily_one['max_chg']
|
|
477
|
-
k_line_info['chg_last'] = stock_qfq_daily_one['chg']
|
|
478
|
-
k_line_info['open_last'] = stock_qfq_daily_one['open']
|
|
479
|
-
k_line_info['close_last'] = stock_qfq_daily_one['close']
|
|
480
|
-
k_line_info['high_last'] = stock_qfq_daily_one['high']
|
|
481
|
-
k_line_info['low_last'] = stock_qfq_daily_one['low']
|
|
482
|
-
k_line_info['avg_five_last'] = stock_qfq_daily_one['avg_five']
|
|
483
|
-
k_line_info['avg_ten_last'] = stock_qfq_daily_one['avg_ten']
|
|
484
|
-
k_line_info['avg_twenty_last'] = stock_qfq_daily_one['avg_twenty']
|
|
485
|
-
k_line_info['avg_thirty_last'] = stock_qfq_daily_one['avg_thirty']
|
|
486
|
-
k_line_info['avg_sixty_last'] = stock_qfq_daily_one['avg_sixty']
|
|
487
|
-
|
|
488
|
-
k_line_info['std_amount_ten'] = stock_qfq_daily_one['std_amount_ten']
|
|
489
|
-
k_line_info['mean_amount_ten'] = stock_qfq_daily_one['mean_amount_ten']
|
|
490
|
-
k_line_info['std_amount_thirty'] = stock_qfq_daily_one['std_amount_thirty']
|
|
491
|
-
k_line_info['mean_amount_thirty'] = stock_qfq_daily_one['mean_amount_thirty']
|
|
492
|
-
k_line_info['std_amount_sixty'] = stock_qfq_daily_one['std_amount_sixty']
|
|
493
|
-
k_line_info['mean_amount_sixty'] = stock_qfq_daily_one['mean_amount_sixty']
|
|
494
|
-
k_line_info['k_line_pattern'] = stock_qfq_daily_one['k_line_pattern']
|
|
495
|
-
k_line_info['history_data'] = stock_qfq_daily_one['history_data']
|
|
496
|
-
|
|
29
|
+
# 处理周线 月线
|
|
30
|
+
k_line_info = week_month_k_line_service.handle_month_week_line(k_line_info, str_day, symbol, deal_days)
|
|
31
|
+
# 处理日线
|
|
32
|
+
k_line_info = daily_k_line_service.handle_day_line(k_line_info, str_day, symbol, deal_days)
|
|
497
33
|
return k_line_info
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
# 计算开盘涨幅
|
|
501
|
-
def calculate_open_chg(stock_qfq_daily, k_line_info):
|
|
502
|
-
# 新股
|
|
503
|
-
if stock_qfq_daily.shape[0] == 1:
|
|
504
|
-
k_line_info['open_chg_last'] = k_line_info['daily01']
|
|
505
|
-
else:
|
|
506
|
-
# 获取前一个交易日的收盘价格
|
|
507
|
-
k_line_info['before_close'] = round(
|
|
508
|
-
k_line_info['close_last'] / (1 + k_line_info['daily01'] * 0.01), 2)
|
|
509
|
-
k_line_info['open_chg_last'] = round((k_line_info['open_last'] / k_line_info['before_close'] - 1) * 100, 2)
|
|
510
|
-
return k_line_info
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
# 排除最近10个交易日有三板以上的股票
|
|
514
|
-
def check_recent_zt_stock(str_day, k_line_info):
|
|
515
|
-
k_line_info.loc[:, 'exclude'] = False
|
|
516
|
-
k_line_info = symbol_classify_api.set_stock_type(k_line_info)
|
|
517
|
-
k_line_info_sh = symbol_classify_api.choose_sh_symbol(k_line_info)
|
|
518
|
-
if data_frame_util.is_empty(k_line_info_sh):
|
|
519
|
-
return k_line_info
|
|
520
|
-
else:
|
|
521
|
-
k_line_info_sh = sh_small_normal_zt_k_line_check_api.recent_day_zt_check(k_line_info_sh.copy())
|
|
522
|
-
return k_line_info_sh
|
|
@@ -18,6 +18,7 @@ import mns_scheduler.k_line.sync.daily_week_month_line_sync as daily_week_month_
|
|
|
18
18
|
import mns_scheduler.k_line.clean.k_line_info_clean_impl as k_line_info_clean_impl
|
|
19
19
|
import mns_common.utils.data_frame_util as data_frame_util
|
|
20
20
|
import mns_common.component.company.company_common_service_api as company_common_service_api
|
|
21
|
+
|
|
21
22
|
K_LINE_CLEAN_DB_NAME = 'k_line_clean_fail_name'
|
|
22
23
|
|
|
23
24
|
# 定义一个全局锁,用于保护 result 变量的访问
|
|
@@ -36,6 +37,7 @@ def sync_k_line_info_task(str_day):
|
|
|
36
37
|
last_trade_day = trade_date_common_service_api.get_last_trade_day(str_day)
|
|
37
38
|
query = {'date': date_handle_util.no_slash_date(last_trade_day)}
|
|
38
39
|
count = mongodb_util.count(query, 'stock_qfq_daily')
|
|
40
|
+
# 当天没有k线数据时 进行同步
|
|
39
41
|
if count == 0:
|
|
40
42
|
daily_week_month_line_sync_api.sync_all_daily_data('daily', 'qfq', 'stock_qfq_daily', str_day,
|
|
41
43
|
None)
|
|
@@ -90,7 +92,10 @@ def handle_fail_data(str_day, real_time_quotes_now):
|
|
|
90
92
|
|
|
91
93
|
# 多线程同步任务
|
|
92
94
|
def multi_threaded_k_line_sync(str_day):
|
|
95
|
+
# 退市代码
|
|
96
|
+
de_list_company_symbols = company_common_service_api.get_de_list_company()
|
|
93
97
|
real_time_quotes_now = east_money_stock_api.get_real_time_quotes_all_stocks()
|
|
98
|
+
real_time_quotes_now = real_time_quotes_now.loc[~(real_time_quotes_now['symbol'].isin(de_list_company_symbols))]
|
|
94
99
|
|
|
95
100
|
# 将list_date列中的所有NaN值设置为99990909
|
|
96
101
|
real_time_quotes_now['list_date'].fillna(20990909.0, inplace=True)
|
|
@@ -184,6 +189,6 @@ def clean_history_data():
|
|
|
184
189
|
|
|
185
190
|
|
|
186
191
|
if __name__ == '__main__':
|
|
187
|
-
sync_k_line_info("2024-
|
|
192
|
+
sync_k_line_info("2024-06-03", None)
|
|
188
193
|
# clean_history_data()
|
|
189
194
|
# sync_k_line_info("2023-12-22")
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 16
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
from mns_common.db.MongodbUtil import MongodbUtil
|
|
9
|
+
import mns_common.utils.date_handle_util as date_handle_util
|
|
10
|
+
from mns_common.component.classify.symbol_classify_param import stock_type_classify_param
|
|
11
|
+
|
|
12
|
+
mongodb_util = MongodbUtil('27017')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# 处理月线 周线 todo 暂时简单计算周线之和
|
|
16
|
+
def handle_month_week_line(k_line_info, str_day, symbol, deal_days):
|
|
17
|
+
sub_stock_new_max_deal_days = stock_type_classify_param['sub_stock_new_max_deal_days']
|
|
18
|
+
if deal_days > sub_stock_new_max_deal_days:
|
|
19
|
+
k_line_info = handle_month_line(k_line_info, str_day, symbol)
|
|
20
|
+
k_line_info = handle_week_line(k_line_info, str_day, symbol)
|
|
21
|
+
else:
|
|
22
|
+
k_line_info['week01'] = 0
|
|
23
|
+
k_line_info['week02'] = 0
|
|
24
|
+
k_line_info['week03'] = 0
|
|
25
|
+
k_line_info['week04'] = 0
|
|
26
|
+
k_line_info['sum_week'] = 0
|
|
27
|
+
k_line_info['week_num'] = 0
|
|
28
|
+
k_line_info['week_last_day'] = '19890729'
|
|
29
|
+
|
|
30
|
+
k_line_info['sum_month'] = 0
|
|
31
|
+
k_line_info['month_num'] = 0
|
|
32
|
+
k_line_info['month01'] = 0
|
|
33
|
+
k_line_info['month02'] = 0
|
|
34
|
+
k_line_info['month01_date'] = '19890729'
|
|
35
|
+
k_line_info['month02_date'] = '19890729'
|
|
36
|
+
return k_line_info
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# 处理月线
|
|
40
|
+
def handle_month_line(k_line_info, str_day, symbol):
|
|
41
|
+
month_begin_day = str_day[0:7] + '-01'
|
|
42
|
+
query = {"symbol": symbol,
|
|
43
|
+
'date': {"$lt": date_handle_util.no_slash_date(month_begin_day)}}
|
|
44
|
+
stock_hfq_monthly = mongodb_util.descend_query(query, 'stock_qfq_monthly', 'date', 2)
|
|
45
|
+
month_num = stock_hfq_monthly.shape[0]
|
|
46
|
+
k_line_info['month_num'] = month_num
|
|
47
|
+
if month_num > 0:
|
|
48
|
+
k_line_info['sum_month'] = round(sum(stock_hfq_monthly['chg']), 2)
|
|
49
|
+
else:
|
|
50
|
+
k_line_info['sum_month'] = 0
|
|
51
|
+
|
|
52
|
+
if month_num == 0:
|
|
53
|
+
k_line_info['month01'] = 0
|
|
54
|
+
k_line_info['month02'] = 0
|
|
55
|
+
k_line_info['month01_date'] = '19890729'
|
|
56
|
+
k_line_info['month02_date'] = '19890729'
|
|
57
|
+
elif month_num == 1:
|
|
58
|
+
k_line_info['month01'] = stock_hfq_monthly.iloc[0].chg
|
|
59
|
+
k_line_info['month02'] = 0
|
|
60
|
+
k_line_info['month01_date'] = stock_hfq_monthly.iloc[0].date
|
|
61
|
+
k_line_info['month02_date'] = '19890729'
|
|
62
|
+
elif month_num == 2:
|
|
63
|
+
k_line_info['month01'] = stock_hfq_monthly.iloc[0].chg
|
|
64
|
+
k_line_info['month02'] = stock_hfq_monthly.iloc[1].chg
|
|
65
|
+
k_line_info['month01_date'] = stock_hfq_monthly.iloc[0].date
|
|
66
|
+
k_line_info['month02_date'] = stock_hfq_monthly.iloc[1].date
|
|
67
|
+
|
|
68
|
+
return k_line_info
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# 处理周线
|
|
72
|
+
def handle_week_line(k_line_info, str_day, symbol):
|
|
73
|
+
month_begin_day = str_day[0:7] + '-01'
|
|
74
|
+
query = {"symbol": symbol,
|
|
75
|
+
'$and': [{'date': {"$gte": date_handle_util.no_slash_date(month_begin_day)}},
|
|
76
|
+
{'date': {"$lt": date_handle_util.no_slash_date(str_day)}}]}
|
|
77
|
+
stock_hfq_weekly = mongodb_util.find_query_data('stock_qfq_weekly', query)
|
|
78
|
+
week_num = stock_hfq_weekly.shape[0]
|
|
79
|
+
if week_num > 0:
|
|
80
|
+
stock_hfq_weekly = stock_hfq_weekly.sort_values(by=['date'], ascending=False)
|
|
81
|
+
k_line_info['sum_week'] = round(sum(stock_hfq_weekly['chg']), 2)
|
|
82
|
+
else:
|
|
83
|
+
k_line_info['sum_week'] = 0
|
|
84
|
+
k_line_info['week_num'] = week_num
|
|
85
|
+
if week_num == 1:
|
|
86
|
+
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
87
|
+
k_line_info['week02'] = 0
|
|
88
|
+
k_line_info['week03'] = 0
|
|
89
|
+
k_line_info['week04'] = 0
|
|
90
|
+
elif week_num == 2:
|
|
91
|
+
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
92
|
+
k_line_info['week02'] = stock_hfq_weekly.iloc[1].chg
|
|
93
|
+
k_line_info['week03'] = 0
|
|
94
|
+
k_line_info['week04'] = 0
|
|
95
|
+
elif week_num == 3:
|
|
96
|
+
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
97
|
+
k_line_info['week02'] = stock_hfq_weekly.iloc[1].chg
|
|
98
|
+
k_line_info['week03'] = stock_hfq_weekly.iloc[2].chg
|
|
99
|
+
k_line_info['week04'] = 0
|
|
100
|
+
elif week_num >= 4:
|
|
101
|
+
k_line_info['week01'] = stock_hfq_weekly.iloc[0].chg
|
|
102
|
+
k_line_info['week02'] = stock_hfq_weekly.iloc[1].chg
|
|
103
|
+
k_line_info['week03'] = stock_hfq_weekly.iloc[2].chg
|
|
104
|
+
k_line_info['week04'] = stock_hfq_weekly.iloc[3].chg
|
|
105
|
+
elif week_num == 0:
|
|
106
|
+
k_line_info['week01'] = 0
|
|
107
|
+
k_line_info['week02'] = 0
|
|
108
|
+
k_line_info['week03'] = 0
|
|
109
|
+
k_line_info['week04'] = 0
|
|
110
|
+
k_line_info['week_last_day'] = month_begin_day
|
|
111
|
+
k_line_info['sum_week'] = 0
|
|
112
|
+
return k_line_info
|
|
113
|
+
stock_hfq_weekly = stock_hfq_weekly.sort_values(by=['date'], ascending=False)
|
|
114
|
+
stock_hfq_weekly_last = stock_hfq_weekly.iloc[0:1]
|
|
115
|
+
k_line_info['week_last_day'] = list(stock_hfq_weekly_last['date'])[0]
|
|
116
|
+
|
|
117
|
+
return k_line_info
|