Cross-currency hedging strategies in blockchain asset quantification

Author: The Little Dream, Created: 2019-11-04 11:44:15, Updated: 2023-10-17 21:25:35

img

Cross-currency hedging strategies in blockchain asset quantification

In hedging strategies, there are various types of hedging. Cross-market hedging, cross-term hedging, etc. Today we will talk about cross-variety hedging, more precisely, cross-currency hedging strategies in blockchain asset quantization trading. The usual items in the hedging transaction are the same, while cross-currency hedging is buying and selling different items. When we hedge the same varieties, we can use the price difference as the buy and sell price in the hedging transaction.

For example: A transaction pair is: LTC_USDT B is for: ETH_USDT

According toA交易对的价格/B交易对的价格This price ratio is a numerical value, a spread position. The larger this ratio is, the more we will sell A and buy B. The inverse ratio rule changes to buy A and sell B. An equal amount of USDT for each hedge is actually a strategy to trade on the grid at a relatively strong price of LTC/ETH. The strategic thinking is not complicated. However, it should be noted that this hedging combination, which is actually using ETH as a fixed-price currency to calculate LTC.

Using the inventor's quantitative trading platform, it is easy to write a strategy prototype: When the policy code runs, it needs to be referenced.imgandimg"Draw Line Library" was created by a group of students.https://www.fmz.com/strategy/27293"Digital currency spot trading library": This is what each user brings with them in the template bar when they create 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

// 参数
var numPoint = 100        // 节点数
var distance = 0.08       // 比例间距
var amountPoint = 100     // 节点金额,单位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("对冲,价格比", 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("对冲,价格比", 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)
    }
}

The first step is to verify a strategic idea by retesting it.

Use the default retesting setting:

img

img

As can be seen, it is very easy to implement a prototype of an idea using only a few dozen lines of code, and the inventor quantifies the trading platform. From the diagram above, this price ratio is mostly volatile, but there is a certain trend direction, and the optimization direction can be for position control when hedging or to join a certain trend recognition.

In the position control aspect, the amount of hedging for each hedging node can be incremented, for example in 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,          // 每次递增amountPoint的8%
            isHold : false,
        }
        arrHedgeList.push(point)
    }
    isFirst = false
}

This allows relatively heavier positions to be concentrated in a position with a higher price ratio, avoiding taking too many positions when the price ratio is lower. Of course, such cross-currency hedging is risky and will result in a buffer if the price of one currency continues to rise relative to another, so cross-currency hedging requires a stronger correlation between the two currencies.

This strategy is just an initial demo and can be modified and optimized.


Related

More