Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 我如何迭代一个数据帧,当我得到一个信号(+1 maX column)时,我如何从另一列中选择另一个单元格?_Algorithm_Python 3.x_Iteration - Fatal编程技术网

Algorithm 我如何迭代一个数据帧,当我得到一个信号(+1 maX column)时,我如何从另一列中选择另一个单元格?

Algorithm 我如何迭代一个数据帧,当我得到一个信号(+1 maX column)时,我如何从另一列中选择另一个单元格?,algorithm,python-3.x,iteration,Algorithm,Python 3.x,Iteration,我已经创建了一个基本的panda数据框架,其中包含历史美元兑日元的交易价格、移动平均线和最后一列“maX”,它决定我是买入+1,卖出-1,还是不买入0。如下所示 OPEN HIGH LOW LAST ma5 ma8 ma21 maX Date 11/23/2009 88.84 89.19 88.58

我已经创建了一个基本的panda数据框架,其中包含历史美元兑日元的交易价格、移动平均线和最后一列“maX”,它决定我是买入+1,卖出-1,还是不买入0。如下所示

             OPEN   HIGH    LOW   LAST     ma5     ma8    ma21  maX
Date                                                               
11/23/2009  88.84  89.19  88.58  88.97     NaN     NaN     NaN  0.0
11/24/2009  88.97  89.07  88.36  88.50     NaN     NaN     NaN  0.0
11/25/2009  88.50  88.63  87.22  87.35     NaN     NaN     NaN  0.0
11/26/2009  87.35  87.48  86.30  86.59     NaN     NaN     NaN  0.0
11/27/2009  86.59  87.02  84.83  86.53  87.588     NaN     NaN  0.0
11/30/2009  87.17  87.17  85.87  86.41  87.076     NaN     NaN  0.0
12/1/2009   86.41  87.53  86.17  86.68  86.712     NaN     NaN  0.0
12/2/2009   86.68  87.49  86.59  87.39  86.720  87.302     NaN  0.0
12/3/2009   87.39  88.48  87.32  88.26  87.054  87.214     NaN  0.0
12/4/2009   88.26  90.77  88.00  90.56  87.860  87.471     NaN  0.0
12/7/2009   90.27  90.47  89.04  89.51  88.480  87.741     NaN  0.0
12/8/2009   89.51  89.53  88.18  88.43  88.830  87.971     NaN  0.0
12/9/2009   88.43  88.69  87.37  87.87  88.926  88.139     NaN  0.0
12/10/2009  87.87  88.45  87.74  88.20  88.914  88.362     NaN  0.0
12/11/2009  88.20  89.81  88.20  89.10  88.622  88.665     NaN  0.0
12/14/2009  89.11  89.32  88.32  88.62  88.444  88.819     NaN  0.0
12/15/2009  88.62  89.95  88.58  89.61  88.680  88.988     NaN  0.0
12/16/2009  89.61  89.99  89.39  89.78  89.062  88.890     NaN  0.0
12/17/2009  89.78  90.37  89.56  89.97  89.416  88.947     NaN  0.0
12/18/2009  89.97  90.91  88.98  90.50  89.696  89.206     NaN  0.0
12/21/2009  90.45  91.24  90.16  91.17  90.206  89.619  88.571  0.0
12/22/2009  91.17  91.87  91.00  91.84  90.652  90.074  88.708  1.0
12/23/2009  91.84  91.87  91.32  91.64  91.024  90.391  88.858  1.0
现在,我如何迭代最后一列“maX”,以便如果在0或-1之后得到新的+1买入信号,我将选择第二天的开盘价,并将其添加到右侧数据框中称为“Entry”的新列中。对于“maX”中的-1或0,“Entry”列将规定为0。我只是想在数据框上创建一个新的列“Entry”,在基本算法“maX”从0或-1更改为+1后,在“Entry”列中显示购买级别

我下面的尝试失败了,我被困在选择“开始”级别并将其添加到新的“条目”列中

Buy = [0,]
maXLast = [0]
openLast = [0]
for maXCurr, openCurr in zip(maX[1:], 'OPEN'[1:]):
    if maXCurr == 1 and maXLast == 0:
        Buy.append(openCurr)
    elif maXCurr == 1 and maX == -1:
        Buy.append(openCurr)
    else:
        Buy.append(0)
    maXLast = maXCurr
    openLast = openCurr

Entry = pd.DataFrame(Buy,index = dfmas.index).astype('float') 
Entry.columns = ['Buy']
非常感谢