गतिशील संतुलन का नया संस्करण

लेखक:अच्छाई, बनाया गयाः 2018-08-28 12:05:37, अद्यतन किया गयाः 2019-12-03 17:26:27

गतिशील संतुलन का नया संस्करणwww.fmz.comपिछले सप्ताह मैंने एक बहुत ही प्रभावी और उच्च रिटर्न ट्रेडिंग रणनीति पेश की, जिसे dynamic balance strategy कहा जाता है। यह एक बहुत ही क्लासिक ट्रेडिंग रणनीति है जो महान वॉरेन बफेट के संरक्षक, बेंजामिन ग्राहम से आई है, जिन्होंने एक बार पुस्तक <<द इंटेलिजेंट इन्वेस्टर>> में एक ट्रेडिंग मॉडल का उल्लेख किया था जिसमें स्टॉक और बॉन्ड गतिशील रूप से संतुलित होते हैं।

मूल रणनीति को निम्न पृष्ठ पर देखा जा सकता हैःhttps://fmzquant.quora.com/Blockchain-Quantitative-Investment-Series-Dynamic-Balance-Strategy

आज, हमारी टीम के अनुभवी प्रोग्रामर ने इस रणनीति के कोडिंग भाग को और भी छोटा और समझने में आसान बना दिया है।

var Coin = ''
var Fiat = ''
var RefreshLoop = 0
var Account = ''
var Depth = ''
var Orders = ''
var BuyWeighted = 0
var SellWeighted = 0
var MidPrice = 0
var InitialBalance = exchange.GetAccount().Balance + exchange.GetAccount().Stocks * exchange.GetDepth().Bids[0].Price

function CancelPendingOrders() {
    for (var j = 0; j < Orders.length; j++) {
          exchange.CancelOrder(Orders[j].Id, Orders[j])}
}

function UpdateAll() {
    Account = exchange.GetAccount()
    Depth = exchange.GetDepth()
    Orders = exchange.GetOrders()
    //Log("UpdateAll")
}

function UpdatePrice() {
    //MidPrice = (Depth.Asks[0].Price+Depth.Bids[0].Price)/2
    BuyWeighted = Depth.Asks[0].Price * (1+SPREAD/100)
    SellWeighted = Depth.Bids[0].Price * (1-SPREAD/100)
    //Log("UpdatePrice")
}

function onTick(){
    // Refresh account balance and market data
    //Log("UpdateAll")
    UpdateAll()
    var Buy = Depth.Asks[0].Price
    var Sell = Depth.Bids[0].Price
    
    // Calculate the weighted price
    //Log("UpdatePrice")
    UpdatePrice()
    
    // Check current order that exist
    if (Orders.length==2){
        return
    }
    if (Orders.length>2){
        CancelPendingOrders()
    }
    // Processing a single order
    if (Orders.length==1){
        Order = Orders[0]
        Price=Order.Price
        if (Order.Type==0){
            if (Price/(1-SPREAD/100) > Sell){
                return
            }else{
                CancelPendingOrders()
                UpdateAll()
            }
        }else{
            if (Price/(1+SPREAD/100) < Buy){
                return
            }else{
                CancelPendingOrders()
                UpdateAll()
            }
        }
    }
    
    // Calculate the value of the position held
    var ValueByBuy = Account.Stocks * BuyWeighted
    var ValueBySell = Account.Stocks * SellWeighted
    Log(Coin + " Value By Weighted Ask - " + Fiat +" Balance : " + (ValueByBuy-Account.Balance))
    Log(Fiat + " Balance - " + Coin +" Value By Weighted Bid : " +(Account.Balance-ValueBySell))
    //Log(ValueByBuy)
    //Log(ValueBySell)
    
    // The value of the currency is higher than the price of coin. sell the coin.
    if (ValueByBuy > Account.Balance){
        ToBeSold = (ValueByBuy - Account.Balance)/2/BuyWeighted
        if (ToBeSold > AMOUNT_MINIMUM){
            ToBeSold = _N(Math.floor(ToBeSold / AMOUNT_INCREMENT) * AMOUNT_INCREMENT)
            Log("Will be sold " + Coin + " Quantity:" + ToBeSold)
            exchange.Sell(BuyWeighted,ToBeSold)
        }
    }
    // The value of the currency is smaller than the coin. buy the coin.
    if (ValueBySell < Account.Balance){
        ToBeBought = (Account.Balance - ValueBySell)/2/SellWeighted
        if (ToBeBought > AMOUNT_MINIMUM){
            ToBeBought = _N(Math.floor(ToBeBought / AMOUNT_INCREMENT) * AMOUNT_INCREMENT)
            Log("Will be brought " + Coin + " Quantity:" + ToBeBought)
            exchange.Buy(SellWeighted,ToBeBought)
        }
    }
    Log(Fiat + " Quantity:" + Account.Balance)
    Log(Coin + " Quantity:" + Account.Stocks)
    
    RefreshLoop = RefreshLoop+1
    if (RefreshLoop>60) {
        var Profit = _N(Account.Stocks*Sell) + _N(Account.Balance) - _N(InitialBalance)
        LogProfit(Profit)
        RefreshLoop = 0
    }
}
function main(){
    var Pair = exchange.GetCurrency()
    LogReset()
    LogProfitReset()
    LogProfit(0)
    UpdateAll()
    CancelPendingOrders()
    Coin = Pair.split("_")[0]
    Fiat = Pair.split("_")[1]
    while (true){
        try {
            onTick()
        } catch (err) {
            Log(err)
        }
        Sleep(DELAY*1000)
    }
}

अधिक

छोटे सपनेअच्छा!