Introduction to Machine Learning (Trend Prediction)

Hi,

This code line assign a signal value equal to -1 when last open day is less than today open:

Df['Signal'][Df['Open'].shift(-1)<Df['Open']]=-1

if that is true, why I get this result?

2010-01-08  113.89  114.62  113.66  114.57  114.33  113.18  114.19       1

2010-01-11  115.08  115.13  114.24  114.73  114.62  113.66  114.57      -1

2010-01-12  113.97  114.21  113.22  113.66  115.13  114.24  114.73      -1

2010-01-13  113.95  114.94  113.37  114.62  114.21  113.22  113.66       1

 

 

with this line, it's the same:

Df['Signal']=np.where(Df['Open'].shift(-1)<Df['Open'], -1, 1)

2010-01-08  113.89  114.62  113.66  114.57  114.33  113.18  114.19       1

2010-01-11  115.08  115.13  114.24  114.73  114.62  113.66  114.57      -1

2010-01-12  113.97  114.21  113.22  113.66  115.13  114.24  114.73      -1

2010-01-13  113.95  114.94  113.37  114.62  114.21  113.22  113.66       1

Hi Mario,

Please take a closer look at the code, it is shift(-1) and not shift(1). So the signal we generate is comparing the open values for today to that of the next day. As we make a prediciton at the open of the current candle so the profit/loss can be known at the open of next candle. For the first row, open is 113.89 and next open is 115.08 so we have a signal of 1. For second row, we have an open of 115.08 and the next open is 113.97, so a signal of -1. Similarly

:wink:

thank you!