The resource loading... loading...

Single-commodity retail strategy V2.0_ annualised by 130%

Author: Quantification of district classes, Date: 2019-10-18 18:01:30
Tags: Grid

It has been estimated that 80% of the time, in terms of market trends, the market is in a turbulent trend. The grid strategy is a strategy for dealing with turbulence. The grid strategy is implemented in a variety of ways, but in essence it is to set a relatively stable leverage strategy, so long as the price fluctuation meets the conditions of the strategy. The zone master today introduces a quantitative strategy, similar to grid trading, but based on this, with some improvements, which can reach an annualized return of 130% in some cases. The zone master calls it the small-selling strategy, which is to imagine the operator is a small-selling operator. He targets a fair price in the market, once higher than the fair price; he puts out the goods, below the fair price, he buys the goods. Here are some steps: Step one: look at the volatility of the commodity, find a fair price indicator, which can be an average line (i.e. 20 cycles of the 30-minute line) or a Brin median line; buy 5 positions by default, and record the transaction price; Step two: buy if below 3% of the fair price indicator; sell if above 3% of the fair price indicator; and record the transaction price; If the price of the transaction is less than 5% of the previous transaction price, the purchase order will be resubmitted; if the price of the transaction is more than 5% of the transaction price, the sale order will be resubmitted; and the transaction price will be recorded; Step three: Depending on the current position, decide how to operate when receiving the buy order; the position fluctuates between 10% and 9%, beyond this range no operation, but the transaction price can be recorded; only buy 2 positions or 1 position per operation, avoiding infinite operations. This is why the strategy is called the single-commodity retail strategy, because the retail area has only one commodity. As a follow-up to the improvement, we hope to increase the number of commodity rotations, even back-to-back blank hedging. Let's run a backtest, first we choose the volatile ETH as the commodity, the cycle is from January 1 to October 10, 2019 and the range has ups and downs. As you can see, the retrospective effect is good, reaching an annualization rate of 130% and creating a transaction fee of 1,651 yuan, which should be a strategy that is welcomed by both exchanges and traders. The disadvantage is that the maximum drawback is slightly higher, reaching about 30%; the main drawback is sent at the stage when the commodity drops significantly. It is also understandable to think, because this strategy is targeted at trading commodities, if the price of the commodity falls, then it may be that some goods have been dumped at a high level, and have not yet been released to the market, and should be able to replenish with the length of time. After registering, you can search the Internet of Things blockchain at https://m.bihu.com/signup?i=1ewtKO&s=4&c=4 and contact the author's block manager. It is also important to remind the reader that this strategy is also related to the choice of commodities. Try to choose commodities that are highly volatile and appear to appreciate in the long term. On the other hand, if you combine commodities to adjust the parameters, then even smaller fluctuations should not be a problem, as long as they can cover the processing fee.


/*backtest
start: 2019-01-01 00:00:00
end: 2019-10-10 00:00:00
period: 1d
exchanges: [{"eid":"OKEX","currency":"ETH_USDT","stocks":0}]
args: [["OpMode",1,10989],["MaxAmount",1,10989],["TradeFee",0.001,10989]]
*/
//注册币乎后https://m.bihu.com/signup?i=1ewtKO&s=4&c=4
//搜索 物联网区块链 可以联系到作者区班主
function main() {
    var isInit = 1; //表示初始态
    var allAmount;
    var cashRatio;
    var initAccount = _C(exchange.GetAccount);
    var lastPrice;
    var wantRatio;
    var wantOper=0;//期待的操作,0不操作,1买入,-1卖出
    Log(initAccount);
    var mhigh;
    var mlow;
    while (true) {
        var mrecords = exchange.GetRecords(PERIOD_M30);
        //一定周期内的高低点
        mhigh=TA.Highest(mrecords, mnum, 'High');
        mlow=TA.Lowest(mrecords, mnum, 'Low');
        
        var midLine = (mhigh+mlow)/2;
        var ticker = _C(exchange.GetTicker);
        var account = _C(exchange.GetAccount);
        var nowPrice=ticker.Sell;
        var obj;
        
        if (isInit == 1) {  //初始化状态为默认仓;     
            //账户现金乘以比例,除以当前价格,保留小数前3位
            obj = $.Buy(_N(account.Balance * initRatio / ticker.Sell, 3));
            if (obj) { //如果购买成功,就标志开仓
                      opAmount = obj.amount;
                      lastPrice = obj.price;
                      isInit=0; //初始化成功
                      account = _C(exchange.GetAccount);
                      Log("初始开仓:购买量", opAmount);
                      Log("目前持币数", account.Stocks);
            }
        }else{ //日常操作检测
            if(nowPrice>midLine*1.03||nowPrice>lastPrice*1.07){
                wantOper=-1;
            }else if(nowPrice<midLine*0.97||nowPrice<lastPrice*0.93){
                wantOper=1;
            }else{
                wantOper=0;
            }
            
            if (wantOper==-1) { //离市平仓
                lastPrice=nowPrice; //不管买没买成功都修改了一下价格
                allAmount=account.Balance+account.Stocks*ticker.Sell; //计算出总金额
                cashRatio=parseFloat((account.Balance/allAmount).toFixed(3));
                
                if(cashRatio>0.9){ //现金比例大于0.9,不做任何操作 
                    wantRatio=0;
                }else if(cashRatio>0.8){ //现金比例超过0.8,可以抛一成仓 
                    wantRatio=0.1;
                }else{ //其他情况都可以抛掉2成仓
                    wantRatio=0.2;
                }
                
                obj = $.Sell(_N(allAmount*wantRatio/ticker.Sell, 3)); 
                if(obj){
                    opAmount = obj.amount;
                    Log("平仓:卖出量",opAmount);
                    nowAccount = _C(exchange.GetAccount);
                    Log("目前现金",nowAccount.Balance,"盈利",allAmount - initAccount.Balance);
                }
            }else if (wantOper==1) { //开仓买入
                lastPrice=nowPrice; //不管买没买成功都修改了一下价格
                allAmount=account.Balance+account.Stocks*ticker.Sell; //计算出总金额
                cashRatio=parseFloat((account.Balance/allAmount).toFixed(3));
                //Log("准备买入",cashRatio);
                if(cashRatio<0.1){ //现金比例小于0.1,已没钱买了
                    wantRatio=0;
                }else if(cashRatio<0.2){ //现金比例超过0.2,可以买一成仓 
                    wantRatio=0.1;
                }else{ //其他情况都可以买2成仓
                    wantRatio=0.2;
                }
                
                obj = $.Buy(_N(allAmount*wantRatio/ticker.Sell, 3)); 
                if(obj){
                    opAmount = obj.amount;
                    Log("买入:买入量",opAmount);
                    nowAccount = _C(exchange.GetAccount);
                    Log("目前现金",nowAccount.Balance,"盈利",allAmount - initAccount.Balance);
                }
            }
        }
        Sleep(Interval*1000);
    }
}

Related

More

kangx1987How about a retest?