问答交流

策略运行正常,但无法模拟交易,dropna出现Nan

由lookit创建,最终由lookit 被浏览 48 用户

运行平台提供的策略模板,自己增加了几个因子,尝试模拟交易时,出现dropna模块出现Nan错误。我尝试在自定义python中加入提前读入m天数据的方法,也无法避免这个问题,不知有何解决方案?

自定义python代码如下:

Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
def bigquant_run(input_1, start_date,end_date):
# 示例代码如下。在这里编写您的代码
ins=input_1.read_pickle()['instruments']
start_date=input_1.read_pickle()['start_date']
end_date=input_1.read_pickle()['end_date']
#进行向前抽取数据,试图避免数据为零的错误
m=90
start_date=(datetime.datetime.strptime(start_date,('%Y-%m-%d'))-datetime.timedelta(m)). strftime('%Y-%m-%d')
df=DataSource('bar1d_index_CN_STOCK_A').read(ins[0],start_date=start_date,end_date=end_date,fields=['close','open','low','high','adjust_factor'])
#stockret=close/shift(close,1)-1
#bmret=close/shift(close,1)-1
#df['bmret']=(df['close']/df['adjust_factor'])/(df['close'].shift(1)/df['adjust_factor'].shift(1))-1
df['bmret']=(df['close'])/(df['close'].shift(1))-1
df=df[['date','bmret']]
#df = df[['date', 'close', 'instrument']].rename(columns={'close': 'close_0'})
data_1 = DataSource.write_df(df)
return Outputs(data_1=data_1, data_2=None, data_3=None)

https://bigquant.com/experimentshare/a845d683c0824090ab08819ad0a43d4b

\

评论
  • 我提交模拟交易成功了,把notebook后面的 ![{w:100}](/wiki/api/attachments.redirect?id=76137a58-a906-47f3-8fe0-290863bdf431)删除,保存策略,在提交模拟交易试试。
  • 多谢,怎没想到提示dropna模块抽取失败,却是策略后面代码的原因,真是让人意料不到
{link}