代码写的确实挺辛苦:
```
def check_first_valley(trade_date, stock):
int_count = 2
for stock_day in trade_date:
df_panel = get_price(stock, count=1, end_date=trade_date[trade_date.size - int_count], frequency='daily',
fields=['open', 'close', 'high_limit', 'money'])
pre_close_price = df_panel['close'].values
df_panel_5 = get_price(stock, count=5, end_date=trade_date[trade_date.size - int_count], frequency='daily',
fields=['open', 'close', 'high_limit', 'money'])
df_close_mean_5 = df_panel_5['close'].mean()
int_count = int_count + 1
if pre_close_price > df_close_mean_5:
return False
if int_count > 8:
return True
```
我写了三个版本,请指正。
```
# 单只股票
def check_first_valley2(trade_date, stock):
bRetVal = True
for int_count in range(2, 9):
closes = get_price(stock, count=5, end_date=trade_date[-int_count], fields=['close'], panel=False)['close']
if closes[-1] > closes.mean():
bRetVal = False
break
#
return bRetVal
# 单只股票
def check_first_valley3(stock):
# type: (str) -> bool
h = attribute_history(stock, 12, '1d', 'close')['close']
return np.all(h.rolling(window=5).apply(lambda x: x[-1] < x.mean(), raw=False).iloc[-8:-1].values)
# 股票列表检测
def check_first_valley4(stocks):
# type: (list) -> list
h = history(12, '1d', 'close', stocks)
s_cm = h.rolling(window=5).apply(lambda x: x[-1] < x.mean()).iloc[-8:-1].sum()
return list(s_cm[s_cm == 7].index)
```
2021-10-25