One of the Classic Strategies: Understanding Grid Trading

What is grid trading?

The grid trading method, also called the fishing net trading method, is a strategy in which a grid is drawn for the target price while the target price is constantly fluctuating, and when the market price touches a certain grid line, it is a strategy to make profits by buying low and selling high.

  • Applicable scenarios: In volatile market conditions, buy when the price falls and sell when the price rises.

  • Classification: According to the long and short tendency, it can be divided into long grid, short grid and neutral grid, that is: the long grid will only open long and flat longs, which is suitable for the volatile upward market, and the short grid will only open short Peaceful and short, suitable for concussive downward market conditions. The neutral grid is to open/close short above the market price when the strategy is started, and open long/close long below.

  • Advantages: shock arbitrage. If you judge that there will be a long period of volatile market conditions, you can obtain additional alpha.

  • Disadvantages: High requirements for market judgment. Because it is a counter-trend transaction, if you encounter a unilateral rising market, it is easy to sell out; if you encounter a unilateral falling market, the loss will be larger.

Specific steps of grid trading

The specific steps of grid trading are as follows:

  1. 1. Determine the transaction target. The best price of the selected target changes greatly and the transaction is more active. If the target is inactive and the price fluctuates little, it will be difficult to trigger a transaction.

  2. 2. Determine the center, pressure level and support level of the grid .  Determine appropriate pressure and support levels so that the price can fluctuate between the pressure and support levels most of the time. If the range of the pressure level and support level is too large, it will be difficult to trigger transactions; if the range of the pressure level and support level is too small, transactions will be triggered frequently. In addition to transaction costs, once the support level is broken, the loss may be larger.

  3. 3. Set grid width and quantity .  The number of grids and the width of the grid can be customized

    • * Equal-width grids may lead to premature buying and selling points and lower yields. Setting up grids with unequal widths can avoid this problem, but you may miss buying and selling opportunities.

    • * Commonly used grid design patterns: equal difference grid and proportional grid. The equal-difference grid means that the difference between the price of each two adjacent levels of pending orders is equal, such as 1, 2, 3, and 4; the equal-proportion grid means that the ratio of the prices of each two adjacent levels of pending orders is equal, such as 1, 2, 4, 8

  4. 4. When the price touches the grid line, if it is higher than the buying price, sell x lots every time it goes up; if it is lower than the buying price, buy x lots every time it goes down.

Code

The core code is as follows:

def next(self):
        grid = pd.cut([self.data.close[0]], self.band, labels=self.labels)[0]

        if np.isnan(grid):
            self.log('价格波动超过网格范围: %.2f' %(self.data.close[0]))
            return

        # 价格上涨
        if grid > self.last_grid:
            grid_range = [self.last_grid, grid]
            if self.last_grid == 0:
                self.last_grid = grid
                return
            if self.last_grid != 0:
                if grid_range != self.last_grid_range:
                    self.last_grid = grid
                    self.last_grid_range = grid_range
                    if self.position.size > 0:
                        self.log('SELL CREATE %.2f, cur position: %d' % (self.data.close[0], self.position.size))
                        self.sell(size=self.p.stake)

        # 价格下跌
        if grid < self.last_grid:
            grid_range = [grid, self.last_grid]
            if self.last_grid == 0:
                self.last_grid = grid
                return
            if self.last_grid != 0:
                if grid_range != self.last_grid_range:
                    self.last_grid = grid
                    self.last_grid_range = grid_range
                    if self.position.size < 10:
                        self.log('BUY CREATE %.2f, cur position: %d' % (self.data.close[0], self.position.size))
                        self.buy(size=self.p.stake)  

illustrate:

  • If the target has not been traded, it means that the price of the target has exceeded the set grid range at this time, and the grid pressure level and resistance level can be adjusted; if there is only a temporary transaction, if it does not exceed the range, the grid width and quantity can also be adjusted.

  • How to record whether the price breaks the grid line? Use the cut function provided by the pandas library to express the grid area where the current price is located. When the grid area changes, it means that the price breaks through a grid line

Conclusion & Communication

Follow the WeChat public account: Zhuge Shuo Talk for more content. At the same time, you can also get an invitation to join the quantitative investment seminar group to communicate and discuss with many practitioners and technical experts. The number of places is limited, so don’t miss it.

Writing articles is not easy. If you think this article is helpful to you, please give it a thumbs up and forward it to give me the motivation to keep writing good articles.

reference

Guess you like

Origin blog.csdn.net/richardzhutalk/article/details/126334858