Logo

dev-resources.site

for different kinds of informations.

Thoughts on asset movement through contract hedging strategy

Published at
5/11/2024
Categories
contract
strategy
fmzquant
asset
Author
fmzquant
Categories
4 categories in total
contract
open
strategy
open
fmzquant
open
asset
open
Author
8 person written this
fmzquant
open
Thoughts on asset movement through contract hedging strategy

Recently, there has been a lot of news about the digital currency market and the exchange. For a time, all currency friends were in a state of panic, worrying about the security of their blockchain assets. There are also many small advertisements of 10% and 20% discount for idle second-hand currencies in various currency market groups. There are many kinds of strategies of "seeking to lose money steadily while making money steadily". Many users also teased "If there is a stable moneymaker, why do you want a stable moneyloser?"
It is true that both making stable profits and losing stable money are money printer, which is not easy to find.
Forgive me for my poor English.

However, there are still some unstable ones. For example, through contract hedging, we can make profits while making losses as much as possible.

DEMO strategy

/*backtest
start: 2020-09-30 00:00:00
end: 2020-10-19 00:00:00
period: 1d
basePeriod: 1m
exchanges: [{"eid":"Futures_OKCoin","currency":"BTC_USD"},{"eid":"Futures_HuobiDM","currency":"BTC_USD"}]
*/

var step = 20    // Step length of adding position price

function main() {
    var pos1 = []
    var pos2 = []
    var ct = "quarter"                         // For example, quarterly contract
    exchanges[0].SetContractType(ct)
    exchanges[1].SetContractType(ct)
    var diff = 0

    while (true) {
        var r1 = exchanges[0].Go("GetDepth")   // Exchange A
        var r2 = exchanges[1].Go("GetDepth")   // Exchange B
        var depth1 = r1.wait()
        var depth2 = r2.wait()

        if(depth1.Bids[0].Price - depth2.Asks[0].Price > diff) {
            if(pos1.length == 0 && pos2.length == 0) {
                var info1 = $.OpenShort(exchanges[0], ct, 10)
                var info2 = $.OpenLong(exchanges[1], ct, 10)
                pos1 = _C(exchanges[0].GetPosition)
                pos2 = _C(exchanges[1].GetPosition)
                diff = depth1.Bids[0].Price - depth2.Asks[0].Price
            } else if(depth1.Bids[0].Price - depth2.Asks[0].Price > diff + step) {
                var info1 = $.OpenShort(exchanges[0], ct, 10)
                var info2 = $.OpenLong(exchanges[1], ct, 10)
                pos1 = _C(exchanges[0].GetPosition)
                pos2 = _C(exchanges[1].GetPosition)
                diff = depth1.Bids[0].Price - depth2.Asks[0].Price
            }
        }

        if(pos1.length != 0 && pos1[0].Profit < -0.001) {
            var info1 = $.CoverShort(exchanges[0], ct, pos1[0].Amount)
            var info2 = $.CoverLong(exchanges[1], ct, pos2[0].Amount)
            pos1 = _C(exchanges[0].GetPosition)
            pos2 = _C(exchanges[1].GetPosition)
            diff = 0
        }
        LogStatus(_D(), diff)
        Sleep(500)
    }
}
Enter fullscreen mode Exit fullscreen mode

Image description

Strategy logic:
The strategy starts to initialize the position variables pos1 and pos2 as empty arrays. The strategy enters the main loop. At the beginning of each loop, the depth data (order book data) of the contracts of the two exchanges are obtained to calculate the price difference. If the price difference continues to expand and beyond the "last price difference plus a step length", continue hedging and adding positions. When the position is held, it is detected that the position loss of the first exchange exceeds a certain value (such as -0.001), then close the position. Repeat in this way.

The principle is very simple, that is, when the price difference is large, then de-hedge. When waiting for the loss of the expected loss of the exchange position, close the position. If the price difference continues to expand, continue to add positions to hedge until the expected loss of the exchange position loss. The important parameters are: the amount of loss to close the position, the step length of adding position price difference, and the hedging amount.

The strategy is rather rudimentary, just to verify the idea, the real bot is not available. There are still many issues to be considered for a real bot, for example, whether the contract to be traded is currency standard or U standard, and whether the multipliers of different contracts in exchanges A and B are the same.

In this way, one exchange will lose money, and the loss part will become the profit part of another exchange (price difference, there may be hedging loss, that is, the loss is more than the profit). The strategy adopts a futures trading class library, $.OverShort, $.OpenShort, these are the interface functions of the template. To run the above DEMO, you need to reference this class library.

The above strategy prototype is just the simplest exploration, and there may be more details to consider in actual operation, for example, the amount of positions can be designed to incremental. This is just an example here. Similar strategies should be able to optimize more, and experts are welcome to give suggestions.

From: https://blog.mathquant.com/2022/12/19/thoughts-on-asset-movement-through-contract-hedging-strategy.html

contract Article's
30 articles in total
Favicon
Contract Management Software on Microsoft 365 SharePoint Online
Favicon
How Deep Storage Data Transforms Smart Contract Migration
Favicon
Solving Cross-Execution Issues in Pact Testing with Kafka and Message Queues
Favicon
Smart contracts on the Blockchain -Complete Guide
Favicon
Building Custom Request Filters for PactJs Verifications in Express and Non-Express Environments
Favicon
Handling Pact Breaking Changes Dynamically in CI/CD
Favicon
Strengthening Pact Contract Testing with TypeScript and Data Abstraction
Favicon
My thoughts and notes about Consumer Driven Contract Testing
Favicon
OKX futures contract hedging strategy by using C++
Favicon
"C++ version of OKX futures contract hedging strategy" that takes you through hardcore quantitative strategy
Favicon
Detailed Explanation of Perpetual Contract Grid Strategy Parameter Optimization
Favicon
Price Performance After the Currency is Listed on Perpetual Contracts
Favicon
Thoughts on asset movement through contract hedging strategy
Favicon
Realize an idea with 60 Lines of Code -- Contract Bottom Fishing Strategy
Favicon
A brief explanation of why it is not feasible to achieve asset movement on OKX through a contract hedging strategy
Favicon
Earn 80 Times in 5 Days, the Power of High-frequency Strategy
Favicon
WordPress Maintenance Contract: Unlock Smart Site Management
Favicon
New gigs-
Favicon
Deploying a Soroban Contract from a .wasm File using js-stellar-sdk
Favicon
RJP Solidity Contract UDT
Favicon
A centralised platform for contract labour in the healthcare industry: Ensuring efficiency and compliance
Favicon
Find contract on France
Favicon
Streamlining automotive industry operations with Ascent Contract Labour Management System
Favicon
The Advantages of Contract Testing: Comparing PACT, Spring Cloud Contract, and Custom Scalable Solutions
Favicon
Advanced Contract Testing Solution with High Scalability
Favicon
Maximizing Success in Smart Contract Auditing Contests: Choosing the Right Approach
Favicon
Building a ballot contract using Soroban plataform and Rust SDK
Favicon
Hợp đồng điện tử vô hiệu
Favicon
Upgradable Proxy Contracts 101 (Advanced)
Favicon
2 Contract Token TRC20 TRON TRX

Featured ones: