The VWAP (Volume Weighted Average Price) strategy is implemented as a class called VWAP, which inherits from the IStrategy class. It involves calculating various indicators and making buy and sell decisions based on certain conditions. In the method populate_indicators, the strategy calculates and adds several indicators to the input dataframe.
These indicators include:
vwap_low, vwap, and vwap_high: These are the lower, middle, and upper bands of the Volume Weighted Average Price (VWAP) calculated using a 20-day period.
tcp_percent_4: This represents the percentage change of the top price within the last 4 periods.
cti: This is the Commodity Channel Index (CCI) indicator calculated with a length of 20. rsi: This is the Relative Strength Index (RSI) indicator calculated with a time period of 14. rsi_84 and rsi_112: These are additional RSI indicators calculated with time periods of 84 and 112, respectively. bb_lowerband, bb_upperband, and bb_middleband: These are the lower, upper, and middle bands of the Bollinger Bands indicator calculated with a window of 20 and standard deviations of 2. The populate_buy_trend method determines the buy signals based on the following conditions:
The closing price is below the vwap_low. The tcp_percent_4 is greater than 0.04. The cti is less than -0.8. The rsi is less than 35. The rsi_84 is less than 60. The rsi_112 is less than 60. The volume is greater than 0. When these conditions are met, the corresponding rows in the dataframe are marked with a value of 1 in the 'buy' column. The populate_sell_trend method marks all rows in the dataframe with a value of 1 in the 'sell' column. Overall, the VWAP strategy involves using a combination of VWAP, CCI, RSI, and Bollinger Bands indicators to generate buy and sell signals based on specific conditions related to price, volume, and indicator values.