The price-Volume-based trading strategy is used to generate a short signal based on the movement in price and volume in the recent past. The past time frame could be 3, 5, 7, 14-Days but the best returns recorded on backtesting turn out to be 3-Days.
If the current closing price is less than the last 3-Days of the simple average closing price of that stock and the current volume is also less than the last 3-Days of the simple average volume of that stock, the engine generates a short signal on that particular stock.
This means one has to short sell that stock at the opening price on the very next day and square-off the position at the close. We would be able to generate positive returns if next day stock closes below its opening price.
Please refer to Extract Historical Stock Data using API to extract the historical data of the stocks. Since it contains all the necessary stock information, based on that it will be easy for us to design and formulate this trading strategy.
Let us understand how to identify profitable trades and execute our trading strategy-
Assuming that we have already extracted the historical stock data and stored it in a Python dictionary, we apply this strategy only on 100 constituents available in the NIFTY 100 Index so as to keep it simple for now (by doing this, we would be able to limit the number of stocks, the investment involved, transaction and slippage costs).
Today's Date is 28-01-2021 (close of business).
The date of Implementing the Strategy is 29-01-2021.
3-Days of data required to analyze and identify the profitable trades- would be from 25-01-2021 to 28-01-2021 (26th being Regional Holiday).
Today's closing price and volume are already stored in the dictionary and readily available.
To calculate a 3-Days simple average of the closing price and volume for all the stocks in one go, we will place our code inside a loop function that will refer to each item specified in the ticker list. An empty Pandas DataFrame is defined so that calculated data points for each item can be stored corresponding to the respective ticker symbol and later, it can be used to identify the stocks for action.

Just to present the calculated data points from that DataFrame-

Here is the most interesting part-
If today's closing price of the stock is less than the last 3-Days simple average of closing price (inclusive of today's price) and if today's volume of the stock is also less than the last 3-Days simple average of volume (inclusive of today's volume), we will go short on that stock on the next day at the opening price and buyback at the close. We would be able to generate positive returns if next day stock closes below its opening price.
We have the below code to identify the stocks-

To see the stocks which are identified by the above engine, we simply specify the list name and run the code-

(As per this strategy, we must short sell all the stocks present in the list at the opening price the very next day and square off the positions at the close. On average, we would be able to generate positive returns.)
Next Date Performance
If we look at the performance of this strategy on the next trading day (in our case, 29-01-2021) with actual data, assuming that we have successfully taken a short position in all the above-identified stocks, the return generated is approximately 2.63%. Results are as below-

Since the returns calculate above are in decimals, we calculate the total positive, total negative, and net percentage return as shown below-

(One can also look at the percentage returns achieved in each individual stock by specifying the DataFrame name "nifty100_ticker_spot_hist2d_df" and run the code.)
We have already performed backtest and concluded that- On any day if the market experience a gap-down opening then there is a high probability that we may end up having negative returns on that particular day. To overcome this gap-down situation, we can improvise our strategy by short-selling the stock only when if the price on the next trading day goes above the previous closing price and buyback at the close.
However, after backtesting this strategy for the entire year of 2020, the annualized return generated is massive.
Why not you backtest the same and post the results in the comment section. Also, let us know what do you think!
Hozzászólások