Observations in a notebook of the course Trading with machine regression

Hi, I think there is a small mistake in the notebook Strategy Analytics.ipynb



where it says:

test_dataset.loc[(test_dataset['High'] > test_dataset['P_H']) & (

    test_dataset['Low'] > test_dataset['P_L']), 'Signal'] = -1



I think it should be:

test_dataset.loc[(test_dataset['High'].shift(1) > test_dataset['P_H']) & (

    test_dataset['Low'].shift(1) > test_dataset['P_L']), 'Signal'] = -1



because it is the High and Low values ​​of the previous day that have to be compared.





on the other hand, where it says:


Compute GLD returns

test_dataset['gld_returns'] = test_dataset['Close'].pct_change()



I think it should be:

Compute GLD returns

test_dataset['gld_returns'] = (test_dataset['Close']-test_dataset["Open"])/test_dataset["Open"]



because the input parameters:

gold_prices['OD'] = gold_prices['Open']-gold_prices['Open'].shift(1)

gold_prices['OL'] = gold_prices['Open']-gold_prices['Close'].shift(1)



they need to know the Open of the current bar, so the value of the return must be the difference between the closing price and of the open of the same bar, i think.



Cheers,

Enrique Abad





 

Hello Enrique, 


  1. The trading logic is as follows:

    We will buy the contract the next day if today's high is greater than the predicted high (Signal = 1). Similarly, we will sell the contract the next day if today's low is less than the predicted low (Signal = -1). Hence shift(1) isn't used while generating signals.



    So, if 'Signal' is 1 or -1 at end of today, we will buy or sell the contract the next day. For the same reason, while calculating the strategy returns, we used 'test_dataset['Signal'].shift(1)' instead of 'test_dataset['Signal']'. 


  2. The input parameters i.e. features for the model help model to predict the dependent variable. The difference between Open & previous day's Open, and Open & previous day's Close are 2 out of 7 features we have used to train the model. 

    This has nothing to do with the way the returns are calculated. Here, the returns calculated are a simple price change which can be easily calculated by using the pct_change() method on the 'Close' price.



    Hope this helps!