【发布时间】:2016-06-19 11:09:58
【问题描述】:
Date Open Close Buying Selling Cut_Off_Price
2009.11.11 4.805 4.43 0 0 0
2009.11.12 4.51 4.505 0 0 0
2009.11.13 4.545 4.765 1 0 3.812
2009.11.16 4.78 4.76 0 0 0
2009.11.17 4.755 4.605 0 0 0
2009.11.18 4.56 4.495 0 0 0
2009.11.19 4.495 4.535 1 0 3.628
2009.11.20 4.535 4.63 0 0 0
2009.11.23 4.7 4.67 0 0 0
2009.11.24 4.74 4.91 0 0 0
2009.11.25 4.97 4.87 0 0 0
2009.11.26 4.93 4.97 0 0 0
2009.11.27 5 4.94 0 0 0
2009.11.30 4.865 4.86 0 0 0
2009.12.1 4.83 3.855 0 0 0
2009.12.2 4.89 4.89 0 0 0
2009.12.3 4.85 4.71 0 0 0
2009.12.4 4.78 4.76 0 0 0
2009.12.7 3.225 3.565 0 0 0
2009.12.8 3.6 3.705 0 0 0
2009.12.9 3.76 3.575 0 0 0
2009.12.10 3.575 3.79 0 0 0
2009.12.11 3.84 3.84 0 0 0
2009.12.14 3.85 3.81 0 0 0
2009.12.15 3.84 3.985 0 0 0
2009.12.16 3.985 4.1 0 0 0
2009.12.17 4.105 4.165 0 0 0
2009.12.18 4.22 4.15 0 0 0
2009.12.21 4.145 4.5 0 0 0
2009.12.22 4.55 4.76 0 0 0
2009.12.23 4.705 4.72 0 0 0
2009.12.24 4.9 4.78 0 0 0
- 数据是股票价格,我发出了买入和卖出信号,Cut_Off_Price 是计算买入价的某个百分比。 随着时间的推移,如果第一天的价格低于截止价,我想发出卖出信号。和销售日期。
我想要的结果如下
Date Open Close Buying Selling Cut_Off_Price Cut_Off_Signal Sell_Out Sell_Out_Date
2009.11.11 4.805 4.43 0 0 0 0 0 0
2009.11.12 4.510 4.505 0 0 0 0 0 0
2009.11.13 4.545 4.765 1 0 3.812 0 1 2009.12.1
2009.11.16 4.780 4.760 0 0 0 0 0 0
2009.11.17 4.755 4.605 0 0 0 0 0 0
2009.11.18 4.560 4.495 0 0 0 0 0 0
2009.11.19 4.495 4.535 1 0 3.628 0 1 2009.12.7
2009.11.20 4.535 4.630 0 0 0 0 0 0
2009.11.23 4.700 4.670 0 0 0 0 0 0
2009.11.24 4.740 4.910 0 0 0 0 0 0
2009.11.25 4.970 4.870 0 0 0 0 0 0
2009.11.26 4.930 4.970 0 0 0 0 0 0
2009.11.27 5.000 4.940 0 0 0 0 0 0
2009.11.30 4.865 4.860 0 0 0 0 0 0
2009.12.1 4.830 3.855 0 0 0 1 0 0
2009.12.2 4.890 4.890 0 0 0 0 0 0
2009.12.3 4.850 4.710 0 0 0 0 0 0
2009.12.4 4.780 4.760 0 0 0 0 0 0
2009.12.7 3.225 3.565 0 0 0 1 0 0
2009.12.8 3.600 3.705 0 0 0 0 0 0
2009.12.9 3.760 3.575 0 0 0 0 0 0
2009.12.10 3.575 3.790 0 0 0 0 0 0
2009.12.11 3.840 3.840 0 0 0 0 0 0
2009.12.14 3.850 3.810 0 0 0 0 0 0
2009.12.15 3.840 3.985 0 0 0 0 0 0
2009.12.16 3.985 4.100 0 0 0 0 0 0
2009.12.17 4.105 4.165 0 0 0 0 0 0
2009.12.18 4.220 4.150 0 0 0 0 0 0
2009.12.21 4.145 4.500 0 0 0 0 0 0
2009.12.22 4.550 4.760 0 0 0 0 0 0
2009.12.23 4.705 4.720 0 0 0 0 0 0
2009.12.24 4.900 4.780 0 0 0 0 0 0
我的代码如下
buying_list = data[data['Buying']==True]
data['Cut_Off_Signal']=False
def trading(data):
for idd in range(len(data.index)):
for ids in range(len(buying_list.index)):
if data.index[idd]>buying_list.index[ids]:
data['Cut_Off_Signal'][idd] = np.where(buying_list['Cut_Off_Price'][ids]>data['Close'][idd],True,False)
data[buying_list.index[ids],'Sell_Out_Signal'] = np.where(data['Cut_Off_Signal'][idd]== True,True,False)
#data.loc[buying_list.index[ids],'Sell_Out_Signal']=True
else:
continue
它没有达到我想要的效果,而且花费了太多时间。 (总行是 970,总buying_list 行是 37。但花了大约 5 分钟。 我尝试 .apply(f) 但失败了(我是初学者 ^^;;) 感谢您的建议!
【问题讨论】: