1, filter suspension
DEF set_feasible_stocks (stock_list, Days, context): # give dataframe information whether suspension, the suspension 1, is not suspended to give 0 suspened_info_df = get_price (List (stock_list), START_DATE = context.current_dt, END_DATE = context.current_dt, Frequency = ' Daily ' , Fields = ' paused ' ) [ ' paused ' ] .T # filter stock suspension return dataframe unsuspened_index suspened_info_df.iloc = [:, 0] <. 1 # Get the day is not suspended stock code List: unsuspened_stocks = suspened_info_df [unsuspened_index] .index # further screened before the days days never suspended stock List: feasible_stocks = [] current_data = get_current_data () for Stock in unsuspened_stocks: IF SUM (attribute_history (Stock , Days, Unit = ' 1D ' , = Fields ( ' paused ' ), skip_paused = False)) [0] == 0: feasible_stocks.append (Stock) return feasible_stocks
2, the trading day migration
DEF shift_trading_day (date, the Shift): # Get all of the trading day, returns a list containing all of the trading day, the value of the element datetime.date type. tradingday = get_all_trade_days () # the Shift days after the date that day to get the line in the list returns a reference number shiftday_index = List (tradingday) .index (dATE) + Shift # line numbers of the date of the return type datetime.date return tradingday [shiftday_index]
3, to select a long array of stock
def sel_duotou_list(security,date): sel_list = [] for stock in security: try: ma5 = MA(stock, date, timeperiod=5)[stock] ma21 = MA(stock, date, timeperiod=21)[stock] ma30 = MA(stock, date, timeperiod=30)[stock] ma55 = MA(stock, date, timeperiod=55)[stock] ma89 = MA(stock, date, timeperiod=89)[stock] ma120 = MA(stock, date, timeperiod=120)[stock] if (ma5>ma21) & (ma21>ma30) & (ma30>ma55): sel_list.append(stock) except: continue return sel_list