In the Strategy return section, it is using cumulative sum instead of product:
"…Once we calculate the percentage returns of the model, we will take a cumulative sum of all these returns on the test data to measure the overall performance of the model…"
final_return = np.nancumsum(strategy_returns)*100
Shouldn't it be (returns+1).cumprod() where the return is already multiplied with trend or signal.
Hi Soumaneel Konar,
Yes, you are correct cumprod gives more accurate results than np.nancumsum. Thanks for pointing out the error. We will make changes to our notebook also.
Thanks,
Danish
Thank you.
One more thing plz look into in the same notebook: DNN Trading Strategy Code
Labels / Signals are created using shift(-5) but the strategy return has been calculated using shift(-1).
Is this correct? Because prediction will correspond to the labels that have been created right?
If the labels are based on data 5 days ahead, the prediction will also be 5 days ahead. Isn't it?
Below is the code from the notebook:
Label / Signal creation:
y = np.where(data.Close.shift(-5) > data.Close, 1, 0)
Return calculation:
market_returns = pd.Series(data.Close.shift(-1).iloc[-test_size:].pct_change().values)
strategy_returns = pd.Series(predict_trend*market_returns)
We are using a Neural network for predicting signals and we are using shift(-5) for generating target values. Using shift(-5) can help us recognize patterns further ahead. But in the case of calculating strategy returns, we can only use shift(-1) because we want to calculate returns in each consecutive period.