Cross currency hedging strategy in blockchain asset quantification transaction

Keywords: Blockchain

In a hedging strategy, there are various types of hedging. Cross market hedge, cross period hedge and so on. Today, let's talk about cross variety hedge, which is exactly the cross currency hedge strategy in the quantitative transaction of blockchain assets. Generally, the subject matter of hedging transactions is the same, while cross currency hedging is to buy and sell different subject matter. When hedging the same variety, we can use the price difference as the buying and selling price in the hedging transaction. For the simplest cross market hedging of the same variety, the price difference fluctuates repeatedly within a certain range. The price difference cannot be used as the buying and selling price for cross product hedging, because the price difference of different products is not very intuitive to observe, and the price ratio is usually used as the buying and selling price.

For example:
A transaction pair: LTC? Usdt
Transaction pair B: eth uusdt

According to the price ratio value of A transaction pair / b transaction pair, open positions in A decentralized way. The larger the ratio, the more we have to sell A and buy B. On the contrary, if the proportion becomes smaller, buy A and sell B. The equivalent USDT amount of each hedging is actually A strategy for grid Trading Based on the relative price strength of LTC/ETH. The strategy is not complicated. However, it should be noted that this hedging portfolio is actually to use ETH as the anchor price currency to price LTC. This anchored price is likely to go out of the unilateral trend. Although it is said that most of the time it may be A volatile trend, this risk needs to be considered and noted.

Using the inventor quantitative trading platform, it is easy to write a strategy prototype:
Policy code needs to be referenced when it runsSum
Line drawing library: https://www.fmz.com/strategy/27293
Digital currency spot transaction class library: This is provided in the template column when each user creates a new strategy.

/*backtest
start: 2019-05-01 00:00:00
end: 2019-11-04 00:00:00
period: 1m
exchanges: [{"eid":"OKEX","currency":"LTC_USDT","balance":100000,"stocks":30},{"eid":"OKEX","currency":"ETH_USDT","balance":100000,"stocks":30}]
*/

/*
A exchanges[0] : EOS_USDT   
B exchanges[1] : ETH_USDT
*/

var Interval = 500

// parameter
var numPoint = 100        // Node number
var distance = 0.08       // Proportional spacing
var amountPoint = 100     // Node amount, unit: USDT
var arrHedgeList = []

function main () {
    var isFirst = true
    while(true) {
        var rA = exchanges[0].Go("GetTicker")
        var rB = exchanges[1].Go("GetTicker")

        var tickerA = rA.wait()
        var tickerB = rB.wait()

        if (tickerA && tickerB) {
            var priceRatioSell = tickerB.Buy / tickerA.Sell     // B sell , A buy
            var priceRatioBuy = tickerB.Sell / tickerA.Buy      // B buy , A sell
            
            if (isFirst) {
                for (var i = 0 ; i < numPoint ; i++) {
                    var point = {
                        priceRatio : priceRatioSell + (i + 1) * distance,
                        coverRatio : priceRatioSell + i * distance,
                        amount : (0.08 * i + 1) * amountPoint,
                        isHold : false,
                    }
                    arrHedgeList.push(point)
                }
                isFirst = false
            }

            for (var j = 0 ; j < arrHedgeList.length; j++) {
                if (priceRatioSell > arrHedgeList[j].priceRatio && arrHedgeList[j].isHold == false) {
                    // B sell , A buy
                    Log("Hedging, price ratio", priceRatioSell, "#FF0000")
                    $.Buy(exchanges[0], arrHedgeList[j].amount / tickerA.Sell)
                    $.Sell(exchanges[1], arrHedgeList[j].amount / tickerB.Buy)
                    arrHedgeList[j].isHold = true
                    LogStatus(_D(), exchanges[0].GetAccount(), "\n", exchanges[1].GetAccount())
                    $.PlotLine("ratio", (priceRatioSell + priceRatioBuy) / 2)
                    break 
                }

                if (priceRatioBuy < arrHedgeList[j].coverRatio && arrHedgeList[j].isHold == true) {    
                    // B buy , A sell
                    Log("Hedging, price ratio", priceRatioBuy, "#32CD32")
                    $.Sell(exchanges[0], arrHedgeList[j].amount / tickerA.Buy)
                    $.Buy(exchanges[1], arrHedgeList[j].amount / tickerB.Sell)
                    arrHedgeList[j].isHold = false
                    LogStatus(_D(), exchanges[0].GetAccount(), "\n", exchanges[1].GetAccount())
                    $.PlotLine("ratio", (priceRatioSell + priceRatioBuy) / 2)
                    break
                }
            }
        }
        Sleep(Interval)
    }
}

Through back testing, we can initially verify the strategic thinking

Use the default backtest settings:

It can be seen that only tens of lines of code are used to construct a strategy of their own ideas. In the inventor's quantitative trading platform, it is very easy to implement a prototype of ideas. From the above figure, we can see that the price ratio is fluctuating most of the time, but there will be a certain trend trend trend. The optimization direction can be position control during hedging or adding a certain trend identification.

In the aspect of position control, you can increase the offset amount of each offset node, for example, in the code:

if (isFirst) {
    for (var i = 0 ; i < numPoint ; i++) {
        var point = {
            priceRatio : priceRatioSell + (i + 1) * distance,
            coverRatio : priceRatioSell + i * distance,
            amount : (0.08 * i + 1) * amountPoint,          // Increase 8% of amountPoint each time
            isHold : false,
        }
        arrHedgeList.push(point)
    }
    isFirst = false
}

In this way, the relatively heavier positions can be concentrated in the position with higher price proportion, so as to avoid occupying positions when the price proportion is low. Of course, such cross species hedging is very risky. If the price of one currency keeps rising relative to that of the other currency, there will be floating losses. Therefore, cross species hedging requires a stronger correlation between the two varieties.

This strategy is only an initial DEMO, which can be further improved and optimized.

Posted by kark_1999 on Wed, 26 Feb 2020 18:55:14 -0800