آپ کو تجزیہ کرنے کے لئے لے Sharpe تناسب، زیادہ سے زیادہ ڈراؤونگ، واپسی کی شرح اور حکمت عملی backtesting میں دیگر اشارے الگورتھم

مصنف:لیدیہ, تخلیق: 2022-11-28 16:44:25, تازہ کاری: 2023-09-13 19:42:38

img

آپ کو تجزیہ کرنے کے لئے لے Sharpe تناسب، زیادہ سے زیادہ ڈراؤونگ، واپسی کی شرح اور حکمت عملی backtesting میں دیگر اشارے الگورتھم

حکمت عملی کے کچھ کارکردگی کے اشارے الگورتھم پر اکثر گروپ ممبروں کے ذریعہ تبادلہ خیال کیا جاتا ہے ، اور ایف ایم زیڈ کے اے پی آئی دستاویز میں بھی ایک الگورتھم کا انکشاف کیا گیا ہے۔ تاہم ، تبصرے کے بغیر اسے سمجھنا آسان نہیں ہے۔ اس مضمون میں ، میں آپ کو الگورتھم کا تجزیہ کرنے کے لئے لے جاؤں گا۔ مجھے یقین ہے کہ اس مضمون کو پڑھنے کے بعد آپ کو شارپ تناسب ، زیادہ سے زیادہ کھوج ، واپسی کی شرح اور حساب کتاب کی منطق کے تصورات کی واضح تفہیم ہوگی۔ ہم ماخذ کوڈ کے ساتھ شروع کریں گے ، جو جاوا اسکرپٹ زبان میں لکھا گیا ہے۔ ایف ایم زیڈ کا بیک ٹیسٹنگ سسٹم بھی بیک ٹیسٹنگ کارکردگی کے اعداد و شمار کو خود بخود پیدا کرنے کے لئے اس الگورتھم کو اپناتا ہے۔

واپس تجزیہ تقریب

function returnAnalyze(totalAssets, profits, ts, te, period, yearDays)

https://www.fmz.com/api#Backtestingنظام شارپ الگورتھم

چونکہ یہ ایک حساباتی فنکشن ہے، اس کے لئے ان پٹ اور آؤٹ پٹ ہونا ضروری ہے۔ آئیے پہلے فنکشن کے ان پٹ کو دیکھیں:

totalAssets, profits, ts, te, period, yearDays
  • کل اثاثے یہ پیرامیٹر ابتدائی کل اثاثے ہیں جب حکمت عملی چلتی ہے.

  • منافع یہ پیرامیٹر ایک اہم پیرامیٹر ہے ، کیونکہ اس اصل ڈیٹا کی بنیاد پر کارکردگی کے اشارے کی ایک سیریز کا حساب لگایا جاتا ہے۔ یہ پیرامیٹر مندرجہ ذیل فارمیٹ میں دو جہتی صف ہے۔[[timestamp1, profit1], [timestamp2, profit2], [timestamp3, profit3],..., [timestampN, profitN]]. یہ دیکھا جاسکتا ہے کہ ریٹرن اینالیز فنکشن کو ایسے ڈیٹا ڈھانچے کی ضرورت ہوتی ہے جو ہر وقت واپسی کے تاریخی ترتیب کو ریکارڈ کرے۔ ٹائم اسٹیمپ 1 سے ٹائم اسٹیمپ N دور سے قریب تک کے تاریخی ترتیب میں ہیں۔ ہر وقت کے نقطہ پر منافع کی قیمت ہوتی ہے۔ مثال کے طور پر ، واپسی ریکارڈ میں تیسرا ٹائم پوائنٹ [ٹائم اسٹیمپ 3 ، منافع] ہے۔ ایف ایم زیڈ کے آن لائن بیک ٹیسٹنگ سسٹم میں ، منافع کی صف کے اعداد و شمار کو بیک ٹیسٹنگ سسٹم کے ذریعہ اس فنکشن کو فراہم کیا جاتا ہے۔ یقینا ، اگر آپ خود ہی واپسی کے اعداد و شمار کو ریکارڈ کرتے ہیں اور اس طرح کی صف کی ساخت تشکیل کرتے ہیں تو ، آپ نتائج کا حساب لگانے کے لئے اسے حساب کتاب کی تقریب کو بھی فراہم کرسکتے ہیں۔

  • ٹی ایس بیک ٹسٹ کا آغاز ٹائم اسٹیمپ۔

  • ٹی بیک ٹسٹ کے اختتام کا ٹائم اسٹیمپ۔

مدت ملی سیکنڈ کی سطح پر حساب کی مدت.

  • سالدن ایک سال میں تجارت کے دن.

اگلا، چلو اس فنکشن کے آؤٹ پٹ کو ایک ساتھ دیکھتے ہیں:

return {
        totalAssets: totalAssets,
        yearDays: yearDays,
        totalReturns: totalReturns,
        annualizedReturns: annualizedReturns,
        sharpeRatio: sharpeRatio,
        volatility: volatility,
        maxDrawdown: maxDrawdown,
        maxDrawdownTime: maxDrawdownTime,
        maxAssetsTime: maxAssetsTime,
        maxDrawdownStartTime: maxDrawdownStartTime,
        winningRate: winningRate
    }
  • کل اثاثے: کل اثاثے
  • سال دن: تجارت کے دن
  • کل منافع: کل منافع
  • سالانہ منافع: سالانہ منافع
  • sharpeRatio: شارپ تناسب
  • عدم استحکام: عدم استحکام
  • maxDrawdown: زیادہ سے زیادہ ڈراؤنڈ
  • maxDrawdownTime: زیادہ سے زیادہ ڈراؤونگ پر ٹائم اسٹیمپ
  • maxAssetsTime: زیادہ سے زیادہ اثاثوں پر ٹائم اسٹیمپ
  • maxDrawdownStartTime: زیادہ سے زیادہ ڈراپ ڈاؤن کا شروع ہونے کا وقت
  • جیتنے کی شرح: جیتنے کی شرح

ان پٹ اور آؤٹ پٹ کو جانتے ہوئے ، ہم یہ سمجھ سکتے ہیں کہ فنکشن کس کے لئے استعمال ہوتا ہے۔ اسے آسان طریقے سے بیان کرنے کے لئے ، یہ فنکشن کو کچھ اصل ریکارڈ دیتا ہے ، جیسے واپسی کے اعدادوشمار کی صف۔ فنکشن آپ کو بیک ٹیسٹ کی کارکردگی ظاہر کرنے کے لئے نتیجہ دے گا۔

اگلا، آئیے دیکھتے ہیں کہ کوڈ کا حساب کیسے لگایا جاتا ہے:

function returnAnalyze(totalAssets, profits, ts, te, period, yearDays) {
    // force by days
    period = 86400000                  // The number of milliseconds in a day, that is 60 * 60 * 24 * 1000
    if (profits.length == 0) {         // If the length of the array of profits is 0, it cannot be calculated and it will return to the null value directly
        return null
    }
    var freeProfit = 0.03              // Risk-free interest rate, which can also be set according to the demand, such as 3% annualized national debt
    var yearRange = yearDays * 86400000          // Milliseconds of all accumulated trading days in a year
    var totalReturns = profits[profits.length - 1][1] / totalAssets      // Total return rate
    var annualizedReturns = (totalReturns * yearRange) / (te - ts)       // The annualized rate of return, the expected rate of return obtained by scaling the time of profit statistics to the scale of one year

    // MaxDrawDown
    var maxDrawdown = 0           // Initialize the maximum drawdown variable to 0
    var maxAssets = totalAssets   // Initialize maximum asset variable with initial net value assignment
    var maxAssetsTime = 0         // Timestamp of the time when the maximum asset is initialized
    var maxDrawdownTime = 0       // Timestamp of the time when the maximum drawdown is initialized
    var maxDrawdownStartTime = 0  // Timestamp of the time when the maximum start time is initialized
    var winningRate = 0           // Initialized win rate is 0
    var winningResult = 0         // Record the number of win time
    for (var i = 0; i < profits.length; i++) {      // Traverse the return array
        if (i == 0) {
            if (profits[i][1] > 0) {                // If the first return record point, the return is greater than 0, it means the profit
                winningResult++                     // The number of win times accumulates 1 
            }
        } else {                                    // If it is not the first returns record point, as long as the returns of the current point is greater than the returns of the previous moment (return point), it means profit, and the number of win times accumulates 1 
            if (profits[i][1] > profits[i - 1][1]) {
                winningResult++
            }
        }
        if ((profits[i][1] + totalAssets) > maxAssets) {    // If the return plus the initial net value at that moment is greater than the largest asset recorded to have occurred, the value of the largest asset is updated and the timestamp of this moment is recorded
            maxAssets = profits[i][1] + totalAssets
            maxAssetsTime = profits[i][0]
        }
        if (maxAssets > 0) {                                // When the maximum asset value recorded is greater than 0, the drawdown is calculated
            var drawDown = 1 - (profits[i][1] + totalAssets) / maxAssets
            if (drawDown > maxDrawdown) {                   // If the current drawdown is greater than the recorded maximum drawdown, update the maximum drawdown, maximum drawdown time, etc
                maxDrawdown = drawDown
                maxDrawdownTime = profits[i][0]
                maxDrawdownStartTime = maxAssetsTime
            }
        }
    }
    if (profits.length > 0) {                            // Calculate the winning rate
        winningRate = winningResult / profits.length
    }
    // trim profits
    var i = 0
    var datas = []
    var sum = 0
    var preProfit = 0
    var perRatio = 0
    var rangeEnd = te
    if ((te - ts) % period > 0) {
        rangeEnd = (parseInt(te / period) + 1) * period     // Process rangeEnd as an integer multiple of period
    }
    for (var n = ts; n < rangeEnd; n += period) {
        var dayProfit = 0.0
        var cut = n + period
        while (i < profits.length && profits[i][0] < cut) {    // Ensure that when the timestamp is not out of bounds, the array length is also not out of bounds
            dayProfit += (profits[i][1] - preProfit)           // Calculate the daily returns
            preProfit = profits[i][1]                          // Record yesterday's returns
            i++                                                // Accumulate i for accessing the next profits node
        }
        perRatio = ((dayProfit / totalAssets) * yearRange) / period   // Calculate the annualized rate of return at that time
        sum += perRatio                                               // Accumulation
        datas.push(perRatio)                                          // Put in the array datas
    }

    var sharpeRatio = 0                    // Initial Sharpe ratio is 0
    var volatility = 0                     // Initial volatility is 0
    if (datas.length > 0) {
        var avg = sum / datas.length;      // Find the mean value
        var std = 0;
        for (i = 0; i < datas.length; i++) {
            std += Math.pow(datas[i] - avg, 2);      // The std is used to calculate the following variance. The following std/datas.length is the variance, and the square root of the number is the standard deviation
        }
        volatility = Math.sqrt(std / datas.length);  // In terms of years, volatility is the standard deviation
        if (volatility !== 0) {
            sharpeRatio = (annualizedReturns - freeProfit) / volatility   // Sharpe formula to calculate Sharpe ratio: (annualized return rate - risk-free rate) / standard deviation
        }
    }

    return {
        totalAssets: totalAssets,
        yearDays: yearDays,
        totalReturns: totalReturns,
        annualizedReturns: annualizedReturns,
        sharpeRatio: sharpeRatio,
        volatility: volatility,
        maxDrawdown: maxDrawdown,
        maxDrawdownTime: maxDrawdownTime,
        maxAssetsTime: maxAssetsTime,
        maxDrawdownStartTime: maxDrawdownStartTime,
        winningRate: winningRate
    }
}

مجموعی طور پر ، الگورتھم پیچیدہ نہیں ہے ، اور کئی تصورات ہوسکتے ہیں جن کو پہلے سے سمجھنے کی ضرورت ہے۔

  • تغیرات: یہ واپسی کے اعداد و شمار کے ایک سیٹ کے طور پر سمجھا جا سکتا ہے. نمونوں کے گروپ، 1، 2، 3، 4 اور 5، کی ایک اوسط قدر ہے (1+2+3+4+5) / 5 = 3، جبکہ تغیرات کے درمیان فرق کے مربع کے مجموعے کی اوسط قدر ہے ہر اعداد و شمار اور اس کے مجموعہ کے درمیان بالترتیب، جو ہے [(1-3) ^ 2 + (2-3) ^ 2 + (3-3) ^ 2 + (4-3) ^ 2 + (5-3) ^ 2) / 5 = 2، اور تغیرات 2 ہے.

  • معیاری انحراف: متغیر کی ریاضیاتی مربع جڑ کا حساب لگائیں، جو معیاری انحراف ہے۔

  • اتار چڑھاؤ: جب حساب کتاب کا پیمانہ سالانہ ہوتا ہے تو، اتار چڑھاؤ معیاری انحراف ہے.

ان تصورات اور حساب کے فارمولوں کی تفہیم کے ساتھ ، فنکشن کا شارپ حساب کا حصہ ایک نظر میں واضح ہوجائے گا۔ شارپ تناسب کا حساب لگانے کے لئے شارپ فارمولا: (سالانہ منافع کی شرح - خطرے سے پاک شرح) / معیاری انحراف

کیا آپ نے ابھی تک سیکھا ہے؟


مزید