Volume Reversal Strategy Python Notebook

In the course Quantitative Trading Stratigies and Models there is an Notebook coded for Volume Reversal strategy there I have lot of doubts in cells 12 and 13, like why are columns 'c_signal' and 'exit' are required and what logic is implemented in cell 13,

In cell 12 we are initializing two new columns that we will use later to verify the already exisitng position and the number of days since the trade execution.

In cell 13 of code, we implement the core of the strategy. Here we will check for the last entry signal, if the signal is more than 5 days old, then we exit the position, else we will continue to hold it until the signal is 5 days old or a counter signal is generated.

Let us understand what we do in each of the if statements below:

First, we check if a new signal is generated, if it is then we will assign the c_signal column equal to the new signal, and then we update the exit criterion according to the signal generated. In this case, we will check if the signal is 1 if it is so, then we will mark the exit count as 1 otherwise, we will mark it as -1.

Next, we will check if the entry signal is same as the existing position. If it is so, then we will update the exit criterion depending on the position. For example, if you are already long then your c_signal would be 1, hence it will be incremented by 1. If you are short then your c_signal is -1 and your exit will be reduced by 1.

After this, we will update the exit criterion for an already existing long trade. We check if the exit value of the c_signal is less 5 days old, if this is the case then we verify if the continuing signal is same as the previous days then we increment the exit by 1.

Just as in the above step, we will update the exit criterion for an already existing short trade.

Next, we will update the exit criterion to 0 on the fifth day after entering the trade. This is one of the conditions of the strategy and accordingly, we will close all positions on their 5th day.

Thanks Varun will analyze the conditions once again.