In hedging strategies, there are various types of hedging: cross-market hedging, cross-period hedging, etc. Today we will talk about cross-currrency hedging, which is precisely the cross-currency hedging strategy in quantitative trading of blockchain assets. Generally, the subject matter of a hedging transaction is the same, while cross-currency hedging involves buying and selling 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-currency hedging, because the price difference of different currencies is not very intuitive to observe, and the price ratio is usually used as the buying and selling price.

For example:
Trading pair A: LTC_USDT
Trading pair B: ETH_USDT

Distribute the opening positions according to the price ratio value of Price of Trading pair A/Price of Trading pair B. The larger the proportion is, the more we will sell A and buy B. If the proportion decreases, buy A and sell B. The equivalent USDT amount of each hedging is actually a strategy for grid trading based on the relative price of LTC/ETH. The strategy idea is not complicated. However, it should be noted that this kind of hedging portfolio actually uses ETH as the anchor price currency to price LTC. The anchored price is likely to go out of the unilateral trend. Although most of the time it may be a volatile trend, this risk needs to be considered and noted.

It is easy to write a strategy prototype by using the FMZ Quant Trading platform:
When the strategy code runs, it needs to reference

and


"Plot library": https://www.fmz.com/strategy/27293
"Digital currency spot trading library": This comes with the template bar 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

// parameters
var numPoint = 100        // Number of nodes
var distance = 0.08       // Proportional distance
var amountPoint = 100     // Node amount in 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("对冲,价格比", 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 backtesting, we can initially verify the strategy ideas

Use the default backtesting settings:


It can be seen that only a few dozen lines of code were used to construct a strategy of your own ideas. It is very easy to implement a prototype of ideas on the FMZ Quant Trading platform. According to the above figure, this price proportion fluctuates most of the time, but there will be a certain trend. The optimization direction can be position control during hedging or adding a certain trend identification.
In terms of position control, you can increase the hedging amount of each hedging 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,          // 8% of amountPoint per increment
            isHold : false,
        }
        arrHedgeList.push(point)
    }
    isFirst = false
}

In this way, the relatively heavy positions can be concentrated in the position with a high price proportion, so as to avoid large positions occupied when the price proportion is low.
Of course, such cross-currency hedging is very risky. If the price of one currency continues to rise relative to the price of another currency, floating losses will occur. Therefore, cross-currency hedging requires a stronger correlation between the two currencies.

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

Leave a Reply

Your email address will not be published. Required fields are marked *