问答交流

表达式问题

由j2015创建,最终由j2015 被浏览 37 用户


请问如何在自定义Python模块写过滤表达式,

实现剔除上证指数5个交易日总涨幅大于4%的日期的训练数据?

即根据日期过滤训练数据。谢谢

评论
  • 直接加过滤模块就行 非要自定义太麻烦
  • ``` 下面的代码可以找出日期吧,请问如何在过滤模块写表达式剔除掉这些日期的上证深证主板和创业板的所有股票? start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d') df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close']) benchmark_data=df[df.instrument=='000001.HIX'] benchmark_data['ret5']=benchmark_data['close']/benchmark_data['close'].shift(5)-1 benchmark_data['filter_1'] = np.where(benchmark_data['ret4']>0.04,1,0) benchmark_data['date']=benchmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d')) benchmark_data.set_index('date',inplace=True) ``` \
{link}